aboutsummaryrefslogtreecommitdiff
path: root/projects/board-test/uart-test.c
blob: be06863d517bacaa3fb0e74f5003e68532e0bd87 (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
/*
 * 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()
{
    char crlf[] = "\r\n";
    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_string2(STM_UART_USER, crlf);
	    uart_send_string2(STM_UART_MGMT, crlf);
	    tx = 'A';
	    led_toggle(LED_BLUE);
	}
    }
}
="w"> = "NONE"; parameter DUTY_CYCLE_CORRECTION = "TRUE"; parameter FACTORY_JF = 16'hC080; parameter integer PHASE_SHIFT = 0; parameter STARTUP_WAIT = "FALSE"; output CLK0, CLK180, CLK270, CLK2X, CLK2X180, CLK90; output CLKDV, CLKFX, CLKFX180, LOCKED, PSDONE; output [7:0] STATUS; input CLKFB, CLKIN, DSSEN; input PSCLK, PSEN, PSINCDEC, RST; endmodule module BUFG (O, I); output O; input I; endmodule module IBUFGDS (O, I, IB); output O; input I, IB; endmodule module IOBUF (O, IO, I, T); parameter CAPACITANCE = "DONT_CARE"; parameter integer DRIVE = 12; parameter IBUF_DELAY_VALUE = "0"; parameter IBUF_LOW_PWR = "TRUE"; parameter IFD_DELAY_VALUE = "AUTO"; parameter IOSTANDARD = "DEFAULT"; parameter SLEW = "SLOW"; output O; inout IO; input I, T; endmodule module FDCE (Q, C, CE, CLR, D); parameter INIT = 1'b0; output Q; input C, CE, CLR, D; endmodule module FD (Q, C, D); parameter INIT = 1'b0; output Q; input C, D; endmodule module DSP48A1 (BCOUT, CARRYOUT, CARRYOUTF, M, P, PCOUT, A, B, C, CARRYIN, CEA, CEB, CEC, CECARRYIN, CED, CEM, CEOPMODE, CEP, CLK, D, OPMODE, PCIN, RSTA, RSTB, RSTC, RSTCARRYIN, RSTD, RSTM, RSTOPMODE, RSTP); parameter integer A0REG = 0; parameter integer A1REG = 1; parameter integer B0REG = 0; parameter integer B1REG = 1; parameter integer CARRYINREG = 1; parameter integer CARRYOUTREG = 1; parameter CARRYINSEL = "OPMODE5"; parameter integer CREG = 1; parameter integer DREG = 1; parameter integer MREG = 1; parameter integer OPMODEREG = 1; parameter integer PREG = 1; parameter RSTTYPE = "SYNC"; output [17:0] BCOUT; output CARRYOUT; output CARRYOUTF; output [35:0] M; output [47:0] P; output [47:0] PCOUT; input [17:0] A; input [17:0] B; input [47:0] C; input CARRYIN; input CEA; input CEB; input CEC; input CECARRYIN; input CED; input CEM; input CEOPMODE; input CEP; input CLK; input [17:0] D; input [7:0] OPMODE; input [47:0] PCIN; input RSTA; input RSTB; input RSTC; input RSTCARRYIN; input RSTD; input RSTM; input RSTOPMODE; input RSTP; endmodule module GND(G); output G; endmodule module VCC(P); output P; endmodule