0

I'm having trouble generating specific time for the STM32F103C8 (Blue Pill). Apparently, the AHB main clock is set to 72 MHz. However, regardless of whether the SysTick clock source is AHB or AHB/8, the time always turns out to be 10 times longer. Clock config

void    delay(){
SysTick->LOAD = 7199999;
SysTick->CTRL = 0x05;
while((SysTick->CTRL&(1<<16)) == 0);
SysTick->CTRL = 0x00;}

This delay should be 0.1 sec. But it always works in 1 sec. Other values ​​are also 10 times higher, regardless of whether CLKSOURCE is AHB or AHB/8. If anyone can help, I appreciate it.

wrha
  • 1
  • the st documentation states that the systick timer is the clock divided by 8, so you need to set it for what is it 72M/8 - 1. 8999999 something like that right? – old_timer Jul 15 '21 at 20:49
  • 1
    and use a scope to measure things or measure several minutes worth of time outs to see it was 1/8th instead of 1/10th...or maybe you have some other issue and it is still off even with a divide by 8 – old_timer Jul 15 '21 at 20:50
  • most vendors feed the same clock the arm sees into the systick clock but the arm core has separate inputs so the chip vendor is free to put whatever clock they want into that...(or divide it or whatever). – old_timer Jul 15 '21 at 20:51

1 Answers1

0

Below is how I use the Systick timer:

    void delaySysTicks(uint32_t msDelay) {
        for(uint32_t c = 0; c < msDelay; c++) {
            SysTick->CTRL = 0x0;            // disable systick
    
            SysTick->LOAD = (SystemCoreClock / 1000U);      // count down reload - 1ms
            SysTick->VAL = 0;
    
            SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
            SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
    
            while(!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));   // wait for timer rollover
        }
    }

delaySysTicks(1000); // busy wait 1 second
PeterVC
  • 4,574
  • 2
  • 16
  • 14