2020-08-17 09:45:53 +00:00
|
|
|
#define _GNU_SOURCE
|
2020-08-07 06:58:20 +00:00
|
|
|
#include "main.h"
|
2020-08-17 09:45:53 +00:00
|
|
|
#include <stdio.h>
|
2020-08-07 06:58:20 +00:00
|
|
|
|
|
|
|
extern UART_HandleTypeDef DEBUG_UART;
|
|
|
|
|
2020-08-17 09:45:53 +00:00
|
|
|
ssize_t uart_write(void* cookie, const char * buffer, size_t size) {
|
2020-08-07 06:58:20 +00:00
|
|
|
if (buffer == 0) {
|
|
|
|
/*
|
|
|
|
* This means that we should flush internal buffers. Since we
|
|
|
|
* don't we just return. (Remember, "handle" == -1 means that all
|
|
|
|
* handles should be flushed.)
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-17 09:45:53 +00:00
|
|
|
return (ssize_t)HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)buffer, (uint16_t)size, HAL_MAX_DELAY);
|
2020-08-07 06:58:20 +00:00
|
|
|
}
|
2020-08-17 09:45:53 +00:00
|
|
|
|
|
|
|
FILE* get_debug() {
|
2020-08-24 15:31:22 +00:00
|
|
|
FILE* fp = fopencookie(NULL, "w+", (cookie_io_functions_t){
|
2020-08-17 09:45:53 +00:00
|
|
|
.read = NULL,
|
|
|
|
.write = uart_write,
|
|
|
|
.seek = NULL,
|
|
|
|
.close = NULL
|
|
|
|
});
|
|
|
|
|
|
|
|
setvbuf(fp, NULL, _IONBF, 0);
|
|
|
|
|
|
|
|
return fp;
|
|
|
|
}
|