Welcome to RDK X5 Robot repository
4. FreeRTOS application
4. FreeRTOS application
4. FreeRTOS application4.1. Experimental purpose4.2. Configure FreeRTOS information4.3. Analysis of experimental flow chart4.4. Core code interpretation4.5. Hardware connection4.6. Experimental effect
4.1. Experimental purpose
On the basis of the "key control buzzer buzzer" program, the function is imported to the FreeRTOS system to detect the KEY1 status on the expansion board and control the buzzer buzzer buzzer. Press the button, the buzzer drops (every 200 milliseconds), press the button again, the buzzer off.
4.2. Configure FreeRTOS information
Since each new project needs configuration information, it is troublesome. Fortunately, STM32CubeIDE provides the function of importing.IOC file, which can help us save time.
- Import ioc file from BEEP project and name it FreeRTOS.
- Click Middleware->FREERTOS, select CMSIS_V1, click Tasks and Queues, there will be a task here by default, and create two new tasks, one to manage the buzzer and the other to manage the keys.

- The buzzer task information is shown as follows:

Task Name: The name of the task. Priority: Set the priority.
Stack Size: Heap space, can be modified according to the actual size. Entry Function: task function entity.
Code Generation Option: indicates the code generation configuration. The default value is weak to generate task entities. You can select external to not generate task entities.
Parameter: Task parameters.
Allocation: Dynamic or Static allocation can be selected. Buffer Name: The name of the statically allocated buff. Control Block Name: statically allocated block name.
The keystroke task is the same, just with a different name.
4.3. Analysis of experimental flow chart

4.4. Core code interpretation
- Create the bsp_task.h and bsp_task.c driver libraries of the buzzer in the BSP. Add the following to bsp_task.h:

Task_Entity_LED() manages the LED light, Task_Entity_Beep() manages the buzzer, and Task_Entity_Key() manages the key.



- Import bsp.h into freertos.c, find the entity functions of the corresponding three tasks, and call the manually established task functions respectively.



4.5. Hardware connection
LED lights, keys KEY1 and buzzer in FreeRTOS application are onboard components and do not need to be manually connected.
4.6. Experimental effect
After burning the program, the LED light flashes every 200 milliseconds, press the key, the buzzer drops and drops (every 200 milliseconds), press the key again, the buzzer is off.