飞思卡尔 k60/k64 移植FreeRTOS+USB
????????每年七八月份是智能車大賽的比賽時間,前段時間,學校車隊的學弟問我嵌入式系統的問題,于是筆者拿起多年未碰的K60/K64芯片,搭建了一個FreeRTOS+USB的系統框架。文章結尾提供源碼。
1.官網下載最新SDK
我們先從nxp官網下載對應芯片的SDK?NXP Sign In | Register
筆者下載的版本是2_10_0,解壓SDK,拷貝如圖文件用于新建工程中。現在的庫是nxp提供的fsl庫,用這庫有什么好處呢?用上這個官方庫,今后我們再采用nxp其他芯片(rt系列,lpc等等)也很容易上手(建議別采用寄存器寫代碼,開發效率會很低下,可移植性也很差)。
2.搭建工程(基于Keil)
查看最新的startup文件,這里的匯編標準(GNU ARM 匯編)正好對應Keil的AC6版本(關于AC6的好處有哪些,可以去搜索了解下,后面很多新出的芯片提供的Demo,基本都是采用的AC6版本。AC5版本逐漸也會被淘汰掉)
ARM 官網有如下一段話:
 General update releases on the last branch, version 5.06, ended in H2 2017 with 5.06u6. After this, further support and maintenance will be available through Arm Compiler Long Term Maintenance releases with maintenance continuing until at least summer 2020. Arm Compiler 5.06 for Certification and Arm Compiler 5.06 Long Term Maintenance releases will each be supported by an Arm Compiler Qualification Kit.
 ?
3.移植FreeRTOS
這里筆者采用的是比較新的版本 V10.3.0. 具體移植內容如圖,啟動代碼跟以往版本有區別,這里port.c文件引用路徑需要特別注意。
?基本裁剪由 FreeRTOSConfig.h 統一管理,如下:
#define configUSE_PREEMPTION 1 #define configUSE_TICKLESS_IDLE 0 #define configCPU_CLOCK_HZ (SystemCoreClock) #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES 5 #define configMINIMAL_STACK_SIZE ((unsigned short)90) #define configMAX_TASK_NAME_LEN 20 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_TASK_NOTIFICATIONS 1 #define configUSE_MUTEXES 1 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_COUNTING_SEMAPHORES 1 #define configUSE_ALTERNATIVE_API 0 /* Deprecated! */ #define configQUEUE_REGISTRY_SIZE 8 #define configUSE_QUEUE_SETS 0 #define configUSE_TIME_SLICING 0 #define configUSE_NEWLIB_REENTRANT 0 #define configENABLE_BACKWARD_COMPATIBILITY 0 #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5/* Used memory allocation (heap_x.c) */ #define configFRTOS_MEMORY_SCHEME 4 /* Tasks.c additions (e.g. Thread Aware Debug capability) */ #define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1/* Memory allocation related definitions. */ #define configSUPPORT_STATIC_ALLOCATION 0 #define configSUPPORT_DYNAMIC_ALLOCATION 1 #define configTOTAL_HEAP_SIZE ((size_t)(32 * 1024)) #define configAPPLICATION_ALLOCATED_HEAP 0/* Hook function related definitions. */ #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 #define configCHECK_FOR_STACK_OVERFLOW 0 #define configUSE_MALLOC_FAILED_HOOK 0 #define configUSE_DAEMON_TASK_STARTUP_HOOK 0/* Run time and task stats gathering related definitions. */ #define configGENERATE_RUN_TIME_STATS 0 #define configUSE_TRACE_FACILITY 1 #define configUSE_STATS_FORMATTING_FUNCTIONS 0/* Task aware debugging. */ #define configRECORD_STACK_HIGH_ADDRESS 1/* Co-routine related definitions. */ #define configUSE_CO_ROUTINES 0 #define configMAX_CO_ROUTINE_PRIORITIES 2/* Software timer related definitions. */ #define configUSE_TIMERS 1 #define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) #define configTIMER_QUEUE_LENGTH 10 #define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2)/* Define to trap errors during development. */ #define configASSERT(x) if(( x) == 0) {taskDISABLE_INTERRUPTS(); for (;;);}/* Optional functions - most linkers will remove unused functions anyway. */ #define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 #define INCLUDE_xTaskGetSchedulerState 1 #define INCLUDE_xTaskGetCurrentTaskHandle 1 #define INCLUDE_uxTaskGetStackHighWaterMark 0 #define INCLUDE_xTaskGetIdleTaskHandle 0 #define INCLUDE_eTaskGetState 0 #define INCLUDE_xEventGroupSetBitFromISR 1 #define INCLUDE_xTimerPendFunctionCall 1 #define INCLUDE_xTaskAbortDelay 0 #define INCLUDE_xTaskGetHandle 0 #define INCLUDE_xTaskResumeFromISR 1/* Override the default implementation of sbSEND_COMPLETED so the macro creates an interrupt in the M4 core. See the comments at the top of main.c. */ //#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateSecondaryToPrimaryInterrupt( pxStreamBuffer )#if defined(__ICCARM__)||defined(__CC_ARM)||defined(__GNUC__)/* in Kinetis SDK, this contains the system core clock frequency */#include <stdint.h>extern uint32_t SystemCoreClock; #endif/* Interrupt nesting behaviour configuration. Cortex-M specific. */ #ifdef __NVIC_PRIO_BITS /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ #define configPRIO_BITS __NVIC_PRIO_BITS #else #define configPRIO_BITS 4 /* 15 priority levels */ #endif/* The lowest interrupt priority that can be used in a call to a "set priority" function. */ #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1U << (configPRIO_BITS)) - 1)/* The highest interrupt priority that can be used by any interrupt service routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER PRIORITY THAN THIS! (higher priorities are lower numeric values. */ #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 2/* Interrupt priorities used by the kernel port layer itself. These are generic to all Cortex-M ports, and do not rely on any particular library functions. */ #define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ #define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */ #define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler //#define xPortSysTickHandler SysTick_Handler?調度時鐘修改如下:
void SysTick_Handler(void) {if(xTaskGetSchedulerState()!=taskSCHEDULER_NOT_STARTED){xPortSysTickHandler();} }?4.USB組件移植
usb組件,官方SDK也有提供于是我們直接拷貝到新的工程中。需要注意osa在SDK其他地方(以往老版本是放在usb子文件夾里的),筆者統一放到一起。
?這里筆者直接使用官方的一個 usb hid demo.關聯文件如圖:
?5.完善系統,大功告成
創建開始任務,開啟系統調度
int main(void) {xBSP_Config();/*Create Start Task*/ if(xTaskCreate(xTask_Start, "Task_Start", TASK_STACK_SIZE_StartTask, NULL, TASK_PRIORITY_StartTask, &Handle_StartTask) != pdPASS){_Error_Handler(__FILE__, __LINE__);} vTaskStartScheduler(); //開始系統調度while(1){/* 如果系統正常啟動是不會運行到這里的,運行到這里極有可能是空閑任務heap空間不足造成創建失敗 */} }初始化周邊外設,創建顯示任務(就一個點燈程序)
static void xTask_Start(void *pvParameters) {xBSP_GPIO_Init();USB_DeviceApplicationInit();//這里就是LED 顯示邏輯相關if(xTaskCreate(xAPP_GuiMainTask, "xAPP_GuiMainTask", TASK_STACK_SIZE_GuiMainTask, NULL, TASK_PRIORITY_GuiMainTask, NULL) != pdPASS){_Error_Handler(__FILE__, __LINE__);}/*刪除開始任務*/ vTaskDelete(NULL); }void xAPP_GuiMainTask(void *pvParameters) {for(;;){AUDIOLED_TOGGLE(); vTaskDelay(100);} }測試:燈正常閃爍,插入USB設備正常枚舉
下載地址:MK64_RTOS_USB飛思卡爾智能車-OS文檔類資源-CSDN下載
總結
以上是生活随笔為你收集整理的飞思卡尔 k60/k64 移植FreeRTOS+USB的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 手机安装Python
- 下一篇: LAYOUT BGA布线规则
