Skip to content
Snippets Groups Projects
Unverified Commit 28f73c4d authored by CNLohr's avatar CNLohr Committed by GitHub
Browse files

Merge pull request #39 from emeb/master

cnlohr's separate putchar() for UART and Debug for speed.
parents a37c90dc 634770be
No related branches found
No related tags found
No related merge requests found
......@@ -31,11 +31,6 @@ int printf(const char* format, ...)
va_end( args );
return ret_status;
}
int putchar(int c)
{
return _write( 0, (const char *)(&c), 1 );
}
/* Some stuff from MUSL
......@@ -883,13 +878,21 @@ int _write(int fd, const char *buf, int 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
// 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)
{
#define DMDATA0 ((volatile uint32_t*)0xe00000f4)
#define DMDATA1 ((volatile uint32_t*)0xe00000f8)
char buffer[4] = { 0 };
int place = 0;
uint32_t timeout = 160000; // Give up after ~40ms
......@@ -924,6 +927,15 @@ int _write(int fd, const char *buf, int 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()
{
// 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