debug.c 771 B

12345678910111213141516171819202122232425262728293031
  1. #define _GNU_SOURCE
  2. #include "main.h"
  3. #include <stdio.h>
  4. extern UART_HandleTypeDef DEBUG_UART;
  5. ssize_t uart_write(void* cookie, const char * buffer, size_t size) {
  6. if (buffer == 0) {
  7. /*
  8. * This means that we should flush internal buffers. Since we
  9. * don't we just return. (Remember, "handle" == -1 means that all
  10. * handles should be flushed.)
  11. */
  12. return 0;
  13. }
  14. return (ssize_t)HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)buffer, (uint16_t)size, HAL_MAX_DELAY);
  15. }
  16. FILE* get_debug() {
  17. FILE* fp = fopencookie(NULL, "w+", (cookie_io_functions_t){
  18. .read = NULL,
  19. .write = uart_write,
  20. .seek = NULL,
  21. .close = NULL
  22. });
  23. setvbuf(fp, NULL, _IONBF, 0);
  24. return fp;
  25. }