cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX LL Driver Bug - HSE calculations

George.P
Associate III
Posted on January 18, 2018 at 09:18

Hello,

I've encountered a bug in code generation when using the LL STM32F3 drivers 1.9.0 in Cube 4.23.0.

The device is the

STM32F303CCTx

, although it's probably not device specific.

Using the clock configurator and setting an HSE of 16MHz, the code generated in 

stm32f3xx_ll_rcc.h

indicates a wrong value for HSE:

&sharpif !defined (HSE_VALUE)

&sharpdefine HSE_VALUE 8000000U /*!< Value of the HSE oscillator in Hz */

&sharpendif /* HSE_VALUE */

This can cause all sorts of problems if one uses the API to get various peripheral clock speeds, like  

LL_RCC_GetUSARTClockFreq

which gave me the wrong value, causing me to set up the wrong baud.

The

.ioc

 file seems correct since the relevant field is correct:

RCC.HSE_VALUE=16000000

#ll-drivers #stm32f3 #cube-mx
12 REPLIES 12
Posted on May 07, 2018 at 07:55

Yes, project-wide definition solves that problem, but my primary point was that Cube software in similar conditions of sole LL usage genarates inoperable code with not so easy to find bu

g but that is already known for a couple of months. While this problem is not fixed even with such a simple solution I think many developers using Cube for LL will have to make the same debugging way as I did.

Jim Kapcio
Associate II
Posted on May 10, 2018 at 23:47

I haven't verified on a board but isn't the real problem the order of the includes in main.c?

swap the order the includes:

#include 'stm32l0xx_hal.h'

#include 'main.h'

This compiles and should give the right answer since 

stm32l0xx_hal.h includes 

stm32f3xx_hal_conf.h which will now be included before stm32f1xx_ll_rcc.h.

This would be a fix to the STM32CubeMX code generator.

Posted on May 11, 2018 at 11:09

As I have mentioned above that won't help much because HSE frequency definition in this case will only take effect for main.c file compilation. Since there are still lots of LL's .c files and each one of these requires its own compilation process with its own separate defines (obviously not including any half_conf.h at all), every such .c file will get only default HSE_VALUE of 8000000 that is defined inside LL's headers making library functions see only this value.