cotex_m3内核的ARM提供了ITM串口打印观测的功能,可以不用ARM单片机自己的串口就可在开发时候串口打印调试.节约了宝贵的内部资源,同时也为调试提供了方便.使用方法如下:
1 将下面的SWO_Printf.c加入到工程中
/*SWO_Printf*/
#include <stdio.h>
/*1 ÔÚkeil mdkÖÐÑ¡ÔñʹÓÃswo; 2http://blog.csdn.net/xiaolei05/article/details/8526021 */
//Add ITM Port register definitions to your source code.
#define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
#define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
#define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
#define TRCENA 0x01000000
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f) {
if (DEMCR & TRCENA) {
while (ITM_Port32(0) == 0);
ITM_Port8(0) = ch;
}
return(ch);
}
2,然后调试选择sw方式,芯片的主频率要设置正确,否则出现乱码异常,设置如下
3 在仿真下打开KEIL_MDK的view-seiral windows - debug(printf) view
4使用printf开始打印调试