STM32日志消息
美好的一天,我想使用STM32 Nucleo Board编写内容丰富的日志消息。 例如,我想显示程序在此期间启动时使用日志(“程序启动”)函数启动的消息,或者我想通过使用日志将错误消息传递给屏幕上(“”程序失败')函数当程序失败时。 我使用C编程langue和STM32Cubeide& Nucleo F207zg董事会提前感谢您的帮助,
感谢我解决了问题
good day, stm32 nucleo board I want to write informative Log messages using.
For example, I want to display the message that the program has started by using the Log("Program started") function when the program starts during this period, or I want to give the error message to the screen by using the Log("Program Failed') function when the program fails.
I using C programming langue and stm32cubeide & Nucleo f207zg board thanks in advance for your help
Thanks I solved the problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
鉴于:
您可以使用
printf <
printf < /代码>就像您在C中所做的那样。为什么?因为printf已经为您照顾了字符串的格式,没有人愿意重新进来,然后将printf输出重定向到处理低级序列协议的UART外围。
以下本指南这些步骤这些步骤非常容易:
。
Given that:
You can implement the logging with
printf
as you would do in C. Why? Because printf already takes care for you the formatting of the strings, which no one wants to reimplement, and then you redirect the printf output to the UART peripheral that handles low level serial protocol.Following this guide the steps are easy enough:
Note that you need to replace the question mark with the actual UART handle declaration, for instance
huart1
正如FRA93指出的那样,您需要实现UART/USART协议通信并将其打印到那里。我正在写这个答复,因为我感觉到您有一些基本的经验编写桌面应用程序,但没有嵌入,因此我会澄清几点。
无需打印控制台。没有日志。他们根本不存在。。不在桌面应用程序开发意义上。
通常这样做的是,MCU的UART之一用于将字符打印到ST-Link上,该字符将其转换为USB(或者可以是FTDI IC,CP2102或其他USB-UART BRIDGES/CONVENTERS)。因此,您的MCU将通过UART发送字符,
如果您从空项目开始并且没有使用的外部库,则USB-UART转换器将在COM端口终端显示它们(像Putty这样的程序),您将需要3打代码。一个人只是为了打印东西。最初,您什么都没有。您必须初始化UART,配置它,然后实现其处理字符,数字的方式。您需要从字面上写一个基本的UART驱动程序。您可以随心所欲地调用打印功能。您可以称其为log(“ Hello World”),您可以称其为窃窃私语(“嗨,那里”)。因为您实际上会创建此功能。你是老板。
现在,鉴于您对所有这些都不熟悉,这听起来可能是一项艰巨的任务。最肯定的是。从头开始写司机不是您想做的事情(除非您在第1天喜欢这种事情)。
我强烈建议您获取一些图书馆,例如由stmicroelectronics通过HAL,并熟悉它可以做的事情 - 包括如何与UART打印东西。互联网上充斥着有关如何与HAL一起使用UART的文章和视频,这实际上是要实施的第一件事。特别是出于原因,它像日志一样工作并简化了进一步的开发/学习。
因此,为了使“日志”有效,我会做以下操作:
最后,您的打印功能将是FRA93提出的功能。 HAL_UART_TRANSMIT是通过UART发送内容的最基本的HAL功能。如果您对使用“日志”作为您调用的函数非常挑剔,以通过UART打印,则可以始终将HAL_UART_TRANSMIT包装到自己的函数中,称为日志。
As pointed out by Fra93, you need to implement UART/USART protocol communication and print stuff to there. I'm writing this reply, because I'm getting a feeling you have some basic experience writing desktop applications, but not embedded, so I will clarify a few points.
There is no console to print to. There are no logs. They simply don't exist. At all. Not in a desktop app development sense.
What's usually done is that one of the UARTs of the MCU is used to print characters to the ST-Link, which converts it to USB (alternatively, can be FTDI IC, CP2102 or other USB-UART bridges/converters). So then your MCU will send out characters over UART, and the USB-UART converter will display them in a COM port terminal (programs like PuTTy)
If you start with empty project and no external libraries used, you will need 3 dozen lines of code alone just to be able to print stuff. Initially, you have nothing. You have to initialize UART, configure it, then implement how it handles characters, numbers. You need to literally write a basic UART driver. And you can call printing function whatever you want. You can call it Log("hello world"), you can call it Whisper("hi there"). Because you will actually create this function. You're the boss.
Now, given you are not very familiar with all of this, it may sound like a difficult task. And it most certainly is. Writing a driver from scratch on your day 1 is not a thing you want to do (unless you're into that kind of stuff on day 1).
I would strongly advise you to get some library, such as HAL by STMicroelectronics, and familiarize yourself with what it can do - including how to print stuff with UART. Internet is flooded with articles and videos of how to use UART with HAL, it's literally one of the first things to be implemented. Specifically for the reason, that it works like logs and simplifies further development/learning.
So, in order to get "logs" working, I would do the following:
In the end, your print function will be the one proposed by Fra93. HAL_UART_Transmit is the most basic HAL function to send stuff via UART. If you're very picky about using "Log" as a function you call to print via UART, you can always wrap HAL_UART_Transmit into your own function called Log.