2024-12-12 09:33 PM - last edited on 2024-12-13 12:12 AM by SofLit
Hello,
Now I'm testing a systick work on STM32L0538-DISCO.
The aim in my project is to make 100Hz, 10Hz, 6Hz, 5Hz, 2Hz and 1Hz systick functions.
In the project, 100Hz, 10Hz, 6Hz and 5Hz systick functions worked, but 2Hz and 1Hz systick functions didn't work.
In my main.c code, 10Hz systick driver ( deci_sec_systick_Driver()) could drive 5Hz systick driver (vigesimal_sec_systick_Driver()) but couldn't drive 2Hz systick driver (demi_sec_systick_Driver()).
I found by debugging that a local static variable (demi_sec_systick_count) reached to 4 but it was reset before reaching 5.
Of course there are nowhere the local static variable is cleared but didn't reach to 5 it's really incredible phenomenon.
Are there someone who experienced like this?
If you know the cause and how to fix it tell me about it.
as reference I'll attach the project.
Thanks,
// 10 Hz systick driver
static void deci_sec_systick_Driver()
{
static uint32_t vigesimal_systick_count = 0;
static uint32_t demi_sec_systick_count = 0;
// 5 Hz systick driver
vigesimal_systick_count += 1;
if(vigesimal_systick_count >= 2)
{
vigesimal_sec_systick_Driver();
vigesimal_systick_count = 0;
}
// 2 Hz systick driver
demi_sec_systick_count += 1;
if(demi_sec_systick_count >= 5)
{
demi_sec_systick_Driver();
demi_sec_systick_count = 0;
}
}
Solved! Go to Solution.
2024-12-13 02:30 PM
@curiae wrote:After your suggestion, I changed hiwdg.Init.Prescaler up to MAX and surely 1sec systick works.
But even at MAX Prescaler, reset itself seemed to occur.
Firstly I thought IWDG generates reset if loop takes time than time-up value by IWDG but real I felt.behavior seems to be different.
I guess reset by IWDG inevitably occurs is it right?
And show me how to avoid IWDG reset when IWDG is used.
Thanks,.
You need to reset the IWDG in your main while loop
while(1)
{
// Reset WDT
HAL_IWDG_Refresh(&hiwdg);
// other code
}
And you have to make sure your other code doesn't take up more time before it can loop back to reset the IWDG
2024-12-12 10:39 PM
Hello,
Let me add more information.
After the unforeseen phenomenon, I predicted MCU reset is done within 500msec.
I added an increment counter in the msec systick driver and as I expected the counter never reached to 500.
So I'm convinced that Systick occurs MCU reset within 500 msec.
If the systick generate MCU reset, how should I stop it?
Please show me how to solve it.
Thanks,
2024-12-12 11:11 PM
The SysTick surely does not generate reset. Some other stuff does. Isolate the problem by deactivating the peripherals. The problem probably lies in some runaway ISR. Deactivate the watchdog if activated.
2024-12-13 12:00 AM
> Deactivate the watchdog if activated.
Yes. Besides of power supply issues, only watchdogs reset the core.
2024-12-13 12:09 AM
Thank you for your answer,
If watchdog occur reset, I'll change time out settings.
But I don't know how should I configure these parameters in MX_IWDG_Init().
By following parameters, reset occur within 500 sec?
If you like please explain about the settings.
Thanks,
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
hiwdg.Init.Window = 4095;
hiwdg.Init.Reload = 4095;
2024-12-13 12:12 AM
Hello @curiae ,
Please in next time kindly use </> button to paste your code. Please refer to How to insert source code.
I'm editing your post.
Thank you for your understanding.
2024-12-13 06:04 AM
After your suggestion, I changed hiwdg.Init.Prescaler up to MAX and surely 1sec systick works.
But even at MAX Prescaler, reset itself seemed to occur.
Firstly I thought IWDG generates reset if loop takes time than time-up value by IWDG but real I felt.behavior seems to be different.
I guess reset by IWDG inevitably occurs is it right?
And show me how to avoid IWDG reset when IWDG is used.
Thanks,.
2024-12-13 12:10 PM
>>And show me how to avoid IWDG reset when IWDG is used.
You have to kick it periodically..
IwdgHandle.Init.Window = IWDG_WINDOW_DISABLE;
...
/* Refresh IWDG: reload counter */
if(HAL_IWDG_Refresh(&IwdgHandle) != HAL_OK)
{
/* Refresh Error */
Error_Handler();
}
STM32Cube_FW_L0_V1.12.2\Projects\NUCLEO-L011K4\Examples\IWDG\IWDG_Reset\Src\main.c
2024-12-13 02:30 PM
@curiae wrote:After your suggestion, I changed hiwdg.Init.Prescaler up to MAX and surely 1sec systick works.
But even at MAX Prescaler, reset itself seemed to occur.
Firstly I thought IWDG generates reset if loop takes time than time-up value by IWDG but real I felt.behavior seems to be different.
I guess reset by IWDG inevitably occurs is it right?
And show me how to avoid IWDG reset when IWDG is used.
Thanks,.
You need to reset the IWDG in your main while loop
while(1)
{
// Reset WDT
HAL_IWDG_Refresh(&hiwdg);
// other code
}
And you have to make sure your other code doesn't take up more time before it can loop back to reset the IWDG