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. kuangbin_ShortPath E (POJ 1860)

    第一次做判环 然后RE了五次 死在了奇怪的点 memset(vis, 0, sizeof dis); memset(dis, 0, sizeof vis); 什么鬼?? 什么鬼?? 其实代码本身还是不 ...

  2. NetStatusEvent info对象的状态或错误情况的属性

      代码属性 级别属性 意义 "NetStream.Buffer.Empty" "status"  数据的接收速度不足以填充缓冲区.数据流将在缓冲区重新填充前中 ...

  3. bufferedReader 乱码问题

    public static void main(String arsg[]) throws Exception{ BufferedReader bufferedReader = new Buffere ...

  4. C函数之memcpy()函数用法

    函数原型 void *memcpy(void*dest, const void *src, size_t n); 功能 由src指向地址为起始地址的连续n个字节的数据复制到以destin指向地址为起始 ...

  5. Andorid面试问题整理

    Acitivty的四中启动模式与特点. standard:默认的启动模式 singleTop:适合那种接受通知启动的页面,比如新闻客户端之类的,可能会给你推送好几次 ,但是每次都是打开同一张页面调用o ...

  6. Goal driven performance optimization

    When your goal is to optimize application performance it is very important to understand what goal d ...

  7. python扫描内网banner信息

    小菜自己无聊写着玩,主要纪念以前的逗逼学习,可以改IPy import mechanize import cookielib import socket import argparse import ...

  8. javascript体系 DOM原理

    解释清楚DOM原理并不是一件容易的事,但是任何一个前端工程师,都必须牢牢掌握它. DOM整体架构: 图解: DOM,即针对XML文档的应用程序编程接口(API).通俗一点说,HTML属于XML的一种, ...

  9. 解决tomcat一闪而过问题

    环境:      jdk 1.8.0.91           windows2003           tomcat8.0 故障现象:启动tomcat 时, 一闪而过 排障步骤: a) 首先是要调 ...

  10. Oracle数据库——半期测验

    一.使用system用户登录SQL*PLUS,使用命令将scott用户解锁,并将scott用户的密码修改为: t_你的学号后三位(例如:t_165).然后,以scott用户连接数据库. 1. 使用sy ...