Files
TencentOS-tiny/doc/19.TencentOS_Tiny_Simulator_Use_MDK.md
David Lin 9c7327662b Update 19.TencentOS_Tiny_Simulator_Use_MDK.md
删除多余描述字“开”
2020-06-06 17:17:44 +08:00

42 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 使用MDK软件全仿真调试体验TencentOS Tiny
有许多朋友想体验或者学习一下TencentOS Tiny内核但是手上却没有合适的硬件没关系本文将教您如何使用MDK软件来仿真调试TencentOS Tiny内核。
参考工程连接https://github.com/Tencent/TencentOS-tiny/tree/master/board/MDK_Simulator_STM32F103RCT6/KEIL/hello_world
我们首先在TencentOS Tiny官库上找到一个STM32工程用MDK软件打开修改printf 函数映射,如图所示:
![](image/MDK_Simulator_Guide/add_printf_code.png)
需要添加的代码如下:
```
#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 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);
}
```
添加完毕后在MDK工程上打开option选项选择debug选项调试方式选择User Simulator并修改调试参数如下图
![](image/MDK_Simulator_Guide/set_simulator_para.png)
完成软件仿真参数配置后就可以点击debug按钮开始调试了打开调试窗口后选择view->Serial windows->debug 就可以打开调试日志窗口了如图可以看到TencentOS Tiny内核的两个任务输出的日志信息。
![](image/MDK_Simulator_Guide/debug_window.png)