2024-11-27 06:08 AM - edited 2024-11-27 06:13 AM
Hello,
I only have 2 GPIOs activated, and the SMPS, not yet any code written from me...
The function HAL_PWREx_ControlVoltageScaling times out in NonSecure (somehow works if debugging and stepping into.. but then HAL_RCC_OscConfig get HAL_Error).
For some reason there is not problem if I call that SystemClock_Config in Secure main.c...
Any idea why this is happening ?
Here is the auto generated SystemClock_Config from the NonSecure main.c:
**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV4;
RCC_OscInitStruct.PLL.PLLM = 3;
RCC_OscInitStruct.PLL.PLLN = 10;
RCC_OscInitStruct.PLL.PLLP = 8;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 1;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
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_PCLK3;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
}
2024-11-28 04:37 AM
Hello @Nero ,
It is to note that system clock config should happen only once either in secure or in non-secure context and normally if it were to happen in secure than a call to this function in non-secure should not impact the already configured oscillator and clock if it were to keep the same configuration done in secure.
my recommendation is either to keep this call in the secure project and remove it from non-secure replacing it by a SystemCoreClockUpdate() if you want to change clock configuration from secure in the non-secure or do the clock configuration in the non-secure project and remove it from secure project as it can be found in:
STM32Cube_FW_U5_V1.5.0\Projects\STM32U5G9J-DK2\Templates\TrustZoneEnabled
Can you share your IOC to check your clock configuration as well as the CubeMX version used to generate your code as when I tested with cubeMX 6.12.1 I got a single call to the SystemClock_Config() in the secure project.
Regards
2024-12-04 06:20 AM
Hello @STea,
I think this issue is related to the Cmake Code generator, I ended up switching to makeFile generation with no trust zones and I don't have any issues anymore; not really a solution but it will work for now with what i need to do.
I did see the TrustZoneEnabled template but couldn't make it work with Cmake.
Thank you for your feedback