Autonomous Lawn Mower/Raspberry pi & STM32

Systick callback function

날아라용팔이 2025. 2. 1. 23:46
반응형

ioc 파일 설정

 

 

 설정 후 SysTick_Handler에 HAL_SYSTICK_IRQHandler();를 추가해주어야 함. SysTick_Handler가 있는 위치는 Core > Src > stm32f4xx_it.c 에 있다. 

 

 

 

예제 코드 

 

// variables for system scheduler

volatile uint32_t ms_counter = 0;

volatile uint32_t tick_1ms = 0;

volatile uint32_t tick_10ms = 0;

volatile uint32_t tick_100ms = 0;

volatile uint32_t tick_1s = 0;

 

void HAL_SYSTICK_Callback(void)

{

// return uwTick in the __weak uint32_t HAL_GetTick(void)

// if(uwTick % 1000==0){

// printf("count : %d\n\r", count);

// count++;

// }

 

// Set 1ms tick flag

tick_1ms = 1;

 

ms_counter++;

 

// Set 10ms tick flag

if (ms_counter % 10 == 0)

{

 

tick_10ms = 1;

}

 

// Set 100ms tick flag

if (ms_counter % 100 == 0)

{

 

tick_100ms = 1;

}

 

// Set 1s tick flag

if (ms_counter % 1000 == 0)

{

 

// motor_control_process(cmd, len, data);

 

tick_1s = 1;

}

 

// Reset counter after 1 second to avoid overflow

if (ms_counter >= 1000)

{

ms_counter = 0;

}

}

반응형