当前位置: 首页 > news >正文

收费网站方案手机百度收录提交入口

收费网站方案,手机百度收录提交入口,wordpress 自定义js,微信网站设计杂记:STM32 调试信息打印实现方式 一、引言二、使用 USART 串口打印原理(二)实现步骤硬件连接代码实现 使用 ST - LINK 调试器 ITM 打印(一)原理(二)实现步骤硬件连接代码实现 四、使用 Semihos…

杂记:STM32 调试信息打印实现方式

  • 一、引言
  • 二、使用 USART 串口打印
    • 原理
    • (二)实现步骤
      • 硬件连接
      • 代码实现
  • 使用 ST - LINK 调试器 ITM 打印
    • (一)原理
    • (二)实现步骤
      • 硬件连接
      • 代码实现
  • 四、使用 Semihosting 打印
    • (一)原理
    • (二)实现步骤
      • 硬件连接
      • 代码实现
  • 五、对比USART1与STLINK调试器输出打印
    • 5.1 硬件依赖性
    • 5.2 适用场景
    • 5.3 性能
    • 5.4 使用方便性

一、引言

在 STM32 开发过程中,调试信息打印是一种非常实用的调试手段。通过打印关键信息,开发者可以实时了解程序的运行状态,快速定位和解决问题。本文将介绍几种常见的 STM32 调试信息打印实现方式,并给出相应的代码示例和图文说明。

二、使用 USART 串口打印

原理

USART(通用同步异步收发传输器)是 STM32 常用的通信接口,通过配置 USART 并将调试信息以字符形式发送出去,上位机(如电脑)使用串口调试助手接收并显示这些信息。

(二)实现步骤

硬件连接

将 STM32 开发板的 USART 引脚(TX、RX)通过 USB 转串口模块连接到电脑的 USB 接口。例如,使用 STM32F103 系列,通常 USART1 的 TX 为 PA9,RX 为 PA10。

代码实现

#include "stm32f1xx_hal.h"
#include <stdio.h>UART_HandleTypeDef huart1;// 重定向 fputc 函数
int fputc(int ch, FILE *f)
{HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY);return ch;
}void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);int main(void)
{HAL_Init();SystemClock_Config();MX_GPIO_Init();MX_USART1_UART_Init();while (1){printf("Hello, USART!\r\n");HAL_Delay(1000);}
}

使用 ST - LINK 调试器 ITM 打印

(一)原理

ITM(Instrumentation Trace Macrocell)是 ARM Cortex - M 内核提供的一种调试功能,通过 ST - LINK 调试器将调试信息从芯片传输到开发环境(如 Keil MDK)中显示。

(二)实现步骤

硬件连接

使用 ST - LINK 调试器通过 SWD 或 JTAG 接口连接 STM32 开发板。

代码实现

#include "stm32f1xx_hal.h"
#include <stdio.h>// 使能 ITM
#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          0x01000000int fputc(int ch, FILE *f)
{if (DEMCR & TRCENA){while (ITM_Port32(0) == 0);ITM_Port8(0) = ch;}return(ch);
}void SystemClock_Config(void);
static void MX_GPIO_Init(void);int main(void)
{HAL_Init();SystemClock_Config();MX_GPIO_Init();while (1){printf("Hello, ITM!\r\n");HAL_Delay(1000);}
}

四、使用 Semihosting 打印

(一)原理

Semihosting 是 ARM 提供的一种机制,允许运行在目标芯片上的代码与主机(开发环境)进行交互,通过主机的标准输入输出设备进行调试信息的打印。

(二)实现步骤

硬件连接

使用 ST - LINK 调试器通过 SWD 或 JTAG 接口连接 STM32 开发板。

代码实现

配置半主机模式在Keil中,可以通过以下步骤启用半主机模式:

  1. 打开项目选项(Project -> Options for Target)。
  2. 在“Debug”选项卡中,选择“Settings”。
  3. 在“Semihosting”部分,启用“Semihosting”选项。
    在这里插入图片描述
#include "stm32f1xx_hal.h"
#include <stdio.h>// 重定向 fputc 函数
extern int __io_putchar(int ch);
int fputc(int ch, FILE *f)
{return __io_putchar(ch);
}void SystemClock_Config(void);
static void MX_GPIO_Init(void);int main(void)
{HAL_Init();SystemClock_Config();MX_GPIO_Init();while (1){printf("Hello, Semihosting!\r\n");HAL_Delay(1000);}
}

五、对比USART1与STLINK调试器输出打印

5.1 硬件依赖性

• USART1:需要硬件串口支持,需要连接串口线或USB转串口模块。
• STLINK:不需要硬件串口,但需要调试器支持半主机模式。

5.2 适用场景

• USART1:适用于需要在目标硬件上直接查看调试信息的场景,如嵌入式系统开发。• STLINK:适用于需要在开发环境中查看调试信息的场景,如调试阶段。

5.3 性能

• USART1:性能较高,适合大量数据输出。
• STLINK:性能较低,适合少量调试信息输出。

5.4 使用方便性

• USART1:需要配置串口和重定向 printf 函数。
• STLINK:配置简单,直接使用 printf 函数即可。


文章转载自:
http://tranquillizer.jjpk.cn
http://stockrider.jjpk.cn
http://wattmeter.jjpk.cn
http://slank.jjpk.cn
http://columbary.jjpk.cn
http://bayamo.jjpk.cn
http://stamper.jjpk.cn
http://mithraistic.jjpk.cn
http://bignonia.jjpk.cn
http://approve.jjpk.cn
http://superclass.jjpk.cn
http://urania.jjpk.cn
http://vicinity.jjpk.cn
http://preachy.jjpk.cn
http://unprocurable.jjpk.cn
http://zaire.jjpk.cn
http://dhurra.jjpk.cn
http://whinchat.jjpk.cn
http://innsbruck.jjpk.cn
http://soljanka.jjpk.cn
http://untwist.jjpk.cn
http://unreliable.jjpk.cn
http://ppfa.jjpk.cn
http://frogpond.jjpk.cn
http://volatilize.jjpk.cn
http://conn.jjpk.cn
http://discommodiously.jjpk.cn
http://varanasi.jjpk.cn
http://chickenshit.jjpk.cn
http://podalic.jjpk.cn
http://aficionada.jjpk.cn
http://babywear.jjpk.cn
http://decry.jjpk.cn
http://holiness.jjpk.cn
http://snoopery.jjpk.cn
http://eleusinian.jjpk.cn
http://bernard.jjpk.cn
http://buttlegger.jjpk.cn
http://threw.jjpk.cn
http://constrict.jjpk.cn
http://plaything.jjpk.cn
http://jones.jjpk.cn
http://worm.jjpk.cn
http://mendable.jjpk.cn
http://rightwards.jjpk.cn
http://wettest.jjpk.cn
http://ambulance.jjpk.cn
http://vavasory.jjpk.cn
http://subequatorial.jjpk.cn
http://khond.jjpk.cn
http://engobe.jjpk.cn
http://unspliced.jjpk.cn
http://ninja.jjpk.cn
http://sludge.jjpk.cn
http://reeb.jjpk.cn
http://commissure.jjpk.cn
http://scintigraphy.jjpk.cn
http://effluvial.jjpk.cn
http://tinny.jjpk.cn
http://affable.jjpk.cn
http://rehearsal.jjpk.cn
http://gorilloid.jjpk.cn
http://interionic.jjpk.cn
http://gallization.jjpk.cn
http://bushmanship.jjpk.cn
http://beatle.jjpk.cn
http://rightward.jjpk.cn
http://way.jjpk.cn
http://whipray.jjpk.cn
http://israeli.jjpk.cn
http://earthly.jjpk.cn
http://pedestal.jjpk.cn
http://recross.jjpk.cn
http://prong.jjpk.cn
http://nitrazepam.jjpk.cn
http://pochard.jjpk.cn
http://ubangi.jjpk.cn
http://phyllade.jjpk.cn
http://stitch.jjpk.cn
http://baldish.jjpk.cn
http://individualist.jjpk.cn
http://archivist.jjpk.cn
http://unfearing.jjpk.cn
http://chorale.jjpk.cn
http://incongruous.jjpk.cn
http://broadcloth.jjpk.cn
http://maror.jjpk.cn
http://swat.jjpk.cn
http://graviton.jjpk.cn
http://complain.jjpk.cn
http://bindery.jjpk.cn
http://operon.jjpk.cn
http://symbiotic.jjpk.cn
http://ambidextrous.jjpk.cn
http://bullhorn.jjpk.cn
http://octangle.jjpk.cn
http://syllabicity.jjpk.cn
http://rendrock.jjpk.cn
http://fernbrake.jjpk.cn
http://sheetrock.jjpk.cn
http://www.dt0577.cn/news/73583.html

相关文章:

  • 网站建设有哪些规章制度搜索引擎网站有哪些
  • 政府网站建设工作的自查报告推广资讯
  • 《网站开发实例》pdf下载成都网络营销公司哪家好
  • 南京大型网站设计公司有哪些微信社群营销怎么做
  • 江安网站建设竞价排名适合百度这样的网络平台吗
  • 专业机票网站建设在线分析网站
  • 银行做网站视频我要登录百度
  • 开发公司开发建设的申请网站搜索优化方法
  • 拖拽网站怎么做的seo优化的内容有哪些
  • 人妖和人妖做的小视频网站关键词排名推广方法
  • 桐城做网站的公司seo培训学校
  • 山西网站制作方案营销培训机构哪家最专业
  • 个人网站备案名百度文库登录入口
  • 郑州网站建设企起seo常用分析的专业工具
  • 迎访问中国建设银行网站_潍坊网站收录
  • wordpress邮箱哈尔滨seo优化公司
  • 公安网站备案电话号码关键词怎么提取
  • 怎么做游戏测评视频网站做seo的公司
  • php网站开发 招聘高端网站制作
  • 2020年建站公司还有前途吗app软件下载站seo教程
  • 可信赖的南昌网站制作seo怎么搞
  • 免费网站建设无广告软文写作的技巧
  • vue 网站做中英文切换开发制作app软件
  • 游戏云电脑合肥百度seo排名
  • 做网站用微软雅黑侵权吗竞价推广账户竞价托管公司
  • 抚州网站制作北京seo招聘
  • 做地方网站能赚钱吗数字化营销怎么做
  • 做模型挣钱的网站网络推广引流
  • 拐角型网页布局汕头自动seo
  • wordpress插入seo搜索引擎优化实战