[fix] update uart_log console
This commit is contained in:
parent
adef945b30
commit
3de75b2326
@ -2,16 +2,11 @@
|
||||
#include "stdarg.h"
|
||||
#include "string.h"
|
||||
|
||||
UART_HandleTypeDef *console = NULL;
|
||||
extern UART_HandleTypeDef UartHandle;
|
||||
extern UART_HandleTypeDef console;
|
||||
|
||||
int putchar(int c)
|
||||
{
|
||||
if (console == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HAL_UART_Transmit(console, (uint8_t*)&c, 0, HAL_TIMEOUT_VALUE);
|
||||
HAL_UART_Transmit(&console, (uint8_t*)&c, 0, HAL_TIMEOUT_VALUE);
|
||||
|
||||
return c;
|
||||
}
|
||||
@ -22,11 +17,7 @@ int puts(const char *c)
|
||||
|
||||
len = strlen(c);
|
||||
|
||||
if (console == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HAL_UART_Transmit(console, (uint8_t*)c, len, HAL_TIMEOUT_VALUE);
|
||||
HAL_UART_Transmit(&console, (uint8_t*)c, len, HAL_TIMEOUT_VALUE);
|
||||
|
||||
return len;
|
||||
}
|
||||
@ -41,11 +32,7 @@ int putstring(const char *c)
|
||||
|
||||
len = strlen(c);
|
||||
|
||||
if (console == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HAL_UART_Transmit(console, (uint8_t*)c, len, HAL_TIMEOUT_VALUE);
|
||||
HAL_UART_Transmit(&console, (uint8_t*)c, len, HAL_TIMEOUT_VALUE);
|
||||
|
||||
return len;
|
||||
}
|
||||
@ -63,7 +50,7 @@ int printf(const char *fmt, ...)
|
||||
|
||||
len = (len > sizeof(print_buf)) ? sizeof(print_buf) : len;
|
||||
|
||||
HAL_UART_Transmit(console, (uint8_t*)print_buf, len, HAL_TIMEOUT_VALUE);
|
||||
HAL_UART_Transmit(&console, (uint8_t*)print_buf, len, HAL_TIMEOUT_VALUE);
|
||||
|
||||
return len;
|
||||
}
|
||||
@ -81,8 +68,3 @@ int printf(const char *fmt, ...)
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_log_set_console(void)
|
||||
{
|
||||
console = &UartHandle;
|
||||
}
|
||||
|
||||
@ -219,11 +219,11 @@ static inline void out_buffer(char character, void* buffer, size_t idx, size_t m
|
||||
}
|
||||
}
|
||||
|
||||
extern UART_HandleTypeDef *console;
|
||||
extern UART_HandleTypeDef console;
|
||||
static inline void out_console(char character, void* buffer, size_t idx, size_t maxlen)
|
||||
{
|
||||
while (!(__HAL_UART_GET_FLAG(console, UART_FLAG_TXFNF)));
|
||||
console->Instance->TDR = (uint8_t)character;
|
||||
while (!(__HAL_UART_GET_FLAG(&console, UART_FLAG_TXFNF)));
|
||||
console.Instance->TDR = (uint8_t)character;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
#include "uart_log.h"
|
||||
|
||||
UART_HandleTypeDef UartHandle;
|
||||
|
||||
extern void uart_log_set_console(void);
|
||||
UART_HandleTypeDef console;
|
||||
|
||||
static void UART_LOG_Msp_Init(void)
|
||||
{
|
||||
@ -46,28 +44,26 @@ static void UART_LOG_Msp_Init(void)
|
||||
|
||||
void uart_log_init(void)
|
||||
{
|
||||
UartHandle.Instance = USART_LOG;
|
||||
UartHandle.Init.BaudRate = UART_LOG_BAUDRATE;
|
||||
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
UartHandle.Init.StopBits = UART_STOPBITS_1;
|
||||
UartHandle.Init.Parity = UART_PARITY_NONE;
|
||||
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
UartHandle.Init.Mode = UART_MODE_TX_RX;
|
||||
UartHandle.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
||||
UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
console.Instance = USART_LOG;
|
||||
console.Init.BaudRate = UART_LOG_BAUDRATE;
|
||||
console.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
console.Init.StopBits = UART_STOPBITS_1;
|
||||
console.Init.Parity = UART_PARITY_NONE;
|
||||
console.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
console.Init.Mode = UART_MODE_TX_RX;
|
||||
console.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
||||
console.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||
console.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
|
||||
UART_LOG_Msp_Init();
|
||||
|
||||
if(HAL_UART_Init(&UartHandle) != HAL_OK)
|
||||
{
|
||||
if(HAL_UART_Init(&console) != HAL_OK) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
/* Set the RXFIFO threshold */
|
||||
HAL_UARTEx_SetRxFifoThreshold(&UartHandle, UART_RXFIFO_THRESHOLD_1_2);
|
||||
HAL_UARTEx_SetRxFifoThreshold(&console, UART_RXFIFO_THRESHOLD_1_2);
|
||||
|
||||
/* Enable the FIFO mode */
|
||||
HAL_UARTEx_EnableFifoMode(&UartHandle);
|
||||
uart_log_set_console();
|
||||
HAL_UARTEx_EnableFifoMode(&console);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user