aboutsummaryrefslogtreecommitdiff
path: root/projects/board-test/uart-test.c
blob: 6f022f42b0cc7b2589720351735d499a91af1d79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Test code that just sends the letters 'a' to 'z' over and
 * 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 GREEN LED for every
 * character sent.
 */
#include "stm32f4xx_hal.h"
#include "stm-init.h"
#include "stm-led.h"
#include "stm-uart.h"

#define DELAY() HAL_Delay(100)

int
main()
{
  uint8_t tx = 'A';
  uint8_t rx = 0;
  uint8_t upper = 0;

  stm_init();

  while (1)
  {
    led_toggle(LED_GREEN);

    uart_send_char2(STM_UART_USER, tx + upper);
    uart_send_char2(STM_UART_MGMT, tx + upper);
    DELAY();

    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);
    }
  }
}