Hello,
I work with the AT91RM9200.
I have some problems with the retarget-function for the implementation of printf. It works but sometimes I get a data abort - maybe if the buffer for printf function is too small???
that's my function to transmit printf messages to the usart
int COM1_1_sendchar(int ch) { if (ch == '\n') { /* Check for CR */ while (!(COM1_1->US_CSR & AT91C_US_TXRDY)); /* Wait for Empty Tx Buffer */ // COM1_1->US_THR = '\r'; /* Output CR */ AT91F_US_PutChar (COM1_1,'\r'); } while (!(COM1_1->US_CSR & AT91C_US_TXRDY)); /* Wait for Empty Tx Buffer */ return (COM1_1->US_THR = ch); /* Transmit Character */ }
retarget.c
#include <stdio.h> #include <rt_misc.h> #include <AT91RM9200.H> #pragma import(__use_no_semihosting_swi) extern int COM1_1_sendchar (int ch); /* in usart.c */ struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout; FILE __stdin; int fputc(int ch, FILE *f) { return (COM1_1_sendchar(ch)); } int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; } void _ttywrch(int ch) { COM1_1_sendchar(ch); } void _sys_exit(int return_code) { label: goto label; /* endless loop */ }
I hope somebody have a idea - because the problem with the data abort is not always but very often
best regards Johannes