You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
toaster-oven-bluepill/Core/Src/uart_stdout.c

52 lines
1.1 KiB

/**
* TODO file description
*/
#include <string.h>
#include "uart_stdout.h"
#include "FreeRTOS.h"
#include "main.h"
#define USE_CRITICAL 0
void stdout_putchar(char c) {
#if USE_CRITICAL
portENTER_CRITICAL();
#endif
while (!LL_USART_IsActiveFlag_TXE(USART_DEBUG)) {}
LL_USART_TransmitData8(USART_DEBUG, c);
while (!LL_USART_IsActiveFlag_TC(USART_DEBUG)) {}
#if USE_CRITICAL
portEXIT_CRITICAL();
#endif
}
void stdout_write(const char *pcBuffer, const size_t iLength) {
#if USE_CRITICAL
portENTER_CRITICAL();
#endif
while (!LL_USART_IsActiveFlag_TXE(USART_DEBUG)) {}
int cnt = (int) iLength;
while (cnt-- > 0) {
char c = *pcBuffer++;
LL_USART_TransmitData8(USART_DEBUG, c);
while (!LL_USART_IsActiveFlag_TC(USART_DEBUG)) {}
}
#if USE_CRITICAL
portEXIT_CRITICAL();
#endif
}
void stdout_puts(const char *pcBuffer) {
stdout_write(pcBuffer, strlen(pcBuffer));
}
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
int _write(int fd, const char *pcBuffer, const int iLength) {
stdout_write(pcBuffer, iLength);
return iLength;
}