From adb5eef77e646b7d063bdacccf883bb9ce6b2ade Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 6 Jul 2016 15:10:14 -0400 Subject: Add uart_set_default() to make debugging output easier. --- projects/hsm/hsm.c | 3 ++- stm-uart.c | 15 ++++++++++----- stm-uart.h | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c index 9cc6e9a..f4683b3 100644 --- a/projects/hsm/hsm.c +++ b/projects/hsm/hsm.c @@ -129,7 +129,7 @@ void HAL_UART2_RxCpltCallback(UART_HandleTypeDef *huart) hal_error_t hal_serial_send_char(uint8_t c) { - return (uart_send_char(c) == 0) ? HAL_OK : HAL_ERROR_RPC_TRANSPORT; + return (uart_send_char2(STM_UART_USER, c) == 0) ? HAL_OK : HAL_ERROR_RPC_TRANSPORT; } hal_error_t hal_serial_recv_char(uint8_t *cp) @@ -203,6 +203,7 @@ static uint8_t *sdram_malloc(size_t size) int main() { stm_init(); + uart_set_default(STM_UART_MGMT); led_on(LED_GREEN); /* Prepare FMC interface. */ diff --git a/stm-uart.c b/stm-uart.c index 7911d44..05190fb 100644 --- a/stm-uart.c +++ b/stm-uart.c @@ -43,8 +43,13 @@ UART_HandleTypeDef huart_user; /* USART2 */ DMA_HandleTypeDef hdma_usart_mgmt_rx; DMA_HandleTypeDef hdma_usart_user_rx; -#define DEFAULT_UART STM_UART_USER +static stm_uart_port_t default_uart = STM_UART_USER; +void uart_set_default(stm_uart_port_t port) +{ + if (port == STM_UART_USER || port == STM_UART_MGMT) + default_uart = port; +} inline UART_HandleTypeDef *_which_uart(stm_uart_port_t port) { @@ -60,7 +65,7 @@ inline UART_HandleTypeDef *_which_uart(stm_uart_port_t port) /* send a single character */ HAL_StatusTypeDef uart_send_char(uint8_t ch) { - return uart_send_char2(DEFAULT_UART, ch); + return uart_send_char2(default_uart, ch); } HAL_StatusTypeDef uart_send_char2(stm_uart_port_t port, uint8_t ch) @@ -71,7 +76,7 @@ HAL_StatusTypeDef uart_send_char2(stm_uart_port_t port, uint8_t ch) /* receive a single character */ HAL_StatusTypeDef uart_recv_char(uint8_t *cp) { - return uart_recv_char2(DEFAULT_UART, cp, HAL_MAX_DELAY); + return uart_recv_char2(default_uart, cp, HAL_MAX_DELAY); } /* receive a single character */ @@ -88,7 +93,7 @@ HAL_StatusTypeDef uart_recv_char2(stm_uart_port_t port, uint8_t *cp, uint32_t ti /* send a string */ HAL_StatusTypeDef uart_send_string(char *s) { - return uart_send_string2(DEFAULT_UART, s); + return uart_send_string2(default_uart, s); } /* send a string */ @@ -129,7 +134,7 @@ HAL_StatusTypeDef uart_receive_bytes(stm_uart_port_t port, uint8_t *buf, size_t */ HAL_StatusTypeDef uart_send_number(uint32_t num, uint8_t digits, uint8_t radix) { - return uart_send_number2(DEFAULT_UART, num, digits, radix); + return uart_send_number2(default_uart, num, digits, radix); } HAL_StatusTypeDef uart_send_number2(stm_uart_port_t port, uint32_t num, uint8_t digits, uint8_t radix) diff --git a/stm-uart.h b/stm-uart.h index 6133093..3efd799 100644 --- a/stm-uart.h +++ b/stm-uart.h @@ -51,6 +51,8 @@ extern UART_HandleTypeDef huart_user; extern DMA_HandleTypeDef hdma_usart_mgmt_rx; extern DMA_HandleTypeDef hdma_usart_user_rx; +extern void uart_set_default(stm_uart_port_t port); + extern HAL_StatusTypeDef uart_send_char(uint8_t ch); extern HAL_StatusTypeDef uart_recv_char(uint8_t *cp); -- cgit v1.2.3