cancel
Showing results for 
Search instead for 
Did you mean: 

increment doesn't work in a systick function

curiae
Associate III

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;

}

}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@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

 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

View solution in original post

8 REPLIES 8
curiae
Associate III

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,

 

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

> Deactivate the watchdog if activated.

Yes. Besides of power supply issues, only watchdogs reset the core.

curiae
Associate III

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;

SofLit
ST Employee

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.

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.
curiae
Associate III

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,.

>>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

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@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

 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.