對於CMSIS函數的調用,ARM官方都是給的stm32的例子,而且stm32調用CMSIS好像也沒出過問題。
問題來源:看到iar的技術文章Using CoreSight Trace Techniques on Cortex-M3/M4,感覺不錯,在kinetis上一一實踐,發現Example 5: Printf via SWO這篇文章中描述的功能不能實現。
問題分析:主要是函數ITM_SendChar()沒有辦法調用;而該函數定義在core_CM4.h頭文件中,在ARM官方的CMSIS描述中該頭文件應該在Device Header File <device.h>中被包含,但是飛思卡爾的頭文件MK60DZ10.h又未包含該頭文件,不知道飛思卡爾為什麼不支持cmsis。
解決辦法:根據CMSIS的描述增加如下代碼:
[cpp]
//cmsis
#define __CM4_REV 0x0001 /* Core revision r0p1 */
#define __MPU_PRESENT 0 /* MPU present or not */
#define __NVIC_PRIO_BITS 3 /* Number of Bits used for Priority Levels */
#define __Vendor_SysTickConfig 0 /* Set to 1 if different SysTick Config is used */
#define __FPU_PRESENT 0 /* FPU present or not */
typedef enum IRQn
{
/****** Cortex-M4 Processor Exceptions Numbers ***************************************************/
/* ToDo: use this Cortex interrupt numbers if your device is a CORTEX-M3 / Cortex-M4 device */
NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
MemoryManagement_IRQn = -12, /*!< 4 Memory Management Interrupt */
BusFault_IRQn = -11, /*!< 5 Bus Fault Interrupt */
UsageFault_IRQn = -10, /*!< 6 Usage Fault Interrupt */
SVCall_IRQn = -5, /*!< 11 SV Call Interrupt */
DebugMonitor_IRQn = -4, /*!< 12 Debug Monitor Interrupt */
PendSV_IRQn = -2, /*!< 14 Pend SV Interrupt */
SysTick_IRQn = -1, /*!< 15 System Tick Interrupt */
/****** Device Specific Interrupt Numbers ********************************************************/
/* ToDo: add here your device specific external interrupt numbers
according the interrupt handlers defined in startup_Device.s
eg.: Interrupt for Timer#1 TIM1_IRQHandler -> TIM1_IRQn */
} IRQn_Type;
/* ToDo: include the correct core_cm#.h file
core_cm0.h if your device is a CORTEX-M0 device
core_cm3.h if your device is a CORTEX-M3 device
core_cm4.h if your device is a CORTEX-M4 device */
#include <core_cm4.h> /* Cortex-M# processor and core peripherals */
/* ToDo: include your system_<Device>.h file
replace '<Device>' with your device name */
//cmsis
運行效果: