diff options
author | Fredrik Thulin <fredrik@thulin.net> | 2016-05-12 19:46:38 +0200 |
---|---|---|
committer | Fredrik Thulin <fredrik@thulin.net> | 2016-05-12 19:48:03 +0200 |
commit | 8a492acf7b856f0ab13a531a77ba9e64097ba007 (patch) | |
tree | 9a58f94ddbd7d1d3a4ca932ded358305622d7811 /projects/board-test/uart-test.c | |
parent | 15d8d22092b0b92cea71a243e31df142e299e322 (diff) |
Test both UARTs, and also test receiving data.
Diffstat (limited to 'projects/board-test/uart-test.c')
-rw-r--r-- | projects/board-test/uart-test.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/projects/board-test/uart-test.c b/projects/board-test/uart-test.c index f32fde7..6f022f4 100644 --- a/projects/board-test/uart-test.c +++ b/projects/board-test/uart-test.c @@ -1,8 +1,9 @@ /* * Test code that just sends the letters 'a' to 'z' over and - * over again using USART2. + * over again to both the USER and MGMT UARTs. If a CR is received, + * it will toggle upper/lower case of the letters being sent. * - * Toggles the BLUE LED slowly and the RED LED for every + * Toggles the BLUE LED slowly and the GREEN LED for every * character sent. */ #include "stm32f4xx_hal.h" @@ -15,20 +16,36 @@ int main() { - uint8_t c = 'a'; + uint8_t tx = 'A'; + uint8_t rx = 0; + uint8_t upper = 0; stm_init(); while (1) { - HAL_GPIO_TogglePin(LED_PORT, LED_GREEN); + led_toggle(LED_GREEN); - uart_send_char(c); + uart_send_char2(STM_UART_USER, tx + upper); + uart_send_char2(STM_UART_MGMT, tx + upper); DELAY(); - if (c++ == 'z') { - c = 'a'; - HAL_GPIO_TogglePin(LED_PORT, LED_BLUE); + if (uart_recv_char2(STM_UART_USER, &rx, 0) == HAL_OK || + uart_recv_char2(STM_UART_MGMT, &rx, 0) == HAL_OK) { + led_toggle(LED_YELLOW); + if (rx == '\r') { + upper = upper == 0 ? ('a' - 'A'):0; + } + } + + if (tx++ == 'Z') { + /* linefeed after each alphabet */ + uart_send_char2(STM_UART_USER, '\r'); + uart_send_char2(STM_UART_USER, '\n'); + uart_send_char2(STM_UART_MGMT, '\r'); + uart_send_char2(STM_UART_MGMT, '\n'); + tx = 'A'; + led_toggle(LED_BLUE); } } } |