PlatformIO Community

Stm32 Standard Library


#1

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.


#2

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


#3

嗯嗯,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.


#5

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


#6

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.


#7

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


#8

OK~Thank you for your answer.


#9

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.


#10

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


#11

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?


#12

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.


#13

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


#14

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?


#15

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.


#16

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