I removed the STlink of the NUCLEO F722ZE board and wrote it, but there was a clock error, so the program itself is not working
It worked normally when there was Stlink, but it’s not working
I set it to HSI and used it, but it didn’t work, so a clock issue occurred to switch to HSE, so I thought it would be okay to just debug it, but at some point, the clock didn’t work, so it didn’t come out of stop mode
I set it as an rtc alarm and woke it up, but it seems like a clock error when it stops after going well
How can I fix this error?
Stlink uses a lot of electric current, so it needs to be removed
I removed only the stlink from the hardware, but this is the situation
Original settings before removing STlink
Setting changed to clock error after removing STlink
This is the setting I used before, but after removing the STlink, the HAL_RCC_OscConfig(&RCC_OscInitStructure) error handle occurred in this part
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 216;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Activate the Over-Drive mode
*/
if (HAL_PWREx_EnableOverDrive() != 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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
{
Error_Handler();
}
}
It’s a code related to stop mode
void RTC_Init(void)
{
__HAL_RCC_RTC_ENABLE();
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
HAL_RTC_Init(&hrtc);
// Get current time
RTC_TimeTypeDef currentTime;
HAL_RTC_GetTime(&hrtc, ¤tTime, RTC_FORMAT_BIN);
// Calculate alarm time (current time + 50 seconds)
RTC_AlarmTypeDef sAlarm;
sAlarm.Alarm = RTC_ALARM_A;
sAlarm.AlarmTime = currentTime;
sAlarm.AlarmTime.Seconds += 30;
// Handle overflow of seconds
if (sAlarm.AlarmTime.Seconds >= 60)
{
sAlarm.AlarmTime.Seconds -= 60;
sAlarm.AlarmTime.Minutes++;
if (sAlarm.AlarmTime.Minutes >= 60)
{
sAlarm.AlarmTime.Minutes -= 60;
sAlarm.AlarmTime.Hours++;
if (sAlarm.AlarmTime.Hours >= 24)
{
sAlarm.AlarmTime.Hours -= 24;
}
}
}
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0;
HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN);
}
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
// Handle the alarm event
// Wake up the system or perform necessary actions here
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // Clear wake-up flag if necessary
}
void vStopMode(void)
{
/* Suspend SysTick */
HAL_SuspendTick();
/* Enable Power Peripheral */
__HAL_RCC_PWR_CLK_ENABLE();
/* Initialize RTC and set alarm */
RTC_Init();
/* STOP Mode */
//HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
/* Resume SysTick When System Wake-up */
HAL_ResumeTick();
/* PLL Clock Recovery */
SystemClock_Config();
// 전력 안정화를 위해 잠시 대기
HAL_Delay(100); // 100ms 정도 대기
}
1