打印
[STM32F4]

STM32F4 Discovery and printf() redirection to debug viewer in Keil MDK-ARM

[复制链接]
963|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 huangcunxiake 于 2016-8-27 10:02 编辑

使用Keil开发STM32F4 Discovery板的时候,使用printf函数,并且,输出信息重定向到debuger中的debug viewer中,从而,增加调试手段。



Objective
The ARM Cortex-M architecture includes a facility for sending/receiving user data through special debug ports. This facility is well suited for typical printf() debug practices, where a typical serial port is utiliced. In theses cases, the idea is to write in my program something like this,
[size=1em]
[color=white !important][size=1em]?




#include

voidmain (void) {

printf("Hello, world!");

}






and use the “Debug (printf) viewer” option avaible in Keil MDK-ARM  (and other environments) to show a terminal where messages are received. See bellow
These are my notes in order to get this mechanism working on the STM32F4 Discovery kit using the Keil environment.
Some vocabulary.
ITM:
SWV: Serial Wire Viewer

St-Link/V2 upgrade and drivers
The STM32F4 Discovery includes a built-in St-link/v2 debug interface. According with its manual, the SWV facility is available in this interface and the hardware lines are propagated in the schematic of the Discovery kit.
Steps:
1 – Download drivers and utilities from the support page for St-Link/v2 for Windows Xp and 7
2 – Install drivers (?Uninstall previous driver from the control panel)
3- Upgrade St-Link/v2 interface of the discovery running the ST-LinkUpgrade.exe utility
Configuring a Keil project
(But not working completly OK)
Assuming you have a working example for the previous debugger version. (Try to) follow these steps:
1 – Open your project and open the “target options” dialog
2 – Select the second “St-link debugger”

3 – Select “settings” and set options according to the next images.

(Here, be carefull with the speed of the core).
(This a trick for flashing the microcontroller)

沙发
huangcunxiake|  楼主 | 2016-8-27 09:09 | 只看该作者
Redirecting/retargeting printf() in my program
Create a C module that includes the following code and add it to your project
/**

   @file
fputc_debug.c

   @brief
Trying to redirect printf() to debug port

   @date
2012/06/25

*/



#include


#include




intfputc(intc,
FILE*stream)

{

   return(ITM_SendChar(c));

}


And start playing!
To be solved!!!!
The problem now is that the code is not flashed when entering in debug mode. I follow these steps:
1 – Rebuild completly the project (to avoid that the systems assumes that the build has been done)
2 – Flash the microcontroller with the “load” button
3 – Start debugging






使用特权

评论回复
板凳
gaoxiansheng| | 2016-8-27 09:48 | 只看该作者
st-link也可以半主机输出吗?我也试试这个效果如何

使用特权

评论回复
地板
huangcunxiake|  楼主 | 2016-8-27 10:02 | 只看该作者
半主机输出是啥意思。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

205

主题

3485

帖子

10

粉丝