cancel
Showing results for 
Search instead for 
Did you mean: 

Using SysTick causes reset?

SBona.2
Associate II

UPDATE: The issue has been solved. The nBFB2 option bit had to be enabled.

Hello, I am currently programming and STM32L152RE on a Nucleo development board. I am using SysTick as a .5s timer that ran a status LED. Everything was working up until recently when I noticed the LED stopped working, and the processor seemed to be restarting. Stepping through with a debugger showed it was able to run all the setup code correctly, but when I let it run to get to the SysTick_Handler(), it would instead go to the reset handler. I also verified it is caused by SysTick as the code does not crash when I do not use it. I also checked the RCC_CR register after the reset to determine the cause, and only the PORRSTF and PINRSTF bits are set, which didn't help me. Here is the code:

int main(void)
{
	clk_init();
	statusLedInit();
        // Turn status LED on
	GPIOA->ODR |= GPIO_ODR_ODR_5;
	usartInit();
	SysTick_Config(SYS_TCK_RELOAD_VAL);
	int val = 0;
	printStr("Hello World!\n");
	while (1)
	{
		val += 1;
	}
}
 
void clk_init()
{
	// Turn the HSI on
	RCC->CR |= RCC_CR_HSION;
	// Wait for it to be stabalized
	while ((RCC->CR & RCC_CR_HSIRDY) == 0)
		;
	// Set HSI to the sys clock
	RCC->CFGR = (RCC->CFGR & ~(RCC_CFGR_SW_Msk)) | 0x1;
	// If it was succesful, clock should now be HSI
	while ((RCC->CFGR & RCC_CFGR_SWS_Msk) == 0x1)
		;
	// Turn the MSI off
	RCC->CR &= ~RCC_CR_MSION;
}

I can include usartInit() and statusLedInit() if needed, but given it crashes regardless if they are there they don't seem relevant. I've also tried erasing the chip and reprogramming, but that did not work either. Thanks for any help.

10 REPLIES 10

Yup it was one of the option bytes! I had to enable the nBFB2 option and now its working. Thanks for the help!