In STM32CubeIDE we can enable RTOS using following steps:
Configuration
1. In Pinout & Configuration, go to Middleware and Software Packs > FREERTOS
2. Configure Interface Mode as CMSIS_V1 or CMSIS_V2
3. Start adding OS Tasks, change Task name and Entry function.
Example:
Manual Code
1. In main.c file > main() function instead of writing in while 1 loop, we need to write actual code in Tasks generated. While 1 loop will not be reached as osKernelStart(); will take over.
2. LED Blinking code can be executed from TASK which we added
Example code:
/* USER CODE BEGIN Header_Task2_init */
/**
* @brief Function implementing the Task2 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_Task2_init */
void Task2_init(void const * argument)
{
/* USER CODE BEGIN Task2_init */
/* Infinite loop */
for(;;)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);
HAL_Delay(200);
//osDelay(10);
}
/* USER CODE END Task2_init */
}
No comments:
Post a Comment