1,下載FreeRTOS
https://www.freertos.org/a00104.html
點擊下載后,會進入如下界面
之后會彈出下載界面,格式為.EXE,不用懷疑。不是木馬。
等待下載完成,速度比較慢。
下載完成后解壓文件。
2,安裝keil5 ,下載安裝STM32L庫及相關文件。
推薦安裝使用JSON庫
安裝完成后,新建工程,新建組,新建目錄文件夾拷貝相關目錄到自己目錄下,
拷貝FreeRTOSv10.2.0\FreeRTOS\Source的文件 heapX.c在portable中的FreeRTOSv10.2.0\FreeRTOS\Source\portable\MemMang中,keil加載FreeRTOSv10.2.0\FreeRTOS\Source\portable\RVDS\ARM_CM3中的文件。
添加這個文件夾路徑到編譯Path下,添加Define :STM32L1XX_MD,USE_STDPERIPH_DRIVER
選擇編譯器編譯
#ifdef __ICCARM__ #include "stm32l1xx_tim.h" //ʶ±ðIAR±àÒë extern void vConfigureTimerForRunTimeStats( void ); extern unsigned long ulTIM6_OverflowCount; #endif /* __ICCARM__ */ #ifdef __CC_ARM //ʶ±ðkeil±àÒë #include "stm32l1xx_tim.h" extern void vConfigureTimerForRunTimeStats( void ); extern unsigned long ulTIM6_OverflowCount;
打開FreeRTOSConfig.h文件,在其最下面添加一下宏定義,這些宏將FreeRTOS的這三個回調跟stm32官方的對應起來,這樣就不用修改啟動文件。同時需要將stm32f10x_it.c里邊對應的三個函數注釋掉或者加上__weak關鍵字。
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
#define vPortSVCHandler SVC_Handler
編譯報錯:
修改main.c文件
添加如下函數:
void vApplicationTickHook(void) { /* This function will be called by each tick interrupt if configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be added here, but the tick hook is called from an interrupt context, so code must not attempt to block, and only the interrupt safe FreeRTOS API functions can be used (those that end in FromISR()). */ } void vApplicationIdleHook(void) { /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle task. It is essential that code added to this hook function never attempts to block in any way (for example, call xQueueReceive() with a block time specified, or call vTaskDelay()). If the application makes use of the vTaskDelete() API function (as this demo application does) then it is also important that vApplicationIdleHook() is permitted to return to its calling function, because it is the responsibility of the idle task to clean up memory allocated by the kernel to any task that has since been deleted. */ } void vApplicationMallocFailedHook(void) { /* vApplicationMallocFailedHook() will only be called if configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook function that will get called if a call to pvPortMalloc() fails. pvPortMalloc() is called internally by the kernel whenever a task, queue, timer or semaphore is created. It is also called by various parts of the demo application. If heap_1.c or heap_2.c are used, then the size of the heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used to query the size of free heap space that remains (although it does not provide information on how the remaining heap might be fragmented). */ taskDISABLE_INTERRUPTS(); for(;;); }
添加如下頭文件:#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"