]> mj.ucw.cz Git - home-hw.git/blobdiff - ssr/Src/debug.c
SSR: Debugging over USART
[home-hw.git] / ssr / Src / debug.c
index d8b3d63796c02b887d1a57c0bcd0811d82f4add9..7fae1e833f60c70bef614006f61e0a536b1e9359 100644 (file)
@@ -4,9 +4,10 @@
 #include <stdarg.h>
 #include <string.h>
 
+#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)