본문 바로가기
임베디드.일렉트로닉스

KEIL MDK-ARM. Debug (printf) Viewer 에서 printf 출력결과 보기.

by i.got.it 2019. 12. 30.
 

개요

 
KEIL MDK-ARM 으로 작성된 펌에어코드상의 printf 구문의 출력값을 KEIL MDK-ARM Debug (prontf) Viewer  창에서 보기 위한 설정법.

 

 
본 방법이 편한이유.
1. 통상 펌웨어 상의 코드에서 printf 출력결과 보려면 타겟칩에 UART 결선하고 PC측에서 하이퍼 터미널등을 이용하여 보게된다.
2. 상기1처럼 별도의 결선처리와 PC측 하이퍼 터미널 없이 타겟보드와 debug 만 연결된 상태(예 : 아래 사진처럼 ST-LINK/V2 연결된 상태, 혹은 ULINK 등) KEIL 개발환경에서 펌웨어 상의  printf 출력결과를 즉시 볼 수 있다.

 

 
 
 

 

 

 

상세- KEIL Debug (printf) Viewer 에 printf 출력 보이게 하기.

 
 
1. 펌웨어 상의 처리
프로젝트에 c 파일 추가(예: 파일명 DebugPrintf.c )하고 아래 코드 작성.
- 아래예는 타겟칩이 STM32L4 인 경우임.
 
1
2
3
4
5
6
7
8
9
10
11
/*
file : DebugPrintf.c
*/
#include "stm32l4xx_hal.h"  // STM32L4 사용하는경우.
#include "stdio.h"
 
int fputc(int c, FILE *stream)
{
      return(ITM_SendChar(c));
}
 
 
혹은, 위와같이 특정칩에 종속되지 않도록 하려면 아래 처럼 작성.
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
file : DebugPrintf.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; // Add whatever needed  
};
 
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. KEIL 프로젝트 옵션에서 Debug 관련 설정.
프로젝트 옵션의 탭 Debug (본 예에서는 ST-Link 를 Debug로 사용하는 경우임)-> 버튼  Settings 클릭하여 뜬 설정창에서,
탭 trace 클릭하여 아래 붉박처럼 설정한다.
아래 그림의 파박은 타겟팁이 실제 작동중인 시스템 클럭을 타이핑해줘야 한다.

 

3. KEIL Debug 에서 printf 출력보기 설정.

Keil Debug 모드에서 메뉴 View -> Serial Window -> Debug (printf) Viewer 클릭한다.

이제 KEIL Debug 모드에서 아래그림 파박 처럼 창 "Debug (printf) Viewer" 가 추가되고 이곳에는 펌웨어상에서 printf 출력이 보이게 된다.

아래 보이는 Hello igotit 은 펌웨어의 main 에 있는 printf("Hello igotit"); 실행된 것이 보이는 예.

 

 

 

 

 

영상으로 작동상황 및 설정 보기. 

 

 

 

 

 

연관 

 

https://igotit.tistory.com/268

 

ST-LINK V2.-STM32, STM8 Debugging and Programming Tool.

구입처 : https://coupa.ng/biMX6M ARM용개발장비 ST - Link/V2 COUPANG www.coupang.com 제조사 제공정보 : http://www.st.com/web/catalog/tools/FM146/CL1984/SC1046/SS1680/PF251168 사용자 설명서 : http://..

igotit.tistory.com

 

https://igotit.tistory.com/818

 

ST-LINK V2. KEIL Trace: No Synchronization 오류 해결방법.

오류증상. KEIL 의 Debug모드에서 아래 그림 처럼 오류 발생. 해결책. ST-LINK V2 firmware update 한다. -> http://igotit.tistory.com/817 ///818.

igotit.tistory.com

 


첫 등록 : 2016년 7월 16일 

최종 수정 : 2019년 12월 30일 

단축 주소 : https://igotit.tistory.com/815

 


 

 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5