2 #include "stm32f1xx_hal.h"
7 void semi_put_char(char c)
9 #ifdef DEBUG_SEMIHOSTING
10 // This is tricky, we need to work around GCC bugs
13 "mov r0, #0x03\n" /* SYS_WRITEC */
23 void semi_write_string(char *c)
25 #ifdef DEBUG_SEMIHOSTING
27 "mov r0, #0x04\n" /* SYS_WRITE0 */
37 void debug_putc(int c)
39 static char debug_buf[128];
41 debug_buf[debug_i++] = c;
42 if (c == '\n' || debug_i >= sizeof(debug_buf) - 1)
44 debug_buf[debug_i] = 0;
45 semi_write_string(debug_buf);
50 void debug_puts(const char *s)
64 static void printf_string(const char *s, uint width, uint flags)
67 uint pad = (len < width) ? width - len : 0;
68 char pad_char = (flags & PF_ZERO_PAD) ? '0' : ' ';
74 if (!(flags & PF_LEFT))
78 static void printf_number(uint i, uint width, uint flags, uint base)
81 char *w = buf + sizeof(buf);
83 if (flags & PF_SIGNED)
95 uint digit = i % base;
99 *--w = ((flags & PF_UPPERCASE) ? 'A' : 'a') + digit - 10;
104 if (flags & PF_NEGATIVE)
107 printf_string(w, width, flags);
110 void debug_printf(const char *fmt, ...)
136 flags |= PF_ZERO_PAD;
139 while (*fmt >= '0' && *fmt <= '9')
140 width = 10*width + *fmt++ - '0';
146 printf_number(va_arg(args, int), width, flags | PF_SIGNED, 10);
149 printf_number(va_arg(args, int), width, flags, 10);
152 flags |= PF_UPPERCASE;
155 printf_number(va_arg(args, int), width, flags, 16);
158 printf_string(va_arg(args, char *), width, flags);