cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to enable SYSTICK

Akshat_codes_
Associate II

Hi,

I am working with the STM32F103RCT6. I am writing a bare metal code for delay function using SYSTICK timer. The problem I am facing is that I am not able to write to the ARM cortex registers. Below is my code for your reference - 
This is the stm32f103xx.h file

#define SYSCLK 8000000UL // System clock frequency in Hz
#define SYSTICK_BASE          0xE000E010UL

// SysTick Structure definition
typedef struct
{
    volatile uint32_t CTRL;      /* SysTick control and status register offset: 0x00 */
    volatile uint32_t LOAD;      /* SysTick reload value register offset: 0x04 */
    volatile uint32_t VAL;       /* SysTick current value register offset: 0x08 */
    volatile uint32_t CALIB;     /* SysTick calibration value register offset: 0x0C */
} SysTick_TypeDef;

#define SYSTICK             ((SysTick_TypeDef *) SYSTICK_BASE)


This is the function in my main.c

void SystemClock_Config(void)
{
    __disable_irq(); // Disable all interrupts

    // 1. Enable HSI
    RCC->CR |= (1 << 0);  // HSION = 1

    // 2. Wait until HSI is ready
    while (!(RCC->CR & (1 << 1)));  // HSIRDY = 1

    // 3. Select HSI as system clock
    RCC->CFGR &= ~(0x3 << 0); // clear SW[1:0]
    RCC->CFGR |=  (0x0 << 0); // select HSI (00)

    // 4. Wait until HSI is used as system clock
    while ((RCC->CFGR & (0x3 << 2)) != (0x0 <<2) );

    SYSTICK->LOAD  = (uint32_t)((SYSCLK / 1000) - 1);   // 1ms reload
    SYSTICK->VAL   = 0;                        // reset counter
    SYSTICK->CTRL  = (1U << 2); // processor clock enable
    SYSTICK->CTRL |= (1U << 1); // enable interrupt
    SYSTICK->CTRL |= (1U << 0); // enable SysTick

    __enable_irq(); // Re-enable all interrupts
  
}

This is the implementation of the SysTick_Handler . I debugged my code and the current_tick variable was not incrementing. 

volatile uint32_t current_tick = 0;

void SysTick_Handler(void)
{
    current_tick +=1;
}


Below is the screenshot of the cube programmer window after I flashed the code - 
Screenshot from 2025-09-03 17-52-58.png

As you can see, the SYSTICK registers do not have the value I tried to write. My code only contains this piece of code which I shared. Is my code missing something that needs to be added or some other register that needs to be configured? 

1 REPLY 1
mfgkw
Associate III

Is the program only flashed or is it started and running?