AnsweredAssumed Answered

SysTick Mystery

Question asked by tiwari.navin on Nov 7, 2015
Latest reply on Nov 8, 2015 by tiwari.navin
hello,
I'm trying to create delay of 1 second and toggle an LED. I'm using SysTick timer for this task. I have STM32F103C8T6 mcu. The following code does not work. Looks like the control never reaches the SysTick_Handler.

#include "stm32f10x.h"
 
 
int main()
{
     
    RCC->APB2ENR|=RCC_APB2ENR_IOPBEN; //enable gpioB clock     
    GPIOB->CRH=0x01;   //pin B.8 output mode with push pull(LED pin)
     
                     
    SysTick->LOAD|=0x895440;    //9000000 in decimal for 1 second delay with 72MHz system clock. CALIB val is 9000(1 ms)
    SysTick->CTRL|=0x02;            //enable interrupt trigger
    SysTick->CTRL|=0x01;            // enable clock
     
     
}
 
void SysTick_Handler(void)
{
    GPIOB->ODR^=0x100;      //toggle LED
}

However when I use the following code, it works!!

#include "stm32f10x.h"
 
 
int main()
{
     
    RCC->APB2ENR|=RCC_APB2ENR_IOPBEN; //enable gpioB clock     
    GPIOB->CRH=0x01;   //pin B.8 output mode with push pull(LED pin)
     
                     
    SysTick->LOAD|=0x895440;    //9000000 in decimal for 1 second delay with 72MHz system clock. CALIB val is 9000(1 ms)
    SysTick->CTRL|=0x02;            //enable interrupt trigger
    SysTick->CTRL|=0x01;            // enable clock
    while(1)
    {  
         
    }
     
}
 
void SysTick_Handler(void)
{
    GPIOB->ODR^=0x100;      //toggle LED
}

I just included an infinite loop at the end of main(). Why is it not working without the endless loop??

Outcomes