aboutsummaryrefslogtreecommitdiff
path: root/stm-uart.c
diff options
context:
space:
mode:
authorFredrik Thulin <fredrik@thulin.net>2016-05-12 19:46:38 +0200
committerFredrik Thulin <fredrik@thulin.net>2016-05-12 19:48:03 +0200
commit8a492acf7b856f0ab13a531a77ba9e64097ba007 (patch)
tree9a58f94ddbd7d1d3a4ca932ded358305622d7811 /stm-uart.c
parent15d8d22092b0b92cea71a243e31df142e299e322 (diff)
Test both UARTs, and also test receiving data.
Diffstat (limited to 'stm-uart.c')
-rw-r--r--stm-uart.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/stm-uart.c b/stm-uart.c
index 0ecbedc..ed872cf 100644
--- a/stm-uart.c
+++ b/stm-uart.c
@@ -37,6 +37,7 @@
#include <string.h>
+UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
/* send a single character */
@@ -45,12 +46,33 @@ HAL_StatusTypeDef uart_send_char(uint8_t ch)
return HAL_UART_Transmit(&huart2, &ch, 1, 0x1);
}
+HAL_StatusTypeDef uart_send_char2(enum stm_uart_port port, uint8_t ch)
+{
+ if (port == STM_UART_USER) {
+ return HAL_UART_Transmit(&huart2, &ch, 1, 0x1);
+ } else if (port == STM_UART_MGMT) {
+ return HAL_UART_Transmit(&huart1, &ch, 1, 0x1);
+ }
+ return HAL_ERROR;
+}
+
/* receive a single character */
HAL_StatusTypeDef uart_recv_char(uint8_t *cp)
{
return HAL_UART_Receive(&huart2, cp, 1, HAL_MAX_DELAY);
}
+/* receive a single character */
+HAL_StatusTypeDef uart_recv_char2(enum stm_uart_port port, uint8_t *cp, uint32_t timeout)
+{
+ if (port == STM_UART_USER) {
+ return HAL_UART_Receive(&huart2, cp, 1, timeout);
+ } else if (port == STM_UART_MGMT) {
+ return HAL_UART_Receive(&huart1, cp, 1, timeout);
+ }
+ return HAL_ERROR;
+}
+
/* send a string */
HAL_StatusTypeDef uart_send_string(char *s)
{