// debug.c
-#define DEBUG_SEMIHOSTING
+#undef DEBUG_SEMIHOSTING
+#define DEBUG_USART USART1
void debug_printf(const char *fmt, ...);
void debug_puts(const char *s);
#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 (
: [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"
: [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;
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)
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);