PlatformIO Community

HAL_Delay(time_ms) problem with CubeMX


#1

Hello all,

I’m missing something to make code generated from the latest CubeMX to work correctly in PIO.
It compiles, it runs, but the timings are not correct.

A HAL_Delay(500ms) call takes approx 1.5 seconds when compiled with pio. Runs ok compiled with CubeIDE.

I don’t know how to dump the env of a CubeIDE project neither so I’m kind of stuck there for now. I’m starting to dig more into it but if someone has a clue it is welcome.


#2

What’s your platformio.ini and code, what’s your MCU, what’s the crystal oscillator’s value on your board, what clock tree config did you setup in CubeMX?


#3

I’m trying the PIO debugger right now and I like it. Baby steps here.

  • Platformio.ini:

[env:nucleo_h743zi]
platform = ststm32
board = nucleo_h743zi
framework = stm32cubemx
build_flags =
;–verbose
-D CORE_CM7
-D USE_FULL_LL_DRIVER
-IInc
-IDrivers\STM32H7xx_HAL_Driver\Inc

I need to mention that to get to this point I created a custom framework (and named it stm32cubemx) with the files from the ST repository for the h7 mcu and h7 boards only. I modified the the platform.json, boards.json, added a package.json and a script files in .platformio to make it work, so I now have a dedicated cubemx framework.

After a debug session, it appears that the HSE frequency is defined as being 25M in stm32h7xx_hal_conf_template.h file from the framework. It is defined as 8M in the stm32h7xx_hal_conf.h generated by MX in the project Inc folder.
It looks like files from the framework are included first.

Adding -D HSE_VALUE=((uint32_t)8000000) to platformio.ini solves the clock problem but does not solve the include precedence problem, as I would prefer that the stm32xxx_hal_conf.h file generated in the project folder was prioritized in the include order.

I’m stuck here. What should I do ? Remove the hal_conf file from the framework ? Going to take a look at the python script now.


#5

Okay I get it now: this is the code from stm32cube.py that I copied blindly and renamed stm32cubemx.py

def generate_hal_config_file(mcu):
    config_path = join(FRAMEWORK_DIR, FRAMEWORK_CORE, "Drivers",
                       MCU_FAMILY.upper() + "xx_HAL_Driver", "Inc")

// if a config file is already there, it doesn’t update

    if isfile(join(config_path, MCU_FAMILY + "xx_hal_conf.h")):
        return


    if not isfile(join(config_path, MCU_FAMILY + "xx_hal_conf_template.h")):
        sys.stderr.write(
            "Error: Cannot find template file to configure framework!\n")
        env.Exit(1)

// if the template file is there, it just copy the template

    copy(join(config_path, MCU_FAMILY + "xx_hal_conf_template.h"),
         join(config_path, MCU_FAMILY + "xx_hal_conf.h"))

I’ll try to change this.


#6

Okay, I’m marking adding -D HSE_VALUE=((uint32_t)8000000) to platformio.ini as the good solution because it is solving this particular issue.

Getting things to compile CubeMX generated code cleanly with a modified py script is harder and interesting and deserves a thread on its own.