Issue with SysTick interrupt not triggering on STM32F0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 9:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 10:00 AM
If you can see a nS led blink. I can't. And most humans as well I think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 11:28 AM
I'm measuring the pin with a scope
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 1:03 PM
Using a .CPP file?
Using a debugger?Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 1:17 PM
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 readvoid 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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 1:28 PM
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 1:33 PM
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 SysTickSysTick_Config(SystemCoreClock / 1000); // 1ms (1000 times a second)Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 2:11 PM
That did it, thanks! Although when I comment out the NVIC_Init portion it stops working, are you sure that part isn't required?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-14 2:18 PM
Yeah, pretty sure
STM32F0xx_StdPeriph_Lib_V1.5.0\Projects\STM32F0xx_StdPeriph_Examples\SysTick\SysTick_Example\main.cUp vote any posts that you find helpful, it shows what's working..
