当前位置:网站首页>STM32 printf问题总结 semihosting microLIB理解
STM32 printf问题总结 semihosting microLIB理解
2022-07-29 05:23:00 【BobBobBao】
STM32使用printf问题总结
背景:使用STM32F4开发板串口时,想用c语言自带的printf函数把字符串输出到串口调试助手。
- 首先需要重定义fputc()、fgetc()函数
///重定向c库函数printf到串口DEBUG_USART,重定向后可使用printf函数
int fputc(int ch, FILE *f)
{
/* 发送一个字节数据到串口DEBUG_USART */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 1000);
return (ch);
}
///重定向c库函数scanf到串口DEBUG_USART,重写向后可使用scanf、getchar等函数
int fgetc(FILE *f)
{
int ch;
HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 1000);
return (ch);
}
勾选options for Target–>Target–>Use MicroLIB,使用MicroLIB库。
-microLIB 是标准C库的一个备选库,用于极少内存的嵌入式硬件中。
-microLIB不支持标准库
-主要完成以下工作:
-创建一个可执行C程序的环境:创建一个堆栈、创建一个堆(如果需要)、初始化程序用到的库
-调用main()开始执行半主机(semi-hosting):它是一种机制,使得运行在ARM目标机上的代码能够通信,并使用运行了调试器的主机上的Input/Output工具
-开发初期,开发者可能根本不知道该ARM器件上有什么输入输出设备,而半主机机制使得开发者不用知道ARM器件的外设,利用主机电脑的外设就可以实现输入输出调试。
-如果要使用ARM器件上的输入、输出设备,首先要关闭semihosting。然后再将输入输出重定向到ARM器件上。
-microLIB 编译时通过Low-Level Functions与硬件连接,采用删减版high-level functions,没用system I/O functions。如果不使用microLIB库,而使用标准库(默认使用semihosting),调用printf()之类的函数,会导致死机。解决方法:
-在程序中添加编译设置,不使用semihosting
//C语言中
#pragma import(__use_no_semihosting_swi)
//汇编语言中
IMPORT __use_no_semihosting_swi
参考:
边栏推荐
- EPS32+Platform+Arduino 跑马灯
- AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘
- SimpleFOC调参2-速度、位置控制
- CS4344国产替代DP4344 192K 双通道 24 位 DA 转换器
- 一、PyTorch Cookbook(常用代码合集)
- STM32FF030 替代国产单片机——DP32G030
- STM32:麦克纳姆轮进行循迹任务(库函数程序代码)
- 4、 Application of one hot and loss function
- 5、 Image pixel statistics
- Transformer review + understanding
猜你喜欢
Migration learning notes - adaptive component analysis
ML15-神经网络(1)
Improve quality with intelligence financial imaging platform solution
1、 Usage of common loss function
ABSA1: Attentional Encoder Network for Targeted Sentiment Classification
CNOOC, desktop cloud & network disk storage system application case
入门到入魂:单片机如何利用TB6600高精度控制步进电机(42/57)
HAL库学习笔记- 8 串口通信之概念
倾角传感器用于通信铁塔、高压电塔长期监测
Power Bi report server custom authentication
随机推荐
三、如何读取视频?
Hal library learning notes-14 ADC and DAC
2.4G频段的无线收发芯片 SI24R1 问题汇总解答
基于FPGA:运动目标检测(补充仿真结果,可用毕设)
Hal library learning notes-10 overview of Hal library peripheral driver framework
iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
Migration learning robot visual domain adaptation with low rank reconstruction
Hal library learning notes - 8 use of serial communication
Migration learning - geodesic flow kernel for unsupervised domain adaptation
充电桩应用方案
HAL库学习笔记-11 I2C
Hal library learning notes - 9 DMA
Migration learning notes - adaptive component analysis
LoRa开启物联网新时代-ASR6500S、ASR6501/6502、ASR6505、ASR6601
2022春招——芯动科技FPGA岗技术面(一面心得)
京微齐力:基于HMEP060的心率血氧模块开发(1:FPGA发送多位指令)
Dust and noise monitoring system
SimpleFOC调参2-速度、位置控制
Chongqing Avenue cloud bank, as a representative of the software industry, was invited to participate in the signing ceremony of key projects in Yuzhong District
Transfer feature learning with joint distribution adaptation