-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
39 lines (31 loc) · 1.01 KB
/
main.cpp
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
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
// Maximum number of element the application buffer can contain
#define MAXIMUM_BUFFER_SIZE 32
// Create a DigitalOutput object to toggle an LED whenever data is received.
static DigitalOut led(LED1);
// Create a BufferedSerial object with a default baud rate.
static BufferedSerial serial_port(USBTX, USBRX);
int main(void)
{
// Set desired properties (9600-8-N-1).
serial_port.set_baud(9600);
serial_port.set_format(
/* bits */ 8,
/* parity */ BufferedSerial::None,
/* stop bit */ 1
);
// Application buffer to receive the data
char buf[MAXIMUM_BUFFER_SIZE] = {0};
while (1) {
if (uint32_t num = serial_port.read(buf, sizeof(buf))) {
// Toggle the LED.
led = !led;
// Echo the input back to the terminal.
serial_port.write(buf, num);
}
}
}