Skip to content
Snippets Groups Projects
Commit 4d10bbd0 authored by Eric Brombaugh's avatar Eric Brombaugh
Browse files

cnlohr's separate putchar() for UART and Debug for speed.

parent a37c90dc
No related branches found
No related tags found
No related merge requests found
...@@ -31,11 +31,6 @@ int printf(const char* format, ...) ...@@ -31,11 +31,6 @@ int printf(const char* format, ...)
va_end( args ); va_end( args );
return ret_status; return ret_status;
} }
int putchar(int c)
{
return _write( 0, (const char *)(&c), 1 );
}
/* Some stuff from MUSL /* Some stuff from MUSL
...@@ -883,13 +878,21 @@ int _write(int fd, const char *buf, int size) ...@@ -883,13 +878,21 @@ int _write(int fd, const char *buf, int size)
} }
return size; return size;
} }
// single char to UART
int putchar(int c)
{
while( !(USART1->STATR & USART_FLAG_TC));
USART1->DATAR = (const char)c;
return 1;
}
#else #else
// For debug writing to the debug interface. // For debug writing to the debug interface.
#define DMDATA0 ((volatile uint32_t*)0xe00000f4)
#define DMDATA1 ((volatile uint32_t*)0xe00000f8)
int _write(int fd, const char *buf, int size) int _write(int fd, const char *buf, int size)
{ {
#define DMDATA0 ((volatile uint32_t*)0xe00000f4)
#define DMDATA1 ((volatile uint32_t*)0xe00000f8)
char buffer[4] = { 0 }; char buffer[4] = { 0 };
int place = 0; int place = 0;
uint32_t timeout = 160000; // Give up after ~40ms uint32_t timeout = 160000; // Give up after ~40ms
...@@ -924,6 +927,15 @@ int _write(int fd, const char *buf, int size) ...@@ -924,6 +927,15 @@ int _write(int fd, const char *buf, int size)
return size; return size;
} }
// single to debug intf
int putchar(int c)
{
int timeout = 16000;
while( ((*DMDATA0) & 0x80) ) if( timeout-- == 0 ) return 0;
*DMDATA0 = 0x85 | ((const char)c<<8);
return 1;
}
void SetupDebugPrintf() void SetupDebugPrintf()
{ {
// Clear out the sending flag. // Clear out the sending flag.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment