Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Initialisation fails when using CubeMX and HSE clock source

Hi,

I am using Windows 10 Pro with SMT32CubeMX (V4.20) and firmware STM32Cube FW_F4 V1.15.0 imported into System Workbench for STM32 (V1.13.1).

I am using an Olimex P405 (STM32F405RGT6 device) development board and ST-LINK/V2 JTAG debugger.

When I configure the CubeMX project to use HSI clock everything works as expected. However, I would like to use HSE as the clock source which is connected to an 8MHz crystal. In this case the function HAL_RCC_OscConfig() returns the error HAL_ERROR.

On further inverstigation into the execution of HAL_RCC_OscConfig(), I find the following.

The first part of the function that configures the HSE clock succeeds and the external crystal oscillator starts up and can be seen on an oscilloscope.

The next part of the function that configures the HSI clock fails at the following line of code.

if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
{
return HAL_ERROR;
}

Any help why this is happening would be appreciated.

Regards
FarmerJo

This bug was introduced by CubeMX v4.20.
In SystemClock_Config() function, when HSE is selected it generates code:

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}

Notice the OscillatorType filed is initialized for BOTH HSI and HSE, while later field HSIState is never set.

So you have two solutions:

  • either remove RCC_OSCILLATORTYPE_HSI for the line to be like this:
    • RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  • or add HSIState field like this:
    • RCC_OscInitStruct.HSIState = RCC_HSI_ON;


I hope they will fix this ASAP, as you have to edit SystemClock_Config() every time the project is regenerated..

Thanks for the reply.

Yes I found the same things. So in order not to have to hand modify the auto-generated code every time I rebuilt the cube code I reverted back to the previous version of cube, which works as expected.

Regards
FarmerJo


I have exact same problem.
I always have to remove RCC_OSCILLATORTYPE_HSI when using HSE for RCC.
Hope this bug be fixed soon.


 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs