(Keil) Debug & Simulation 操作

0x00

printf在MCU環境下print debug error message,利用Logic Analyzer模擬MCU register or GPIO狀態。

若是要要使用printf函數且顯示在Debug Viewer (printf) ,必須加上Regtarge.c這個檔案實際內容如下

 1 #include <stdio.h>
 2 #include <rt_misc.h>
 3 #include "stm32f4xx.h"
 4 
 5 #pragma import(__use_no_semihosting_swi)
 6 extern int  SendChar(int ch);
 7 extern int  GetKey(void);
 8 
 9 struct __FILE {
10   int handle;
11 };
12 
13 FILE __stdout;
14 FILE __stdin;
15 
16 /* #define ITM_DEBUG = 1 */
17 #define ITM_DEBUG = 1
18 
19 //#if defined (ITM_DEBUG)
20 #ifdef ITM_DEBUG
21 
22 int fputc(int ch, FILE *f) {
23   return (ITM_SendChar(ch));
24 }
25 #else
26 
27 int fputc(int ch, FILE *f)
28 {
29     return SendChar(ch);
30 }
31 
32 #endif
33 
34 int fgetc(FILE *f) {
35   return (SendChar(GetKey()));
36 }
37 
38 void _ttywrch(int ch) {
39  SendChar (ch);
40 }
41 
42 int ferror(FILE *f) {
43   return EOF;
44 }
45 
46 void _sys_exit(int return_code) {
47 label:  goto label;
48 }

在6, 7行的函數主要有在main.c裡頭實現,目的是將printf函數內容透過USART傳送到PC,而Regtarge.c主要目的改寫底層函數。

extern int  GetKey(void);
extern int  GetKey(void);

在配置上我捫必須做一點小更改 Micro LIB 打勾,這樣就可以使用C standard library相關函數

但這樣還無法完全使用printf顯示到 debug viewer上,必須在對debugger (ICE) 做一點設定上的修改。

Core Clock 必須填上System Clock才能正常顯示在視窗上。

 

假如需要使用類似邏輯分析儀(LA)的功能,可以透過Keil配置使用 Logic Analyzer

首先針對MCU的Mamory Map針對週邊實際定義的Address設定read/write權限。

建立一個ini檔案內容如下

map 0x40000000,0x400FFFFF read write

在Keil裡頭選擇ini檔案位置,確認可以針對Address可以進行模擬。紅框部分都是需要注意的地方。

Keil LA 使用上必須填寫Address的正確位置,範例是針對GPIO做模擬,所以只會看到GPIO H/L。

Sample code是delay 500us 進行GPIO轉態,d代表cursor的時間差0.5ms也就是delay 500us。

 輸入Reg使用方法如下。

 

 

posted on 2018-12-01 23:36  OO程式猿  阅读(2132)  评论(0编辑  收藏  举报

导航