The manual porting process is complex and tedious. First, use cubemx for quick configuration:
First, print a message to the serial port:
/* USER CODE BEGIN 2 */ printf("hello shxi\r\n");
/* USER CODE END 2 */
/* Call init function for freertos objects (in freertos.c) */ MX_FREERTOS_Init();
OK proves that the configuration is correct!
Tasks are processes/threads. Creating a task allocates a space.
Task creation and deletion related functions:
xTaskCreate() //Dynamically create a task
xTaskCreateStatic()//Statically create a task
vTaskDelete()//Delete a task
The stack for dynamically created tasks is allocated by the system, while the stack for statically created tasks is passed by the user. Generally, dynamic task creation is used.
/* BaseType_t xTaskCreate(TaskFunction_t pxTaskCode, //Pointer to the task function, the task must implement a never-returning continuous loopconst configSTACK_DEPTH_TYPE usStackDepth ,//Task stack sizeconst char* const pcName, //Task name, maximum lengthconfigMAX_TASK_NAME_LENvoid *const pvParameters, //Parameters passed to the task functionUBaseType_t uxPriority, //Task priority, the greater the number, the higher the priorityTaskHandle_t *const pxCreatedTask, //Task handle, which is the task's control block )*/
Next, create tasks taskled1 & taskled2 that blink LED1 and LED2 at different frequencies:
Note the details of selected projects:
Task name: taskled1
Priority:osPriorityNormal
Dynamic creation: Dynamic
Entry name: Starttaskled1
Similarly for CV taskled2:
Next, open GPIOB8, GPIOB9 to pull up the port voltage
Then generate code:
/* USER CODE END Header_Starttaskled1 */void Starttaskled1(void const * argument){ /* USER CODE BEGIN Starttaskled1 */ /* Infinite loop */ for(;;) { HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_8); osDelay(400); } /* USER CODE END Starttaskled1 */}
/* USER CODE END Header_Starttaskled2 */void Starttaskled2(void const * argument){ /* USER CODE BEGIN Starttaskled2 */ /* Infinite loop */ for(;;) { HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_9);
osDelay(100); } /* USER CODE END Starttaskled2 */}
Successfully lit display effect:
