当前位置:网站首页>FreeRTOS startup - based on stm32

FreeRTOS startup - based on stm32

2022-06-11 04:08:00 z_ Curtain

1、Reset_Handler

The first assembly function executed after the system is powered on , The system initializes through this function

1 Reset_Handler PROC
2 EXPORT Reset_Handler [WEAK]
3 IMPORT __main
4 IMPORT SystemInit
5 LDR R0, =SystemInit
6 BLX R0 
7 LDR R0, =__main
8 BX R0
9 ENDP

2、__main

C Library function , This function will be called after system initialization , To carry out C Code


3、main()

main The function is C Language code is the first function to execute , Generally, the creation and startup of the operating system are in main Call in function .

 int main(void)
 {
    
 	BaseType_t xReturn = pdPASS;/*  Define a return value for creation information , The default is  pdPASS */
 
 	/*  Hardware initialization of development board  */
	 BSP_Init(); 
	 taskENTER_CRITICAL(); // Enter the critical area 
   /*  establish  AppTaskCreate  Mission  */ 
 	xReturn = xTaskCreate((TaskFunction_t )AppTaskCreate,/*  Task entry function  */
 						  (const char* )"AppTaskCreate",/*  Task name  */
 						  (uint16_t )512, /*  Task stack size  */
 						  (void* )NULL,/*  Task entry function parameters  */
 						  (UBaseType_t )1, /*  Task priority  */
 						  (TaskHandle_t*)&AppTaskCreate_Handle);/* Task control block pointer */
 	taskEXIT_CRITICAL(); // Exit critical region 
 	/*  Start task scheduling  */
	 if (pdPASS == xReturn)
 		vTaskStartScheduler(); /*  Start the task , Turn on scheduling  */ (3)
	 else
	 	return -1; 
 
	 while (1); /*  Normal will not be implemented here  */
 }


4、 Create tasks

By calling FreeRTOS The task creation function of creates a task , In task creation ,FreeRTOS It will automatically perform a series of operating system initialization , Such as initializing memory .

// Create task function prototype 
BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
					    const char * const pcName,
					    const uint16_t usStackDepth,
					    void * const pvParameters,
					    UBaseType_t uxPriority,
					    TaskHandle_t * const pxCreatedTask )

5、 Start the task

When the task is created , We need to turn on the scheduler , Because creating is just adding tasks to the system , Not really scheduled yet , And idle tasks are not realized , The timer task has not been realized , All of these are starting the scheduling function vTaskStartScheduler() Implemented in .

Why idle tasks ? because FreeRTOS Once started , It is necessary to ensure that a task in the system is running at all times (Runing), And idle tasks cannot be suspended or deleted , Idle tasks have the lowest priority , So that other tasks in the system can preempt idle tasks at any time CPU Right to use .

These are all necessary things for the system , There is no need for users to implement ,FreeRTOS It's all done for us . After handling these necessary things , The system really starts up .


Reference resources

Wildfire FreeRTOS Actual combat of Kernel Implementation and application development

原网站

版权声明
本文为[z_ Curtain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020549199469.html