MDK+硬件仿真器实现debugprintf()-stm32

1MDK工程设置如下

2其中stm32debug.ini文件内容为

/******************************************************************************/

/* STM32DBG.INI: STM32 Debugger Initialization File */

/******************************************************************************/

// <<< Use Configuration Wizard in Context Menu >>> //

/******************************************************************************/

/* This file is part of the uVision/ARM development tools. */

/* Copyright (c) 2005-2007 Keil Software. All rights reserved. */

/* This software may only be used under the terms of a valid, current, */

/* end user licence from KEIL for a compatible version of KEIL software */

/* development tools. Nothing else gives you the right to use this software. */

/******************************************************************************/

FUNC void DebugSetup (void) {

// <h> Debug MCU Configuration

// <o1.0> DBG_SLEEP <i> Debug Sleep Mode

// <o1.1> DBG_STOP <i> Debug Stop Mode

// <o1.2> DBG_STANDBY <i> Debug Standby Mode

// <o1.5> TRACE_IOEN <i> Trace I/O Enable

// <o1.6..7> TRACE_MODE <i> Trace Mode

// <0=> Asynchronous

// <1=> Synchronous: TRACEDATA Size 1

// <2=> Synchronous: TRACEDATA Size 2

// <3=> Synchronous: TRACEDATA Size 4

// <o1.8> DBG_IWDG_STOP <i> Independant Watchdog Stopped when Core is halted

// <o1.9> DBG_WWDG_STOP <i> Window Watchdog Stopped when Core is halted

// <o1.10> DBG_TIM1_STOP <i> Timer 1 Stopped when Core is halted

// <o1.11> DBG_TIM2_STOP <i> Timer 2 Stopped when Core is halted

// <o1.12> DBG_TIM3_STOP <i> Timer 3 Stopped when Core is halted

// <o1.13> DBG_TIM4_STOP <i> Timer 4 Stopped when Core is halted

// <o1.14> DBG_CAN_STOP <i> CAN Stopped when Core is halted

// </h>

_WDWORD(0xE0042004, 0x00000027); // DBGMCU_CR

_WDWORD(0xE000ED08, 0x20000000); // Setup Vector Table Offset Register

}

DebugSetup(); // Debugger Setup

3项目工程加载retarget.c或者debugprint.c,其中retarget.c内容如下

#include <stdio.h>

#include "stm32f10x.h"

#pragma import(__use_no_semihosting_swi)

struct __FILE { int handle; /* Add whatever you need here */ };

FILE __stdout;

FILE __stdin;

int fputc(int ch, FILE *f)

{

return ITM_SendChar(ch);

}

volatile int32_t ITM_RxBuffer;

int fgetc(FILE *f)

{

while (ITM_CheckChar() != 1) __NOP();

return (ITM_ReceiveChar());

}

int ferror(FILE *f)

{

/* Your implementation of ferror */

return EOF;

}

void _ttywrch(int c)

{

fputc(c, 0);

}

int __backspace()

{

return 0;

}

void _sys_exit(int return_code)

{

label:

goto label; /* endless loop */

}

debugprint.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 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);

}

4包含头文件#include <stdio.h>,并调用printf

5在debug中打开输出仿真:View-serial-debug(printf)

MDK+硬件仿真器实现debugprintf()-stm32的更多相关文章

  1. SLAM+语音机器人DIY系列:(四)差分底盘设计——1.stm32主控硬件设计

    摘要 运动底盘是移动机器人的重要组成部分,不像激光雷达.IMU.麦克风.音响.摄像头这些通用部件可以直接买到,很难买到通用的底盘.一方面是因为底盘的尺寸结构和参数是要与具体机器人匹配的:另一方面是因为 ...

  2. STM32硬件IIC驱动设计(转)

    源: STM32硬件IIC驱动设计 参考: STM32—硬件IIC主机通信 STM32’s I2C 硬件BUG引发的血案(qzm) 解决STM32 I2C接口死锁在BUSY状态的方法讨论

  3. STM32环境搭建/学习观点/自学方法 入门必看

    文章转自armfly开发板V4软件开发手册,分享学习~ 今天有幸看到armfly的开发板软件开发手册,开头的基础知识,真的很有用,还好有看到,一切都不迟,感悟很多,摘抄部分,学习分享~ 关于开发环境的 ...

  4. 嵌入式单片机STM32应用技术(课本)

    目录SAIU R20 1 6 第1页第1 章. 初识STM32..................................................................... ...

  5. STM32之串口通信

    一.RS232通信协议 1.概念 个人计算机上的通讯接口之一,由电子工业协会(Electronic Industries Association,EIA) 所制定的异步传输标准接口. 2.电气特性 逻 ...

  6. STM32 ADC多通道转换DMA模式与非DMA模式两种方法(HAL库)

    一.非DMA模式(转) 说明:这个是自己刚做的时候百度出来的,不是我自己做出来的,因为感觉有用就保存下来做学习用,原文链接:https://blog.csdn.net/qq_24815615/arti ...

  7. 【转】stm32 IAP升级程序

      一.什么是IAP,为什么要IAP       IAP即为In Application Programming(在应用中编程),一般情况下,以STM32F10x系列芯片为主控制器的设备在出厂时就已经 ...

  8. 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU硬件那些事(2.6)- 串行NOR Flash下载算法(MCUXpresso IDE篇)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是MCUXpresso IDE开发环境下i.MXRT的串行NOR Flash下载算法设计. 在i.MXRT硬件那些事系列之<在串行N ...

  9. 痞子衡嵌入式:超级下载算法RT-UFL v1.0在Keil MDK下的使用

    痞子衡主导的"学术"项目 <RT-UFL - 一个适用全平台i.MXRT的超级下载算法设计> v1.0 版发布近 4 个月了,部分客户已经在实际项目开发调试中用上了这个 ...

随机推荐

  1. STL学习小结

    STL就是Standard Template Library,标准模板库.这可能是一个历史上最令人兴奋的工具的最无聊的术语.从根本上说,STL是一些"容器"的集合,这些" ...

  2. Analyzing The Papers Behind Facebook's Computer Vision Approach

    Analyzing The Papers Behind Facebook's Computer Vision Approach Introduction You know that company c ...

  3. pgbouncer配置

    DESCRIPTION pgbouncer is a PostgreSQL connection pooler. Any target application can be connected to  ...

  4. rman的使用

    下面是两种连接方式[oracle@oracle3A ~]$ rman target/ Recovery Manager: Release 11.2.0.1.0 - Production on Mon ...

  5. Openjudge计算概论-求序列中的众数

    /*===================================== 求序列中的众数 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一个长度为N的整数序列 (不多于128 ...

  6. JavaScript文件中调用AngularJS内部方法或改变$scope变量

    需要在其他JavaScript文件中调用AngularJS内部方法或改变$scope变量,同时还要保持双向数据绑定: 首先获取AngularJS application: 方法一:通过controll ...

  7. JS-unicode编码转换

    JS-unicode编码转换 <script type="text/Javascript"> var toUN = { on: function(str) { var ...

  8. python读取excel的行数

    基于python3.x下 需要包 from openpyxl import load_workbook 代码如下: from openpyxl import load_workbook wb = lo ...

  9. windows系统安装MongoDB

    最近一直在学习node.js,nodejs开发指南中有一个微博的web开发项目,由于该书出的比较早(2012出的),目前为止利用nodejs进行web开发各种组合技术都发生了很大的更新,例如书中选择的 ...

  10. Hermes:来自腾讯的实时检索分析平台

    实时检索分析平台(Hermes)是腾讯数据平台部为大数据分析业务提供一套实时的.多维的.交互式的查询.统计.分析系统,为各个产品在大数据的统计分析方面提供完整的解决方案,让万级维度.千亿级数据下的秒级 ...