1. Edit /Users/yinhuanyuan/.platformio/platforms/ststm32/boards/bluepill_f103c8.json
“extra_flags”: “-DSTM32F1 -DSTM32F103xB -DARDUINO_BLUEPILL_F103C8”,
“extra_flags”: “-DSTM32F1 -DSTM32F10X_MD -DSTM32F103xB -DARDUINO_BLUEPILL_F103C8”,
and
“mbed”,
“cmsis”,
“libopencm3”,
“stm32cube”
“stm32cube”,
“spl”
2. Create a blink example for blue pill using SPL.
#ifndef STM32F1
#error “This example is for an STM32F1 series board!”
#endif
#include
#include
#include
/* blinky for PC_13 (on-board red LED) */
#define LEDPORT (GPIOC)
#define LEDPIN (GPIO_Pin_13)
#define ENABLE_GPIO_CLOCK (RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE))
/* toggle time */
#define DELAY_TIME_MILLIS 1000
/* variable keeps track of timing delay */
static __IO uint32_t TimingDelay;
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in milliseconds.
* @retval None
*/
void Delay(__IO uint32_t nTime) {
TimingDelay = nTime;
while (TimingDelay != 0);
}
void TimingDelay_Decrement(void) {
if (TimingDelay != 0x00) {
TimingDelay–;
}
}
/* system entry point */
int main(void) {
//setup SysTick for 1 millisecond interrupts
if (SysTick_Config(SystemCoreClock / 1000)) {
/* Capture error */
while (1);
}
/* gpio init struct */
GPIO_InitTypeDef gpio;
/* enable clock GPIO */
ENABLE_GPIO_CLOCK;
/* use LED pin */
gpio.GPIO_Pin = LEDPIN;
/* mode: output */
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
/* apply configuration */
GPIO_Init(LEDPORT, &gpio);
/* main program loop */
for (;;) {
/* set led on */
GPIO_SetBits(LEDPORT, LEDPIN);
/* delay */
Delay(DELAY_TIME_MILLIS);
/* clear led */
GPIO_ResetBits(LEDPORT, LEDPIN);
/* delay */
Delay(DELAY_TIME_MILLIS);
}
/* never reached */
return 0;
}
/******************************************************************************/
/* Cortex-M3 Processor Exceptions Handlers */
/******************************************************************************/
void NMI_Handler(void) {
}
void HardFault_Handler(void) {
/* Go to infinite loop when Hard Fault exception occurs */
while (1) {
}
}
void MemManage_Handler(void) {
/* Go to infinite loop when Memory Manage exception occurs */
while (1) {
}
}
void BusFault_Handler(void) {
/* Go to infinite loop when Bus Fault exception occurs */
while (1) {
}
}
void UsageFault_Handler(void) {
/* Go to infinite loop when Usage Fault exception occurs */
while (1) {
}
}
void SVC_Handler(void) {
}
void DebugMon_Handler(void) {
}
void PendSV_Handler(void) {
}
void SysTick_Handler(void) {
//decrement timing delay here
TimingDelay_Decrement();
}
3. Run pio run, we got the following error:
Compiling .pio/build/bluepill_f103c8/src/main.o
Archiving .pio/build/bluepill_f103c8/libFrameworkCMSISVariant.a
Archiving .pio/build/bluepill_f103c8/libFrameworkSPL.a
Indexing .pio/build/bluepill_f103c8/libFrameworkCMSISVariant.a
Indexing .pio/build/bluepill_f103c8/libFrameworkSPL.a
src/main.c:4:10: fatal error: stm32f10x.h: No such file or directory
*******************************************************************
* Looking for stm32f10x.h dependency? Check our library registry!
*
* CLI > platformio lib search “header:stm32f10x.h”
* Web > https://platformio.org/lib/search?query=header:stm32f10x.h
*
*******************************************************************
#include
^~~~~~~~~~~~~
compilation terminated.
*** [.pio/build/bluepill_f103c8/src/main.o] Error 1
4. Edit /Users/yinhuanyuan/.platformio/platforms/ststm32/builder/frameworks/spl.py,
if “STM32F40_41xxx” in extra_flags:
src_filter_patterns += [“-“]
if “STM32F427_437xx” in extra_flags:
src_filter_patterns += [“-“]
elif “STM32F303xC” in extra_flags:
src_filter_patterns += [“-“]
elif “STM32L1XX_MD” in extra_flags:
src_filter_patterns += [“-“]
elif “STM32F10X_MD” in extra_flags:
src_filter_patterns += [“”]
5. Make a folder named stm32f1 under /Users/yinhuanyuan/.platformio/packages/framework-spl/stm32/cmsis/variants
startup_stm32f10x.c
stm32f10x.h
stm32f10x_conf.h
system_stm32f10x.c
system_stm32f10x.h
6. Make a folder named stm32f1 under
/Users/yinhuanyuan/.platformio/packages/framework-spl/stm32/spl/variants
make a folder named inc and src under this stm32f1 folder.
7. Copy the following files to inc folder
misc.h
stm32f10x_adc.h
stm32f10x_bkp.h
stm32f10x_can.h
stm32f10x_cec.h
stm32f10x_crc.h
stm32f10x_dac.h
stm32f10x_dbgmcu.h
stm32f10x_dma.h
stm32f10x_exti.h
stm32f10x_flash.h
stm32f10x_fsmc.h
stm32f10x_gpio.h
stm32f10x_i2c.h
stm32f10x_iwdg.h
stm32f10x_pwr.h
stm32f10x_rcc.h
stm32f10x_rtc.h
stm32f10x_sdio.h
stm32f10x_spi.h
stm32f10x_tim.h
stm32f10x_usart.h
stm32f10x_wwdg.h
copoye the followign files to src folder
misc.c
stm32f10x_adc.c
stm32f10x_bkp.c
stm32f10x_can.c
stm32f10x_cec.c
stm32f10x_crc.c
stm32f10x_dac.c
stm32f10x_dbgmcu.c
stm32f10x_dma.c
stm32f10x_exti.c
stm32f10x_flash.c
stm32f10x_fsmc.c
stm32f10x_gpio.c
stm32f10x_i2c.c
stm32f10x_iwdg.c
stm32f10x_pwr.c
stm32f10x_rcc.c
stm32f10x_rtc.c
stm32f10x_sdio.c
stm32f10x_spi.c
stm32f10x_tim.c
stm32f10x_usart.c
stm32f10x_wwdg.c