Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mirao opened this issue Sep 25, 2019 · 3 comments

Comments

@mirao
Copy link

mirao commented Sep 25, 2019

Steps to reproduce:

; build_flags =
;     -DHSE_VALUE=8000000U
  • Follow the README.md (how to connect device, build and upload)
  • When app is built and uploaded to MCU, open serial console and see output

Expected result:

  • text "Hello World!"

Actual result:

  • displayed characters are corrupted:
    image

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:

  • Hardcode the constant value to platformi.ini. It takes precedence before #define in source code
build_flags =
    -DHSE_VALUE=8000000U

Used SW and HW:

  • MCU STM32F407-DISC1
  • Ubuntu 19.04
  • VSCode 1.38.1
  • pio 4.0.3
  • ststm32 5.6.0
  • framework-stm32cube 2.0.181130
  • STM32CubeMX 5.3.0
  • platformio.platformio-ide@1.8.3
@valeros
Copy link
Member

valeros commented Sep 26, 2019

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
Copy link
Author

mirao commented Sep 27, 2019

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants