aboutsummaryrefslogtreecommitdiff
path: root/src/uart-test/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uart-test/main.c')
-rw-r--r--src/uart-test/main.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/uart-test/main.c b/src/uart-test/main.c
index 77c17f4..55ec6fb 100644
--- a/src/uart-test/main.c
+++ b/src/uart-test/main.c
@@ -9,24 +9,45 @@
#define DELAY() HAL_Delay(250)
+UART_HandleTypeDef *huart;
+
+/*
+ * If a newline is received on UART1 or UART2, redirect output to that UART.
+ */
+void check_uart_rx(UART_HandleTypeDef *this) {
+ uint8_t rx = 0;
+ if (HAL_UART_Receive(this, &rx, 1, 0) == HAL_OK) {
+ if (rx == '\n') {
+ HAL_GPIO_TogglePin(LED_PORT, LED_GREEN);
+
+ huart = this;
+ }
+ }
+}
+
int
main()
{
uint8_t c = 'a';
- uint32_t i = 0;
stm_init();
+ huart = &huart1;
+
while (1)
{
HAL_GPIO_TogglePin(LED_PORT, LED_YELLOW);
- HAL_UART_Transmit(&huart1, (uint8_t *) &c, 1, 0xff);
+ HAL_UART_Transmit(huart, (uint8_t *) &c, 1, 0xff);
DELAY();
if (c++ == 'z') {
c = 'a';
HAL_GPIO_TogglePin(LED_PORT, LED_BLUE);
}
+
+ /* Check for UART change request */
+ check_uart_rx(&huart1);
+ check_uart_rx(&huart2);
}
}