X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Futil-debug.c;h=d0914a669b4c1c050a9eac3f3d1e8ded79c075f6;hb=bb37203461a4380e32be26594a74b77727dda97d;hp=e47ff46c9bd04c6f119216381e0a903ebcce9a1d;hpb=59f04eaa0a96f06ca4b94474c8a3a6ee677541fa;p=home-hw.git diff --git a/lib/util-debug.c b/lib/util-debug.c index e47ff46..d0914a6 100644 --- a/lib/util-debug.c +++ b/lib/util-debug.c @@ -1,5 +1,12 @@ +/* + * Debugging Utilities for STM32 + * + * (c) 2018--2019 Martin Mareš + */ + #include "util.h" +#include #include #include @@ -15,6 +22,13 @@ // Use this USART for debugging messages // #define DEBUG_USART USART1 +// Use this LED for debugging +#ifdef DEBUG_LED_BLUEPILL +#define DEBUG_LED_GPIO GPIOC +#define DEBUG_LED_PIN GPIO13 +#define DEBUG_LED_INVERSE +#endif + /*** Implementation ***/ #ifdef DEBUG_SEMIHOSTING @@ -61,8 +75,16 @@ void debug_putc(int c) #endif #ifdef DEBUG_USART if (c == '\n') - usart_send_blocking(USART2, '\r'); - usart_send_blocking(USART2, c); + usart_send_blocking(DEBUG_USART, '\r'); + usart_send_blocking(DEBUG_USART, c); +#endif +} + +void debug_flush(void) +{ +#ifdef DEBUG_USART + while (!usart_get_flag(DEBUG_USART, USART_FLAG_TC)) + ; #endif } @@ -153,6 +175,9 @@ void debug_printf(const char *fmt, ...) c = *fmt++; switch (c) { + case 'c': + debug_putc(va_arg(args, int)); + break; case 'd': printf_number(va_arg(args, int), width, flags | PF_SIGNED, 10); break; @@ -176,3 +201,23 @@ void debug_printf(const char *fmt, ...) va_end(args); } + +void debug_led(bool light) +{ +#ifdef DEBUG_LED_GPIO +#ifdef DEBUG_LED_INVERSE + light = !light; +#endif + if (light) + gpio_set(DEBUG_LED_GPIO, DEBUG_LED_PIN); + else + gpio_clear(DEBUG_LED_GPIO, DEBUG_LED_PIN); +#endif +} + +void debug_led_toggle(void) +{ +#ifdef DEBUG_LED_GPIO + gpio_toggle(DEBUG_LED_GPIO, DEBUG_LED_PIN); +#endif +}