Keil stm32 printf到Debug窗口


 

使用JlinkV8+Keil4
1、在main.c輸入以下代碼

#include <stdio.h>  
  
#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;  
};  
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、打開Trace

4、運行效果

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM