对于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的描述增加如下代码:
//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
运行效果: