Hello,
I’ve got a board using a STM32F030 which is specified in platform-ststm32/demo_f030f4.json at master · platformio/platform-ststm32 · GitHub . The file uses "variant": "DEMO_F030F4"
. The currently stable STM32Duino release 1.7.0 has two other board variants: DEMO_F030F4_16M and DEMO_F030F4_HSI. Is it possible to overwrite/change the variant from platformio.ini without creating a custom board json?
I tried board_build.variant = DEMO_F030F4_16M
, however this fails somewhere inside the STM32 toolchain:
~/.platformio/packages/framework-arduinoststm32/system/STM32F0xx/stm32f0xx_hal_conf.h:4:10: fatal error: variant.h: No such file or directory
As you can see in the STM32Duino repo you referenced it says
So, they all use the same build.variant=DEMO_F030F4
, but a different build.board
value. This results in a different macro being created.
As you can then see in the variant.cpp
file:
WEAK void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/* Initializes the CPU, AHB and APB busses clocks */
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
#ifdef ARDUINO_DEMO_F030F4_HSI
/* Internal HSI, 48MHz system clock */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
#else
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14 | RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
RCC_OscInitStruct.HSI14CalibrationValue = 16;
This file has been truncated. show original
Depending on the set Macros (ARDUINO_DEMO_F030F4_HSI
and ARDUINO_DEMO_F030F4_16M`), a different oscillator initialization is done.
Thus you can just adapt the macros in your custom board.json or add them via build_flags
.
2 Likes
Thanks for the answer. For those searching along: This would be the corresponding platformio.ini :
[env:demo_f030f4]
platform = ststm32
board = demo_f030f4
framework = arduino
build_flags = -DARDUINO_DEMO_F030F4_16M