Skip to main content
jovijuan
Associate III
February 1, 2022
Solved

Why is HSI_VALUE redefined in project options when LL drivers are used for RCC?

  • February 1, 2022
  • 4 replies
  • 3200 views

I'm trying to setup a project with STM32CubeIDE 1.8 (includes CubeMX 6.4) that uses LPUART1 on a STM32L031K6. I want to lower the CPU frequency to 4MHz, and, to reduce power, I'm using HSI/4 as clock input.

0693W00000JO5yjQAD.pngLPUART baudrate is set wrong (4 times higher than expected according to logic analyzer), it's generated out of PCLK1 frequency that is assigned as HSI_VALUE >> 2. While HSI_VALUE is defined in stm32l0xx_ll_rcc.h:

#define HSI_VALUE (16000000U)

But, during debug I realize that HSI_VALUE value is 4000000, it is redefined as a compiler directive:

-mcpu=cortex-m0plus -std=gnu11 -g3 -DDEBUG -DSTM32L031xx -DUSE_FULL_LL_DRIVER -DHSE_VALUE=8000000 -DHSE_STARTUP_TIMEOUT=100 -DLSE_STARTUP_TIMEOUT=5000 -DLSE_VALUE=32768 -DMSI_VALUE=2097000 -DLSI_VALUE=37000 -DVDD_VALUE=3300 -DPREFETCH_ENABLE=0 -DINSTRUCTION_CACHE_ENABLE=1 -DDATA_CACHE_ENABLE=1 -DHSI_VALUE=4000000 -c -I../Core/Inc -I../Drivers/STM32L0xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32L0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage --specs=nano.specs -mfloat-abi=soft -mthumb

If HSI is not divided by 4 it's just redefined as 16000000 and everything works ok.

If I use HAL driver for RCC HSI_VALUE is not redefined as a compiler directive so it's ok too.

I know that I can delete that redefinition from project options, but it's added again if I change anything in CubeMX and generate code again.

This topic has been closed for replies.
Best answer by Mike_ST

Hello,

Thank you for sharing your issue,

I think HSI should not be redefined at compilation time, but this is my opinion.

I entered a ticket.

4 replies

Mike_ST
Mike_STBest answer
ST Technical Moderator
February 1, 2022

Hello,

Thank you for sharing your issue,

I think HSI should not be redefined at compilation time, but this is my opinion.

I entered a ticket.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
Associate II
September 18, 2023

Hello Mike,

This issue is still here with the most up-to-date version of the L0 package. Do you have any answer from the dev/support team ?

Pavel A.
September 18, 2023

@Brieuc When you create the project 1st time (generate code for CubeIDE), is the preprocessor symbol for HSE_VALUE defined in the project settings (not in any source or include file)? Is the value correct?

If you re-generate the project after changes in the clock/timing page, does the above mentioned preprocessor symbol change accordingly? If it does not - change it manually.

Note: Eclipse allows to override preprocessor symbols and options separately for every source file, be careful not to do this (unless you want exactly this).