-
Notifications
You must be signed in to change notification settings - Fork 177
Update serial communication and clean up duplicated & outdated info #1317
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
Changes from all commits
c3f4b37
7f461a1
0a55715
7dbd02e
7f8ba37
04e7a53
91fbd10
128f5a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,57 +6,71 @@ 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). | ||||||
| - Print out messages to a host PC terminal (useful for debugging). | ||||||
| - 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. | ||||||
| - Communicate with applications running on the host computer 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. | ||||||
|
|
||||||
| [](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_HelloWorld/main.cpp) | ||||||
| [](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_STDOUT/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`. When a single board is connected, run: | ||||||
|
|
||||||
| <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> | ||||||
| ``` | ||||||
| mbed sterm | ||||||
| ``` | ||||||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ### Installing an application for Windows | ||||||
| (If you have multiple boards connected, please refer to [Additional options of mbed sterm](#additional-options-of-mbed-sterm).) | ||||||
|
|
||||||
| There are many terminal applications for Windows, including: | ||||||
| `mbed sterm` starts message printing. | ||||||
|
|
||||||
| - [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. | ||||||
| Restart the application using the board's reset button, or by entering <kbd>Ctrl + B</kbd> in the serial terminal. | ||||||
| The console prints "Hello World!" to the terminal after the reset. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We haven't used the word "console" until now. What does it refer to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, it should be "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**. | ||||||
| <span class="tips">**Tip:** To compile, flash and open a serial terminal in one command line, you can append `--flash --sterm` to `mbed compile`.</span> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a little out of context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to have a separate (short) section for it |
||||||
|
|
||||||
| Check your connection parameters: | ||||||
| ## Additional options of mbed sterm | ||||||
|
|
||||||
| 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**. | ||||||
| - If you have multiple boards connected: | ||||||
| 1. Run `mbedls` to find the port of the board you want to use. | ||||||
| 1. Run `mbed sterm -p <PORT>`. | ||||||
|
|
||||||
| Your terminal program is now configured and connected. | ||||||
| If your application uses a baud rate, specify with `-b <BAUDRATE>` when opening the serial terminal. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't they always use baud rate? Is it just if it's not the default set somewhere? Shouldn't it match the board? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix it |
||||||
|
|
||||||
| ## Using terminal applications on Linux | ||||||
| - To list all options, run `mbed sterm -h`: | ||||||
|
|
||||||
| CoolTerm should work under Linux. If for some reason it doesn't, you can try one of the following: | ||||||
| ``` | ||||||
| usage: mbed sterm [-h] [-m TARGET] [-p PORT] [-b BAUDRATE] [-e ECHO] [-r] [-v] [-vv] | ||||||
|
|
||||||
| - [Minicom](https://help.ubuntu.com/community/Minicom). | ||||||
| - [GNU Screen](https://www.gnu.org/software/screen/manual/screen.html). | ||||||
| Open serial terminal to connected target (usually board), or connect to a user-specified COM port | ||||||
|
|
||||||
| ## Minimal Printf | ||||||
| optional arguments: | ||||||
| -h, --help show this help message and exit | ||||||
| -m TARGET, --target TARGET | ||||||
| Compile target MCU. Example: K64F, NUCLEO_F401RE, | ||||||
| NRF51822... | ||||||
| -p PORT, --port PORT Communication port. Default: auto-detect. Specifying | ||||||
| this will also ignore the -m/--target option above. | ||||||
| -b BAUDRATE, --baudrate BAUDRATE | ||||||
| Communication baudrate. Default: 9600 | ||||||
| -e ECHO, --echo ECHO Switch local echo on/off. Default: on | ||||||
| -r, --reset Reset the targets (via SendBreak) before opening | ||||||
| terminal. | ||||||
| -v, --verbose Verbose diagnostic output | ||||||
| -vv, --very_verbose Very verbose diagnostic output | ||||||
| ``` | ||||||
|
|
||||||
| 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. This is achievable with the [BufferedSerial](../apis/bufferedserial.html) and [UnbufferedSerial](../apis/unbufferedserial.html) classes. | ||||||
|
|
||||||
| Use your terminal application to interact with the following examples. | ||||||
|
|
||||||
|
|
@@ -80,12 +94,6 @@ Tie pins together to see characters echoed back. | |||||
|
|
||||||
| [](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_PassCharacters/main.cpp) | ||||||
|
|
||||||
| ## Using stdin, stdout and stderr | ||||||
|
|
||||||
| By default, the C `stdin`, `stdout` and `stderr file` handles map to the PC serial connection: | ||||||
|
|
||||||
| [](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_STDOUT/main.cpp) | ||||||
|
|
||||||
| ## Read to a buffer | ||||||
|
|
||||||
| [](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_ReadToBuffer/main.cpp) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,21 @@ | ||
| <h1 id="debug-ide-qs">Debugging the quick start</h1> | ||
| <h1 id="debug-ide-qs">Debugging with the Online Compiler</h1> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a lot of similarities with cli debug. I think it would be better to combine the two pages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally agree - the quick start pages are rather brief, maybe CLI and online compiler can go into different sections of one page There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. People using one tool don't like having to read through instructions/info for another tool. And sometimes they don't even realise it's there so they assume it's missing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iriark01 I understand if the instructions are quite different and long. In this case it is rather short and it would remove the duplication. I thought you combined instructions for blinky bare metal ; this would be another example of combined instructions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current documentation layout on the website Maybe, we can rename both "Debugging with ..." to "Exporting to a desktop IDE", and factor out "Using printf" (and how to drag & drop an image) into a separate page "Debugging"? It would still look natural in my personal opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I combined bare metal and the full profile, but not into the same tool. The tools are seen as very separate beasts - Mbed Studio actually has its own site. I would argue that the problem here is that there's no real value to having either of these pages in the quick start. Debugging and exporting are both covered in much greater detail elsewhere in the docs. @LDong-Arm please can you use a branch on this repo rather than a fork? That will generate a preview of the docs site with your changes, which will make this discussion much easier. |
||
|
|
||
| ## Using printf | ||
|
|
||
| The easiest way to do basic debugging is to use the `printf` command in your code, then read the output using a serial terminal, such as [PuTTY](http://www.putty.org/) or [CoolTerm](http://freeware.the-meiers.org/). | ||
| The easiest way to do basic debugging is to use the `printf` function in your code, then read the output using a serial terminal. | ||
|
|
||
| For example, add `printf("Hello World!\n\r");` to the top of your main function, and then recompile the program and flash it to your device. | ||
| For example, add `printf("Hello World!\n");` to the top of your main function, and then recompile the program and flash it to your device. To view the output, open a serial terminal: | ||
| ``` | ||
| mbed sterm | ||
| ``` | ||
|
|
||
| <span class="notes">**Note:** Unless otherwise specified, `printf` defaults to a baud rate of `9600` on Mbed OS. You can modify this value in the `mbed_app.json` file. To configure your terminal client to this baud rate, change the speed option when selecting the port. You can view the [configuration options page](../program-setup/advanced-configuration.html) to learn more about how to configure OS-level options.</span> | ||
| You may need to reset the board, because messages are visible if printed while the terminal is open. | ||
|
|
||
| To determine which communication port your board connects to: | ||
| To close the serial terminal, press Ctrl + C. | ||
|
|
||
| 1. **On Windows**: | ||
| <span class="notes">**Note:** Unless otherwise specified, `printf` defaults to a baud rate of `9600` on Mbed OS. You can modify this value in the `mbed_app.json` file. To configure your terminal client to this baud rate, change the speed option when selecting the port. You can view the [configuration options page](../reference/configuration.html) to learn more about how to configure OS-level options.</span> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is sort of related to my earlier question about baud rate |
||
|
|
||
| 1. Open the Device Manager by pressing <kbr>Windows key</kbr> + <kbr>R</kbr>. | ||
| 1. Enter `devmgmt.msc`. | ||
| 1. Click **OK**. | ||
| 1. Under **Ports (COM & LPT)**: your Mbed board is listed as a `USB Serial Device` next to its COM port. | ||
|
|
||
| 1. **On Linux**: Run `dmesg | grep tty` from your command-line. | ||
|
|
||
| 1. **On macOS**: Run `ls /dev/tty.*` from your command-line. | ||
| For more options of `mbed sterm`, see [Board to PC communication over USB](../tutorials/serial-comm.html). | ||
|
|
||
| ## Exporting to a desktop IDE | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be either "host computer" or "host PC" consistently. Although I might just go with "PC" or "computer" - does the word "host" really clarify anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a leftover from the old documentation, I'll remove it