2021-06-04 01:01 AM
Hello,
We have been using STCubeMx(v6.2.1) to generate our system initialization code. We started a new project for an stm32H7A3xx MCU.
But with the auto-generated code, it fails on the HAL_RCC_ClockConfig->HAL_InitTick->HAL_SYSTICK_Config.
We tried different clock configurations (lower freq., different prescalers) but it resulted in the same fault.
Any idea where the problem is?
Thanks in advance,
Adria Terrades
Auto-generated SystemClock_Config:
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE
|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 280;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_1;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
{
Error_Handler();
}
}
Solved! Go to Solution.
2021-06-06 11:24 PM
At the end, we ended up remaking the project and little by little and it solved itself. I suppose something messed up with the previous auto-generation.
Thanks for your responses,
AT
2021-06-04 01:31 AM
> it fails on the HAL_RCC_ClockConfig->HAL_InitTick->HAL_SYSTICK_Config.
How?
JW
2021-06-04 01:44 AM
It doesn't pass the check, at the function call:
if (HAL_SYSTICK_Config(SystemCoreClock / (1000UL / (uint32_t)uwTickFreq)) > 0U)
{
return HAL_ERROR;
}
where it unrolls to the CMSIS function SysTick_config(uint32_t ticks).:
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
The HAL_RCC_ClockConfig sets the variable SystemCoreClock, with the MX parametrization:
/* Update the SystemCoreClock global variable */
common_system_clock = HAL_RCC_GetSysClockFreq() >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE)>> RCC_CDCFGR1_CDCPRE_Pos]) & 0x1FU);
SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
SystemCoreClock = common_system_clock;
which leads to the error.
AT
2021-06-04 07:54 AM
If you have uwTickFreq = HAL_TICK_FREQ_10HZ, your reload won't fit in 24 bits. Use a faster frequency.
If that's not it, attach your IOC if you can. Verify SystemCoreClock gets set to 280e6. See what uwTickFreq is equal.
2021-06-06 11:24 PM
At the end, we ended up remaking the project and little by little and it solved itself. I suppose something messed up with the previous auto-generation.
Thanks for your responses,
AT
2021-06-17 07:01 AM
@Community member
Would you please show what you did to fix this problem? I am having the same problem on a STM32F4-DISCO board. CubeMX is making a faulty clock configuration.
2021-06-17 07:33 AM
I just started a new project and configure the mx options step by step (configure, save, compile, test) and it worked...
Try adding configuration parameters one at the time.
AT