Nucleo STM32F103RB는 72MHz 속도로 동작
1초에 7200000Hz로 클럭 발생 → 누군가 7200만번에 한 번씩 신호를 주면 1초가 지났다는 것을 인지
⇒ 7200만 클럭에 한 번씩 인터럽트 발생시키면 되겠다
72000클럭에 한 번씩 누군가 신호를 해주면 1ms 시간 측정 가능
STM32에서는 이런 역할을 System Timer에서 수행할 수 있도록 만들어져 있다
시스템 클럭에서 to Cortex System Timer로 보내주는 클럭과 메모리 맵에 있는 Private Peripheral Bus가 이것

int main(void)
{
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
STM_EVAL_LEDInit(LED2);
STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);
BlinkSpeed = 0;
while (1)
{
if(BlinkSpeed == 0)
{
STM_EVAL_LEDToggle(LED2);
Delay(50);
}
else if(BlinkSpeed == 1)
{
STM_EVAL_LEDToggle(LED2);
Delay(200);
}
}
}
extern "C"
{
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
}
main.cpp
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
stm32f1xx_it.c
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}
core_cm3.h
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
static __INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
SysTick->VAL = 0; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
