]> mj.ucw.cz Git - home-hw.git/commitdiff
SSR: Debugging over USART
authorMartin Mares <mj@ucw.cz>
Tue, 7 Aug 2018 20:47:06 +0000 (22:47 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 7 Aug 2018 20:47:06 +0000 (22:47 +0200)
ssr/Inc/util.h
ssr/Src/debug.c
ssr/Src/main.c

index 0beed7c87232f5748061bc26b52585eb2524b8ea..405098c869505bb5ae6780c5c1c1da12edba0ad2 100644 (file)
@@ -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);
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)
index 3a3f0341944cb5ab0e841951b74bae71c0ea5633..cc6e3636777405c8354cda4ae8cee2e8922e0f86 100644 (file)
@@ -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);