Skip to content

Update serial communication and clean up duplicated & outdated info #1326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 27, 2020
Merged
24 changes: 5 additions & 19 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"sources": []
},
{
"title": "Build and debug with Mbed CLI",
"title": "Build with Mbed CLI",
"sub_chapters": [{
"title": "Installing Mbed CLI",
"intro": {
Expand All @@ -108,31 +108,17 @@
"path": "docs/quick-start/cli_code.md"
},
"sources": []
},
{
"title": "Debugging with Mbed CLI",
"intro": {
"path": "docs/quick-start/quick-start-cli-debug.md"
},
"sources": []
}
]
},
{
"title": "Build and debug with the Online Compiler",
"title": "Build with the Online Compiler",
"sub_chapters": [{
"title": "Importing and compiling the code",
"intro": {
"path": "docs/quick-start/quick-start-compiler.md"
},
"sources": []
},
{
"title": "Debugging with the Online Compiler",
"intro": {
"path": "docs/quick-start/quick-start-online-debug.md"
},
"sources": []
}
]
},
Expand Down Expand Up @@ -1115,9 +1101,6 @@
"type": "markdown",
"chapters": [{
"title": "Debugging",
"intro": {
"path": "docs/tools/debug/debug_intro.md"
},
"sub_chapters": [{
"title": "Methods",
"sources": [{
Expand Down Expand Up @@ -1151,6 +1134,9 @@
},
{
"title": "Third party tools",
"intro": {
"path": "docs/tools/debug/debug_intro.md"
},
"sources": [{
"path": "docs/tools/debug/eclipse_pyocd.md"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We release Mbed OS under an Apache 2.0 license, so you can confidently use it in

Our [quick start](../quick-start/index.html) guides show how to build an example application for both the full profile and bare metal profile, on Mbed CLI, Mbed Studio and the Mbed Online Compiler.

| [Build with Mbed Studio](https://os.mbed.com/docs/mbed-studio/current/getting-started/index.html) | [Build with Mbed Online Compiler](../quick-start/build-and-debug-with-the-online-compiler.html) | [Build with Mbed CLI](../quick-start/build-and-debug-with-mbed-cli.html) |
| [Build with Mbed Studio](https://os.mbed.com/docs/mbed-studio/current/getting-started/index.html) | [Build with Mbed Online Compiler](../quick-start/build-with-the-online-compiler.html) | [Build with Mbed CLI](../quick-start/build-with-mbed-cli.html) |
| --- | --- | --- |
| Download our dedicated desktop IDE, including all the necessary tools to work with Mbed OS. <br>This link will take you to the Mbed Studio documentation site. | Zero-installation web IDE to explore Mbed OS; great for rapid prototyping and education. | Command-line tool requiring manual setup of tools, but providing the greatest degree of flexibility. |

Expand Down
83 changes: 41 additions & 42 deletions docs/program-setup/serial/serial_communication.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,86 +6,85 @@ The Arm Mbed microcontroller on your board can communicate with a host PC over t

This allows you to:

- Print out messages to a [host PC terminal (useful for debugging)](#terminal-applications).
- Read input from the host PC keyboard.
- Communicate with applications and programming languages running on the host PC that can communicate with a serial port. Examples are Perl, Python and Java.
- Print out messages to a PC terminal (useful for debugging).
- Read input from a PC keyboard.
- Communicate with applications running on a PC to exchange data.

## Hello, world
## Hello World - printing messages

This program prints a "Hello World" message that you can view on a [terminal application](#using-terminal-applications). Communication over the USB serial port uses the standard serial interface. Specify the internal (USBTX, USBRX) pins to connect to the serial port routed over USB:
This program prints a "Hello World!" message that you can view on a serial terminal. Mbed OS redirects any `printf()` statements to the board's debug USB serial.

[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Serial_HelloWorld/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Serial_HelloWorld/blob/v6.0/main.cpp)
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Serial_STDOUT/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Serial_STDOUT/blob/v6.0/main.cpp)

## Viewing output in a serial terminal

## Using terminal applications
Serial terminals run on your host PC. They provide an interface where your Mbed board can print and where you can type characters back to your board.

Terminal applications run on your host PC. They provide a window where your Mbed board can print and where you can type characters back to your board.
Mbed CLI provides a serial terminal that is configured with a default baud rate of `9600`. You can either set it to [open after compilation](#opening-a-serial-terminal-after-compilation), or open it [manually](#manually-opening-a-serial-terminal).

<span class="tips">**Serial configuration:** The standard setup for the USB serial port is 9600 baud, 8 bits, 1 stop bit, no parity (9600-8-N-1)</span>
### Opening a serial terminal after compilation

### Installing an application for Windows
You can use one command to compile an application, flash it onto a board and open a serial terminal:

There are many terminal applications for Windows, including:
```
mbed compile -t <TOOLCHAIN> -m <TARGET> --flash --sterm
```

- [CoolTerm](http://freeware.the-meiers.org/) - this is the application we use in this example. We use it often because it usually "just works".
- [Tera Term](http://sourceforge.jp/projects/ttssh2/files).
- [PuTTY](http://www.chiark.greenend.org.uk/~sgtatham/putty/).
- Some Windows PCs come with **Hyperterminal** installed.
When the board is flashed, it starts printing to the terminal (`Hello World!`, in this example).

### Configuring the connection
To close the serial terminal, enter <kbd>Ctrl + C</kbd>.

1. Plug in your Mbed board.
1. Open CoolTerm.
1. Click **Connect**. This opens up an 8-n-1 9600 baud connection to the first available serial port. If you have more than one board plugged in, you may need to change the port under **Options > Serial Port > Port**.
<div style="background-color:#F3F3F3; text-align:left; vertical-align: middle; padding:15px 30px;"> <b>Note:</b>
<br/>- If your application uses a baud rate other than 9600, specify it with `-b BAUDRATE` in the command above.
<br/>- This method only works for a single board. To work with multiple boards, open a serial terminal manually as described below.</div>

Check your connection parameters:
### Manually opening a serial terminal

1. Select **Options > Serial Port**.
1. You should see 9600 baud, 8 bits, 1 stop bit, no parity (9600-8-N-1).
1. If you do not see your board, click **Re-Scan Peripherals**.
You can open a serial terminal manually, which is useful when the board is already flashed with the desired application (i.e. one built with the [online compiler](../quick-start/build-with-the-online-compiler.html)).

Your terminal program is now configured and connected.
When a single board is connected, run:

## Using terminal applications on Linux
```
mbed sterm
```

CoolTerm should work under Linux. If for some reason it doesn't, you can try one of the following:
`mbed sterm` starts message printing.

- [Minicom](https://help.ubuntu.com/community/Minicom).
- [GNU Screen](https://www.gnu.org/software/screen/manual/screen.html).
To close the serial terminal, enter <kbd>Ctrl + C</kbd>.

## Minimal Printf
<div style="background-color:#F3F3F3; text-align:left; vertical-align: middle; padding:15px 30px;"> <b>Note:</b>
<br/>If your application uses a baud rate other than 9600, specify it with `-b BAUDRATE` when opening the serial terminal.
<br/>If you have multiple boards connected:
<br/>1. Run `mbedls` to find the port of the board you want to use.
<br/>2. Run `mbed sterm -p PORT`.
<br/>To list all options, run `mbed sterm -h`</div>

For low memory devices you may optionally use the [ArmMbed minimal printf library](https://github.com/ARMmbed/minimal-printf).
## Additional examples - reading user inputs

# Additional examples
In addition to printing messages, Mbed OS applications can also read keyboard inputs from the user using the [BufferedSerial](../apis/bufferedserial.html) and [UnbufferedSerial](../apis/unbufferedserial.html) classes.

Use your terminal application to interact with the following examples.

If you're not sure how to build these examples and run them on your board, please see our [build tools section](../build-tools/index.html).

## Echo back characters you type
### Echo back characters you type

[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Serial_EchoBack/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Serial_EchoBack/blob/v6.0/main.cpp)

## Use the U and D keys to make LED1 brighter or dimmer
### Use the U and D keys to make LED1 brighter or dimmer

<span class="tips">**Note:** This example only works if LED1 is on the Pwm pin of the board you are using, such as the NUCLEO-F401RE. </span>
<span class="notes">**Note:** This example only works if LED1 is on the Pwm pin of the board you are using, such as the NUCLEO-F401RE. </span>

<span class="images">![](../../images/NUCLEOF401RE.png)<span>The pin map of the NUCLEO-F401RE shows LED1 on the Pwm pin.</span></span>

[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Serial_LEDControl/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Serial_LEDControl/blob/v6.0/main.cpp)

## Pass characters in both directions
### Pass characters in both directions

Tie pins together to see characters echoed back.

[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Serial_PassCharacters/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Serial_PassCharacters/blob/v6.0/main.cpp)

## Using stdin, stdout and stderr

By default, the C `stdin`, `stdout` and `stderr file` handles map to the PC serial connection:

[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Serial_STDOUT/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Serial_STDOUT/blob/v6.0/main.cpp)

## Read to a buffer
### Read to a buffer

[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-snippet-Serial_ReadToBuffer/tree/v6.0)](https://github.com/ARMmbed/mbed-os-snippet-Serial_ReadToBuffer/blob/v6.0/main.cpp)
2 changes: 1 addition & 1 deletion docs/quick-start/further_reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- [Mbed OS serial communication](../program-setup/serial-communication.html).

- Tutorials:
- [Other debugging methods](../debug-test/methods.html).
- [Debugging](../debug-test/methods.html).
- [Serial communications](../program-setup/serial-communication.html).
- [Optimizing binary size](../apis/platform-tutorials.html).

Expand Down
22 changes: 0 additions & 22 deletions docs/quick-start/quick-start-cli-debug.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/quick-start/quick-start-compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,3 @@ Alternatively, you may select the import button on the top left hand side of the
1. Open the folder where the executable file was downloaded, and then click and drag (or copy and paste) the file to your Mbed board's USB device folder.

1. Press the board's reset button.

## Related links

- [Collaborating with multiple authors](../build-tools/collaborative-work.html).
- [Mbed OS statistics API](../apis/mbed-statistics.html).
- [Mbed OS configuration](../program-setup/advanced-configuration.html).
- [Mbed OS serial communication](../program-setup/serial-communication.html).
33 changes: 0 additions & 33 deletions docs/quick-start/quick-start-online-debug.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/quick-start/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The quick start offers two versions of Blinky: the full profile version and the

## Please choose how to proceed

| [Build with Mbed Studio](https://os.mbed.com/docs/mbed-studio/current/getting-started/index.html) | [Build with Mbed Online Compiler](../quick-start/build-and-debug-with-the-online-compiler.html) | [Build with Mbed CLI](../quick-start/build-and-debug-with-mbed-cli.html) |
| [Build with Mbed Studio](https://os.mbed.com/docs/mbed-studio/current/getting-started/index.html) | [Build with Mbed Online Compiler](../quick-start/build-with-the-online-compiler.html) | [Build with Mbed CLI](../quick-start/build-with-mbed-cli.html) |
| --- | --- | --- |
|Download our dedicated desktop IDE, including all the necessary tools to work with Mbed OS.<br> This link will take you to the Mbed Studio documentation site. | Zero-installation web IDE to explore Mbed OS; great for rapid prototyping and education. | Command-line tool requiring manual setup of tools, but providing the greatest degree of flexibility. |

Expand Down
30 changes: 1 addition & 29 deletions docs/tools/debug/debug_intro.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Debugging
<h1 id="debugging">Debugging with third party tools</h1>

There are extensive instructions on debugging Arm Mbed OS applications with [uVision 5](../debug-test/keil-uvision.html), [Eclipse](../debug-test/third-party-tools.html) and [Visual Studio Code](../debug-test/visual-studio-code.html), but you can use any IDE that supports GDB to debug Mbed OS applications. This document gives advice on how to configure these IDEs. Before starting, first [configure your local debug toolchain](setting-up-a-local-debug-toolchain.html).

Expand Down Expand Up @@ -28,34 +28,6 @@ In your project folder, run:
$ mbed export -i make_gcc_arm -m K64F
```

#### Serial terminal

You can open a serial terminal to the COM port of a connected Mbed target (usually board) using the `mbed sterm` command. If no COM port is specified, Mbed CLI detects the connected Mbed targets and their COM ports.

There are various options to `mbed sterm`:

- `--port <COM port>` to specify system COM port to connect to.
- `--baudrate <numeric>` to select the communication baudrate, where the default value is 9600.
- `--echo <on|off>` to switch local echo (default is `on`).
- `--reset` to reset the connected target by sending Break before opening the serial terminal.

You can also set default port, baudrate and echo mode using the `TERM_PORT`, `TERM_BAUDRATE` and `TERM_ECHO` Mbed CLI configuration options.

The following shortcuts are available within the serial terminal:

- Ctrl+b - Send Break (reset target).
- Ctrl+c - Exit terminal.
- Ctrl+e - Toggle local echo.
- Ctrl+h - Help.
- Ctrl+t - Menu escape key.
- _You can view more shortcuts within the serial terminal's help menu (Ctrl+h)._

You can also add the `--sterm` option to `mbed compile -f` to compile a new program, flash the program or firmware image to the connected target and then open the serial terminal to its COM port:

```
$ mbed compile -t GCC_ARM -m K64F -f --sterm
```

## Building your project

You can now configure your IDE to build this project by setting the build command to:
Expand Down
Loading