Printf in keil for stm32f4-eval2 board

笑着哭i 提交于 2019-12-12 02:46:38

问题


Is there c++ or c code anywhere that will help me use printf in keil uvision 5 for the stm32f4-eval2 board? I know you have to retarget the uarts and usarts but I have not been able to do this without errors even with help from the sites I have found online.

I would like to be able to use the debug printf viewer.

I tried the following link but it did not work: http://www.keil.com/support/man/docs/ulinkpro/ulinkpro_trace_itm_viewer.htm


回答1:


You are not very specific if you want to print via UART or if you want to print via ITM debug channel. For ITM it is pretty simple. Create a file with the following content and make sure SWO trace is enabled on your debug connection:

#include <stdio.h> 

/* Replace next line: Include the device system header file here */
#error "device include file missing"
/* e.g.: #include "STM32F4xx.h" */

#pragma import(__use_no_semihosting_swi)

volatile int ITM_RxBuffer = ITM_RXBUFFER_EMPTY;  /*  CMSIS Debug Input        */

int fputc(int c, FILE *f) {
  return (ITM_SendChar(c));
}

int fgetc(FILE *f) {
  while (ITM_CheckChar() != 1) __NOP();
  return (ITM_ReceiveChar());
}

Make sure you tick the "Use MicroLib" option in Options for Target->Target



来源:https://stackoverflow.com/questions/24605244/printf-in-keil-for-stm32f4-eval2-board

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!