问题
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