How can i use printf in keil for my stm32f429i disc1 discovery board. I followed the steps on this link www.keil.com/.../ulink2_trace_itm_viewer.htm. i am still not able to print. Do i have to add any code. If yes where? My retarget_io.c file which gets created when i select the stdio and stdin itm is locked. Its unmodifiable. Is there a need to modify that? Blocked at this since 2 days. So need help soon. Do i have to add this to my main file?
#include <stdio.h> #include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
// Para utilização do saida de debug através do ULINK2 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n))) #define DEMCR (*((volatile unsigned long *)(0xE000EDFC))) #define TRCENA 0x01000000
struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout;
// Escreve caractere na porta de Debug int sendchar (int ch) { if (DEMCR & TRCENA) { while (ITM_Port32(0) == 0); ITM_Port8(0) = ch; } return(ch); }
int fputc(int ch, FILE *f) { return (ITM_SendChar((uint32_t)ch)); }
int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; }
void _ttywrch(int ch) { sendchar(ch); }
void _sys_exit(int return_code) { label: goto label; /* endless loop */ }
Use ITM_SendChar()
You need to ensure you're using the right CPU core speed in the Trace configuration, and that any Solder Bridges (SB) on the board that connect the SWO pin to the ST-LINK are in fact made.
Make sure SB9 is made on the STM32F429I-DISCO
>> Blocked at this since 2 days. So need help soon. A more powerful lesson to learn to actually read manuals
www.st.com/.../dm00093903.pdf
community.st.com/.../140878-re-how-to-properly-setup-printf-with-keil-µvision-and-stm32l151c8t6a
I have used itm_sendchar () in fputc function. Where should I exactly use it?
printf("Use the cited code, and this will print via SWV into the Serial (Debug) Window\n");
Illustration of how output should look community.st.com/.../107897 community.st.com/.../114079