PlatformIO Community

Stm32 Standard Library

Hello everyone, I have a question. I want to write a program for the STM32F103C8T6 chip. The framework I use is not the STM32CUBE library but a standard library, but I have not found the standard library in PlatFormIO. I don’t know how to do it.

Do you mean just the bare-metal the C standard library (newlib-nano) or the STM32 standard peripheral library (SPL)?

嗯嗯,YES,Is ST’s standard peripheral library,I saw that PlatFormIO supports STM32CUBE, but I don’t see the standard peripheral library. I want to ask if PlatFormIO can use the standard peripheral library.

I see some ST chips support SPL, but STM32F103C8T6 does not seem to support

We have SPL examples (https://github.com/platformio/platform-ststm32/tree/develop/examples/spl-blink) but the bluepill_f103c8 target (here) is not including spl in the frameworks . I’ll look into it why it’s not activated later the day.

Pull-Request is on its way, see https://github.com/platformio/platform-ststm32/pull/226. Will be available after merging and release.

OK~Thank you for your answer.

Hello, I am very grateful for your reply. I changed my local “bluepill_f103c8.json” file according to the link you gave. When compiling, I was prompted with the missing “stm32f10x.h”. I feel that the SPL of STM32F1 is not downloaded.

Do I need to download the SPL library from the ST official website and add it to these directories?

Sorry, I didn’t read the text on GITHUB seriously. Now I have added the file, but I still have a question: Why is the STM32F1 series chip used so much, and PlatFormIO does not support the SPL library of the STM32F1 series chip?

1 Like

I can upload my framework-spl files in the evening.

SPL is deprecated by STM (see here) and they recommend to use LL (low-level) or STM32Cube libraries.

1 Like

My framework-spl can be downloaded from https://drive.google.com/open?id=1HTh7bK_5nY7-EjgIgb7_S584TIrOQ_cj.

2 Likes

Thank you very much for your answer, I have copied the file to the correct place and compiled it correctly. In this case, can I use the SPL library of the entire STM32F1 series?

nice :+1:

Not directly, you have to enable the board JSON for it. If you take a look at the diff for the bluepill_f103c8.json file (here), then you will see that it

  • adds "spl" into the "frameworks" array
  • adds the macro STM32F10X_MD

The first change will cause PlatformIO to allow writing framework = spl without aborting. The second macro is needed for the SPL framework to identifiy the device class. If you look into framework-spl\stm32\cmsis\variants\stm32f1\system_stm32f10x.c you’ll see there are macros which control the target CPU frequency (for STM32F103C8: 72MHz after PLL from 8MHz quartz crystal) and other stuff.

From framework-spl\stm32\cmsis\variants\stm32f1\stm32f10x.h:

#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL) 
  /* #define STM32F10X_LD */     /*!< STM32F10X_LD: STM32 Low density devices */
  /* #define STM32F10X_LD_VL */  /*!< STM32F10X_LD_VL: STM32 Low density Value Line devices */  
  /* #define STM32F10X_MD */     /*!< STM32F10X_MD: STM32 Medium density devices */
  /* #define STM32F10X_MD_VL */  /*!< STM32F10X_MD_VL: STM32 Medium density Value Line devices */  
  /* #define STM32F10X_HD */     /*!< STM32F10X_HD: STM32 High density devices */
  /* #define STM32F10X_HD_VL */  /*!< STM32F10X_HD_VL: STM32 High density value line devices */  
  /* #define STM32F10X_XL */     /*!< STM32F10X_XL: STM32 XL-density devices */
  /* #define STM32F10X_CL */     /*!< STM32F10X_CL: STM32 Connectivity line devices */
#endif
/*  Tip: To avoid modifying this file each time you need to switch between these
        devices, you can define the device in your toolchain compiler preprocessor.

 - Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers
   where the Flash memory density ranges between 16 and 32 Kbytes.
 - Low-density value line devices are STM32F100xx microcontrollers where the Flash
   memory density ranges between 16 and 32 Kbytes.
 - Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers
   where the Flash memory density ranges between 64 and 128 Kbytes.
 - Medium-density value line devices are STM32F100xx microcontrollers where the 
   Flash memory density ranges between 64 and 128 Kbytes.   
 - High-density devices are STM32F101xx and STM32F103xx microcontrollers where
   the Flash memory density ranges between 256 and 512 Kbytes.
 - High-density value line devices are STM32F100xx microcontrollers where the 
   Flash memory density ranges between 256 and 512 Kbytes.   
 - XL-density devices are STM32F101xx and STM32F103xx microcontrollers where
   the Flash memory density ranges between 512 and 1024 Kbytes.
 - Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
  */

So for the STM32F103C8 it says “Mainstream Performance line” and "medium-density ", so we conclude that we need the STM32F10X_MD macro.

The other thing is the startup assembler code located framework-spl\stm32\cmsis\variants\stm32f1\startup_stm32f10x_md.s. I copied the startup file for the MD device class because I know it was the correct one for the bluepill. Other boards require other startup files. These files come from the SPL download STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7.

I haven’t looked into how the builder script here finds out which .s file to use so I just assumed it would try to assemble all of them; that’s why there should be only one .s file in there. You can do the same (only place the correct startup file in the folder) or we’d need to adapt the builder script to only select the correct startup file. For that the script would have to know which device class we have.

The other STM32 F0/3/4 and L1 don’t have this problem, they all have nice unified startup files. I wonder why that’s so for the F1 class.

Thank you for your answer~(膜拜大佬:grinning:):+1::+1::+1:

请问你知道怎么使用platform用spl的framework来开发stm32f103嘛

其实并不算太复杂,只需两步,
第一步:将framework-spl的库下载下来放到C:\Users\Administrator.platformio\packages这个路径下, maxgerhardt把这个文件放到谷歌云盘去了,我们中国是不能访问外网的 ,我待会 给你 发个链接。然后更改这个文件bluepill_f103c8.json,这个文件在C:\Users\Administrator.platformio\platforms\ststm32\boards这个文件下,Stm32 Standard Library
第二步:打开platformIO子选择板子的时候直接输入blupill找到相应的板子,在 下面的固件库中看看有没有SPL,然后OK了,

或者说用我按照以上操作配置 好的文件:
第一步:把framework-spl解压放到C:\Users\Administrator.platformio\packages这个文件下。百度网盘地址:链接: https://pan.baidu.com/s/1_72k879BZ0O-m3Eu0UjtKw 提取码: vrq6 复制这段内容后打开百度网盘手机App,操作更方便哦
第二步: 把ststm32解压放到C:\Users\Administrator.platformio\platforms这个文件下,如果有这个文件,则替换掉它。百度网盘地址:链接: https://pan.baidu.com/s/1gfxn8NaVsm3xka0MyG3dBA 提取码: gkq3 复制这段内容后打开百度网盘手机App,操作更方便哦
第三步:创建工程,选择bluepill板子,你无法直接创建STM32F103的SPL库,只能通过板子来创建,目前我只知道这么办,然后 选择SPL就可以了

另外感谢 maxgerhardt的大力帮助

谢谢楼主,我用你得方法已经成功编译stm32f103得SPL程序,但是用jlink烧录程序得时候,单片机没有反应,然后platform用什么进行仿真呢,怎么在线仿真,跑到主程序去

在线DEBUG需要登录账户,就是你打开VSCODE会自动弹出的那个platformIO的主页上有个登录,登录了才能debug,如果你是新注册的账户,会有30天的免费试用期,30天以后就不能debug了,那时需要进行购买,debug按钮在vscode的任务栏上,名字叫做“调试”,然后你就可以愉快的进行调试了