cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with SysTick interrupt not triggering on STM32F0

banks
Associate II
Posted on March 14, 2016 at 17:12

I've been having trouble with getting the SysTick interrupt to trigger in a simple program using the standard peripheral library. The code should just pulse an LED every time the SysTick interrupt fires, but instead it just sits in the main() loop and never toggles the GPIO.

#include ''stm32f0xx.h''
GPIO_InitTypeDef GPIO_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
void init()
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel = SysTick_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPriority = 0;
NVIC_Init(&NVIC_InitStruct);
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
}
void LED_On()
{
GPIOA->BRR = GPIO_Pin_6;
}
void LED_Off()
{
GPIOA->BSRR = GPIO_Pin_6;
}
int main()
{
init();
LED_Off();
for(;;);
}
void SysTick_Handler()
{
LED_On();
LED_Off();
}

Am I missing something obvious that's needed to set up the SysTick interrupt handler? I've been looking around for a while and I haven't seen something other people are doing with the standard peripheral library that I'm not. Thanks for any help.
8 REPLIES 8
pj
Associate II
Posted on March 14, 2016 at 18:00

If you can see a nS led blink. I can't. And most humans as well I think.

banks
Associate II
Posted on March 14, 2016 at 19:28

I'm measuring the pin with a scope

Posted on March 14, 2016 at 21:03

Using a .CPP file?

Using a debugger?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
banks
Associate II
Posted on March 14, 2016 at 21:17

Nope, just C files. I'm programming the board with an ST-Link and debugging over that using GDB. When I set breakpoints in the SysTick ISR they never get triggered.

I know that the GPIO/etc is correct because when I modify main() to read

void main()
{
 init();
for(;;)
{
LED_On();
LED_Off();
}
}

then the pin does toggle correctly (albeit rather slowly, only ~188KHz which seems slow given that the system_stm32f0xx.c file from the discovery board software library should be setting the system clock to 48MHz).
TDK
Guru
Posted on March 14, 2016 at 21:28

 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

If you feel a post has answered your question, please click "Accept as Solution".
Posted on March 14, 2016 at 21:33

Don't use the NVIC_Init, this is a System Handler, not an IRQ

After selecting the clock source, you must actually configure and enable the SysTick

SysTick_Config(SystemCoreClock / 1000); // 1ms (1000 times a second)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
banks
Associate II
Posted on March 14, 2016 at 22:11

That did it, thanks! Although when I comment out the NVIC_Init portion it stops working, are you sure that part isn't required?

Posted on March 14, 2016 at 22:18

Yeah, pretty sure

STM32F0xx_StdPeriph_Lib_V1.5.0\Projects\STM32F0xx_StdPeriph_Examples\SysTick\SysTick_Example\main.c

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