This repository is an example for asynchronous serial. It is a test unit with test cases for asynchronous serial methods, using two serial peripheral modules (for instance TX from USART0 and RX from USART1).
To build and run this example the following requirements are necessary:
- A computer with the following software installed:
- CMake.
- yotta. Please note that yotta has its own set of dependencies, listed in the installation instructions.
- Python.
- ARM GCC toolchain.
- A serial terminal emulator (e.g. screen, pySerial, cu).
- An FRDM-K64F development board. Please look at the pinout picture to find the correct pins.
- A micro-USB cable.
- A wire to connect TX and RX pins.
- If your OS is Windows, please follow the installation instructions for the serial port driver.
TX and RX pin definitions are target-specific. To function correctly, the code and the physical board must both be using the same pins. Follow these steps to determine which pins the code is configured to use.
-
First, find the pin references in the source files. In this example, view
serial_asynch.cpp
. The pin references areYOTTA_CFG_HARDWARE_TEST_PINS_SERIAL_TX
andYOTTA_CFG_HARDWARE_TEST_PINS_SERIAL_RX
. -
Next, find these target-specific pin references in the configuration data by running the command:
yotta config
Each keyword in the pin reference represents a level in the target configuration structure. To find what YOTTA_CFG_HARDWARE_TEST_PINS_SERIAL resolves to, look under config...hardware...test-pins...serial.
In this example, the serial tx and rx pins are defined as:
"serial": {
"tx": "PTC17",
"rx": "PTD2"
}
-
Locate the pins (i.e. PTC17, PTD2) on the board's pinout picture:
-
Finally, create a loopback, connect the pins together by a wire.
-
Connect the FRDM-K64F to the computer with the micro-USB cable, being careful to use the micro-USB port labeled "OpenSDA".
-
Connect YOTTA_CFG_HARDWARE_TEST_PINS_SERIAL_TX to YOTTA_CFG_HARDWARE_TEST_PINS_SERIAL_RX. See the previous section for an explanation if you do not know how to locate these.
-
Assuming you have cloned this repository or receive it with a release tarball, open a terminal window and navigate to the repository's folder.
cd /path/to/example-asynch-serial
-
Select the yotta target and build to it:
yotta target frdm-k64f-gcc yotta build
-
Copy
build/frdm-k64f-gcc/source/example-asynch-serial.bin
to your mbed board and wait until the LED next to the USB port stops blinking. -
Start the serial terminal emulator and connect to the virtual serial port presented by FRDM-K64F. For settings, use 115200 baud, 8N1, no flow control.
-
Press the reset button on the board.
-
The output in the terminal should look like this:
Starting short transfer test Res is 0 Res is 0 Short transfer DONE, event is 256 Starting long transfer test Res is 0 Res is 0 Long transfer DONE, event is 256 **** Test done ****