AnsweredAssumed Answered

CubeMx generates unfunctionnal code with lib 1.5

Question asked by JulienD on Apr 24, 2016
Latest reply on Oct 25, 2016 by JulienD
Hi,

Here's some code generated with cubeMx:

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
 
__HAL_RCC_PWR_CLK_ENABLE();
 
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI
                                   | RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
                              | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
 
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV8;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
 
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
 
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

STM32Cube FW_L1 V1.5.0 lib changed some behaviour in HAL_RCCEx_PeriphCLKConfig function. It may return HAL_ERROR if HSE state is on.
This makes the above code return an error and not set the RTC.

I don't know exactly where's the bug but very basically I commented out the "return HAL_ERROR" and it does the job (maybe for my own use...).

I suppose this is a bug either in the lib either in cubeMx that does not call in the good order...
But maybe I did it wrong. In this case what ?

Regards
Julien

Outcomes