cstm32stm32ldiscovery

How does delay work on the stm32l152RC?


I just bought an stm32l152RC and was wondering how the delay works. The system clock is 16Mhz.

Code:

static volatile uint32_t TimingDelay;
void Delay(__IO uint32_t nCount);


int main(void) {
    Config_Systick();
    char *RCCp = (char*) 0x40023800;
    int *PBp = (int *) 0x40020400;
    // RCC Config
    *((int*) (RCCp + 28)) |= 0x3f;
    *((int*) (RCCp + 32)) |= 1;
    *PBp = 0x5000;

    while (1) {
        GPIO_TOGGLE(GPIOB, LD_GREEN); //toggle green led
        Delay(1000); // 1 second?
    }
} // end of main

    RCC_ClocksTypeDef RCC_Clocks;
    void Config_Systick() {
        RCC_GetClocksFreq(&RCC_Clocks);
        SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); // setting changed to / 1000
    }

    void TimingDelay_Decrement(void) {
        if (TimingDelay != 0x00) {
            TimingDelay--;
        }
    }

    void Delay(uint32_t nTime) {
        TimingDelay = nTime;
        while (TimingDelay != 0) {
        };
    }

When I execute Delay(1000); in this case the Delay is 1 second, could someone please explain why the delay is 1 second?


Solution

  • After doing some research this is the answer I came up with. doing SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); means you'r setting 1000 ticks per second. when you do Delay(100) the delay will be 100 ms.