2024-09-06 01:36 AM - last edited on 2024-09-06 01:42 AM by SofLit
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 정도 대기
}
Solved! Go to Solution.
2024-09-06 01:50 AM - edited 2024-09-06 01:50 AM
Hello @ark2,
Since you are using HSEState = RCC_HSE_BYPASS, is the external clock source available and stable?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-09-06 01:41 AM - edited 2024-09-06 01:41 AM
Hello @ark2 ,
First, kindly use English to post a thread.
Second, please use </> button to paste your code (I'm editing your post). Review the tips on posting on this link.
Translation:
I removed STlink from the NUCLEO F722ZE board and wrote it, but a clock error occurs and the program itself does not work. It worked normally when Stlink was present, but it does not work.
I used it by setting it to HSI, but it does not work. So I tried to switch to HSE, and there was a clock issue, so I thought I could just debug it, but at some point the clock did not work and it did not come out of the stop mode. I set it to RTC alarm and woke it up, but it worked fine and then stopped, so it seems to be a clock error.
How can I solve this error? Stlink uses a lot of current, so it should be removed.
I only removed stlink from the hardware, and this is the situation.
Original settings before removing STlink
This was a previously used setup, but after removing STlink, an error handle HAL_RCC_OscConfig(&RCC_OscInitStructure) occurred in this part.
2024-09-06 01:50 AM - edited 2024-09-06 01:50 AM
Hello @ark2,
Since you are using HSEState = RCC_HSE_BYPASS, is the external clock source available and stable?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-09-06 02:03 AM
After removing the stlink, there was a problem with the clock, so I'm fixing it, but it still seems to be a problem with the external clock
But I don't know how to fix it
It doesn't change even if you edit it in the cube mx and set the clock