From 5aea63d91caa902f9213e0abf681b264188f9774 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 7 Aug 2018 22:47:06 +0200 Subject: [PATCH] SSR: Debugging over USART --- ssr/Inc/util.h | 3 ++- ssr/Src/debug.c | 17 +++++++++++++---- ssr/Src/main.c | 4 +++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ssr/Inc/util.h b/ssr/Inc/util.h index 0beed7c..405098c 100644 --- a/ssr/Inc/util.h +++ b/ssr/Inc/util.h @@ -38,7 +38,8 @@ static inline void put_u32_be(byte *p, u32 x) // debug.c -#define DEBUG_SEMIHOSTING +#undef DEBUG_SEMIHOSTING +#define DEBUG_USART USART1 void debug_printf(const char *fmt, ...); void debug_puts(const char *s); diff --git a/ssr/Src/debug.c b/ssr/Src/debug.c index d8b3d63..7fae1e8 100644 --- a/ssr/Src/debug.c +++ b/ssr/Src/debug.c @@ -4,9 +4,10 @@ #include #include +#ifdef DEBUG_SEMIHOSTING + void semi_put_char(char c) { -#ifdef DEBUG_SEMIHOSTING // This is tricky, we need to work around GCC bugs volatile char cc = c; asm volatile ( @@ -17,12 +18,10 @@ void semi_put_char(char c) : [msg] "r" (&cc) : "r0", "r1" ); -#endif } void semi_write_string(char *c) { -#ifdef DEBUG_SEMIHOSTING asm volatile ( "mov r0, #0x04\n" /* SYS_WRITE0 */ "mov r1, %[msg]\n" @@ -31,11 +30,13 @@ void semi_write_string(char *c) : [msg] "r" (c) : "r0", "r1" ); -#endif } +#endif + void debug_putc(int c) { +#ifdef DEBUG_SEMIHOSTING static char debug_buf[128]; static int debug_i; debug_buf[debug_i++] = c; @@ -45,6 +46,14 @@ void debug_putc(int c) semi_write_string(debug_buf); debug_i = 0; } +#endif +#ifdef DEBUG_USART + if (c == '\n') + debug_putc('\r'); + while (!LL_USART_IsActiveFlag_TXE(DEBUG_USART)) + ; + LL_USART_TransmitData8(DEBUG_USART, c); +#endif } void debug_puts(const char *s) diff --git a/ssr/Src/main.c b/ssr/Src/main.c index 3a3f034..cc6e363 100644 --- a/ssr/Src/main.c +++ b/ssr/Src/main.c @@ -174,7 +174,9 @@ int main(void) usb_ep_receive(&usb, 0x01, rx_packet, 64); } - // debug_printf("Counter = %d\n", cnt); + static int cnt; + debug_printf("Counter = %d\n", cnt); + cnt++; //__WFI(); LL_mDelay(1000); -- 2.39.2