2021-06-25 03:28 AM
Hi Everybody,
I'm using a nucleo board with STM32L412KB and I try to learn how to use the STOP mode.
I want to put the micro in STOP mode and reactivate it whit a command via USART.
I put the UASART baudrate at 115200 and use the HSI clock. (see clock configuration immage).
When I connect the serial programm to read the message from the micro (using ZOC with 115200 baudrate ) I view strange message like the baudrate is not corret. (view immage "strange message").
If I change the clock of the USART1 (from HSI to PCLK2) I view the message correct but is not possible to reactivate the micro from STOP mode with USART.
Which is the problem? Have I forgot some configuration in the USART ?
THank you for your help
2021-10-06 01:48 PM
Hello :)
Recently I stumbled upon this problem, and sadly found your question unanswered.
After doing some digging and guessing, I found the source of the problem, and the solution:
The solution:
Under the SystemClock_Config function, do the following
// Replace this
RCC_OscInitStruct.HSICalibrationValue = 16; // bug here, this value is incorrect
// with this
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
The problem:
There is a bug in STM32Cube code generation (I use CubeIDE 1.5.0), where it does not assign the right value calibration value to the HSI clock.
When generating code with USART2 clocked using the HSI, you can find the following code under the `SystemClock_Config` function:
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16; // bug here, this value is incorrect
If you'll go to the definition of the HSICalibrationValue, you will find the following comment:
uint32_t HSICalibrationValue; /*!< The calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT). */
Look up the definition of this default value, and you'll find the following:
#define RCC_HSICALIBRATION_DEFAULT 0x40U /*!< Default HSI calibration trimming value 64 on devices other than STM32L47x/STM32L48x */
And by using this `RCC_HSICALIBRATION_DEFAULT` as the calibrationValue for the HSI - your UART should work just fine :)
Therefore - it seems there is a bug in the code generator which causes this behavior (At least in CubeIDE 1.5.0).
Note: You provided code where USART is clocked by the PCLK, but you can change it to HSI and use the fix I explained above.
In addition - you might want to consider using LPUART - it seems more fit when using it with STOP mode.