diff --git a/Core/Src/main.c b/Core/Src/main.c index 3026162..6178e7f 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -70,7 +70,19 @@ static void MX_USART1_UART_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +#define MAIN_LOOP_PERIOD 50 +static void loop_delay() { + static uint32_t last_loop = 0; + uint32_t dt = HAL_GetTick() - last_loop; + if (dt < MAIN_LOOP_PERIOD) { + HAL_Delay(MAIN_LOOP_PERIOD - dt); + HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_RESET); + } else { + HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_SET); + } + last_loop = HAL_GetTick(); +} /* USER CODE END 0 */ /** @@ -127,7 +139,7 @@ int main(void) { soc_update(); can_send_status(); - HAL_Delay(10); + loop_delay(); } /* USER CODE END 3 */ }