How to use RTC while using Root of Trust on the NUCLEO-N657X0-Q board.
I am a user of the NUCLEO-N657X0-Q board.
I am using the NUCLEO-N657X0-Q board with Root of Trust enabled, and I want to use the RTC.
Out of the 3 stages (FSBL → Secure App → Non-Secure App) I want to use the RTC in the Non-Secure App.
My development environment is as follows:
1> Development tool: Keil uVision V5.42
2> Example source: STM32Cube\Repository\STM32Cube_FW_N6_V1.2.0\Projects\NUCLEO-N657X0-Q\Applications\ROT\OEMuROT_Appli
3> Development board: NUCLEO-N657X0-Q
The biggest problem is that when HAL_RTC_Init() is called in the Non-Secure App, it hangs.
The source for STM32Cube_FW_N6_V1.2.0\Projects\NUCLEO-N657X0-Q\Applications\ROT\OEMuROT_Appli was created by referencing STM32Cube_FW_N6_V1.2.0\Projects\STM32N6570-DK\Applications\ROT\OEMuROT_Appli.
The code I added is as follows.
1. Added to the main function of the Secure App.
HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RCC_PERIPH_INDEX_RTC, RIF_ATTRIBUTE_NSEC);
2. Added a function to the Non-Secure App.
RTC_HandleTypeDef RtcHandle;
void rtc_Init(void)
{
memset(&RtcHandle, 0, sizeof(RTC_HandleTypeDef));
RtcHandle.Instance = RTC;
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RtcHandle.Init.AsynchPrediv = 0x7F;
RtcHandle.Init.SynchPrediv = 0xF9;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
RtcHandle.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
RtcHandle.Init.BinMode = RTC_BINARY_NONE;
printf("rtc_Init() start 111...\r\n");
if (HAL_RTC_Init(&RtcHandle) != HAL_OK)
{
printf("rtc_Init() Fail!\r\n");
return;
}
printf("rtc_Init() OK!\r\n");
}
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if (hrtc->Instance == RTC)
{
HAL_PWR_EnableBkUpAccess();
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) ;
__HAL_RCC_RTC_CLK_ENABLE();
__HAL_RCC_RTCAPB_CLK_ENABLE();
printf("HAL_RTC_MspInit() end...\r\n") ;
}
}
int main(void)
{
.
.
.
#ifdef PRINT_BOOT_TIME
printf("\r\nBoot time : %u ms at %u MHz", (unsigned int)(time), (unsigned int)(SystemCoreClock/1000000U));
printf("\r\n");
#endif
printf("\r\n======================================================================");
printf("\r\n= (C) COPYRIGHT 2024 STMicroelectronics =");
printf("\r\n= =");
printf("\r\n= User App #%c =", *pUserAppId);
printf("\r\n======================================================================");
printf("\r\n\r\n");
/* User App firmware runs*/
rtc_Init() ;
FW_APP_Run();
.
.
.
}
The execution result is as follows.
======================================================================
(C) COPYRIGHT 2024 STMicroelectronics =
=
User App #A =
======================================================================
rtc_Init() start 111...
HAL_RTC_MspInit() end…
if (HAL_RTC_Init(&RtcHandle) != HAL_OK) //// ==> It hangs at this point.
I would like to inquire about how to use RTC in a ROT (Root of Trust) environment.
The actual RTC usage is in the Non-Secure App.
Thank you.
