platformio / platform-ststm32

ST STM32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/ststm32
Apache License 2.0
381 stars 303 forks source link

framework-stm32cube: Custom HSE_VALUE is "overridden" by value from package's template stm32f4xx_hal_conf #290

Open mirao opened 4 years ago

mirao commented 4 years ago

Steps to reproduce:

Expected result:

Actual result:

The problem is that the constant HSE_VALUE originally set to 8MHz by STM32Cube (see #define in Inc/stm32f4xx_hal_conf.h in project's root) isn't taken into account. App uses the default value from .platformio/packages/framework-stm32cube/f4/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_conf.h instead and it is 25Mhz.

But serial input/output over UART doesn't work well with such frequency.

Workaround:

valeros commented 4 years ago

Your workaround with build_flags is the best solution at the moment. We plan to improve the build script for stm32cube framework, so it'll be able to handle such cases.

mirao commented 4 years ago

Just FYI: I've found out, that the external HSE oscillator was enabled because I confirmed the dialog Initialize all peripherals with their default mode? in STM32CubeMX when I was creating a new project. But the demo works even with internal HSI. It can be enabled in STM32CubeMX in "Clock Configuration => PLL Source HSI". HSI has only one frequency 16MHz and thus there's no need to apply any workaround.

raphaelmor commented 4 years ago

Just adding my 2 cents (I spent a few days struggling with the same issue with I2S). From what I understand (being a newbie with STM32, HAL, and Platformio), stm32f4xx_hal_conf.h is supposed to be copied into the application code and customized. I have no idea how to do that (given that platformio is so good at hiding those details), so I used the workaround of using build flags too.