Skip to content

New feature: Serial Terminal (revised) #664

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 12 commits into from
May 16, 2018

Conversation

screamerbg
Copy link
Contributor

Revised based on feedback in #650 and #652

This PR adds serial terminal feature to Mbed CLI via mbed sterm command. Currently, the supported command-line arguments are:

  • --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.

If no COM port is specified, Mbed CLI will attempt to detect the connected Mbed target and its COM port.

Inside the serial terminal, there's a wider variety of options:

--- CTRL+B     Send Break (reset target)
--- CTRL+C     Exit terminal
--- CTRL+E     Toggle local echo
--- CTRL+H     Help
--- CTRL+T     Menu escape key, followed by:
---    P       Change COM port
---    B       Change baudrate
---    TAB     Show detailed terminal info
---    CTRL+A  Change encoding (default UTF-8)
---    CTRL+F  Edit filters
---    CTRL+L  Toggle EOL
---    CTRL+R  Toggle RTS
---    CTRL+D  Toggle DTR
---    CTRL+C  Send control character to remote
---    CTRL+T  Send control character to remote

Example usage with mbed sterm

$ mbed sterm -r -b 115200
[mbed] Detecting connected targets/boards to your system...
[mbed] Opening serial terminal to "DISCO_L475VG_IOT01A"
--- Terminal on /dev/tty.usbmodem1413 - 115200,8,N,1 ---
$$$076402216E3C651F5178F3460x10000188
Start Simple Mbed Cloud Client
Connecting to the network using Wifi...

This feature also extends the mbed compile command and adds --sterm argument, which could be combined with -f/--flash. This enables automation workflow where Mbed CLI will first compile a program, then flash/apply it onto the connected target, and then open serial terminal to the target, so you can check the output of the freshly compiled program - see below.

$ mbed compile -t GCC_ARM -m DETECT -f --sterm
Building project mbed-os-example-blinky (DISCO_L475VG_IOT01A, GCC_ARM)
Scan: .
Scan: mbed
Scan: env
Compile [100.0%]: main.cpp
Link: mbed-os-example-blinky
Elf2Bin: mbed-os-example-blinky
+------------------+-------+-------+------+
| Module           | .text | .data | .bss |
+------------------+-------+-------+------+
| [fill]           |   102 |     7 |   11 |
| [lib]/c.a        | 27166 |  2204 |   56 |
| [lib]/gcc.a      |  3752 |     0 |    0 |
| [lib]/m.a        |    88 |     0 |    0 |
| [lib]/misc       |   236 |    16 |   28 |
| main.o           |   267 |     4 |  276 |
| mbed-os/drivers  |  1301 |     4 |  100 |
| mbed-os/hal      |  1395 |     4 |   66 |
| mbed-os/platform |  3096 |     4 |  354 |
| mbed-os/rtos     |  9114 |   168 | 5989 |
| mbed-os/targets  |  7017 |     5 |  388 |
| Subtotals        | 53534 |  2416 | 7268 |
+------------------+-------+-------+------+
Total Static RAM memory (data + bss): 9684 bytes
Total Flash memory (text + data): 55950 bytes

Image: ./BUILD/DISCO_L475VG_IOT01A/GCC_ARM/mbed-os-example-blinky.bin
[mbed] Detecting connected targets/boards to your system...
[mbed] Opening serial terminal to "DISCO_L475VG_IOT01A"
--- Terminal on /dev/tty.usbmodem1413 - 115200,8,N,1 ---
$$$07200221061A657F395EF362start
something 1
something 2
something 3

The implementation is based on PySerial, which is one of the fundamental libraries for Mbed Greentea (mbed test). Therefore there are no additional dependencies.

Inspired by @yennster's request (#639).
Also revised based on feedback in #650 and #652

Copy link
Contributor

@sg- sg- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 but might want @toyowata to review and confirm if we are using UTF-8 support by default with the Arm standard library and Japanese characters.

@toyowata
Copy link

toyowata commented Apr 30, 2018

@sg- @screamerbg

I tested it on Japanese Windows 10 and works fine.
The test program had UTF-8 Japanese code below.

#include "mbed.h"

DigitalOut led1(LED1);

// main() runs in its own thread in the OS
int main() {
    printf("hello, Mbed world!\n");
    printf("こんにちは。エェェェェンベッドの世界へようこそ!\n");
    int count = 0;
    while (true) {
        led1 = !led1;
        printf("count = %d\n", ++count);
        wait(0.5);
    }
}
C:\Users\toyom\mbed-os-example-blinky>mbed sterm
[mbed] Detecting connected targets/boards to your system...
[mbed] Opening serial terminal to "K64F"
--- Terminal on COM22 - 9600,8,N,1 ---
hello, Mbed world!
こんにちは。エェェェェンベッドの世界へようこそ!
count = 1
count = 2
count = 3
count = 4
count = 5
count = 6
count = 7
count = 8
count = 9
count = 10
count = 11
count = 12
count = 13
count = 14
--- [QUIT] ---

@screamerbg
Copy link
Contributor Author

Bump @theotherjimmy @yennster

Also cc @jupe @teetak01

@yennster
Copy link
Contributor

@screamerbg For all of the commands with letters such as CTRL+B, does this command require that B be capitalized? i.e. the full command would be CTRL+SHIFT+b?

@screamerbg
Copy link
Contributor Author

@yennster these don't have to be capitalised. Technically lower case.

@theotherjimmy
Copy link
Contributor

@screamerbg I'd personally like to see them lower cased. I don't think anyone will have a problem with CTRL vs. Ctrl, although the later is what's printed on my keyboard...

@screamerbg
Copy link
Contributor Author

@theotherjimmy @yennster These are now provided lower case (see latest commit)

@screamerbg
Copy link
Contributor Author

Bump @MarceloSalazar

@screamerbg
Copy link
Contributor Author

@iriark01 @AnotherButler @GarySwansonARM @cargro This feature could replace the various OS-specific terminal tools we have in OS documentation and training materials. What do you think?

@theotherjimmy
Copy link
Contributor

@screamerbg As usual, you want to specify the version of Mbed CLI :D. Yes documenting this feature are the primary method of interaction with the serial console is warranted. You may want to leave the rest as alternatives.

Copy link
Contributor

@MarceloSalazar MarceloSalazar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great!

--- Mbed Serial Terminal (0.3a)
--- Based on miniterm from pySerial
---
--- CTRL+B Send Break (reset target)
Copy link
Contributor

@yennster yennster May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@screamerbg Are these just comments within the file? Can they be changed to match the lowercase commands in the README? (L67-L85)

README.md Outdated
- Ctrl+t - Menu escape key
- _Even more shortcuts are available through the Menu shortcut. Check the help within the serial terminal (Ctrl+h).__

To automate things, you can also add the `--sterm` option to `mbed compile -f` to compile a new program, flash the program/firmware image to the connected target and then open serial terminal to it's COM port:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@screamerbg I think this should say:

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great. Thanks!

README.md Outdated
- Ctrl+e - Toggle local echo
- Ctrl+h - Help
- Ctrl+t - Menu escape key
- _Even more shortcuts are available through the Menu shortcut. Check the help within the serial terminal (Ctrl+h).__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@screamerbg Why not list all of the shortcut commands within the README?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yennster Primarily because it's a long list of commands that are very specific to the console experience. Unless you have the console running, you won't care about these options. Does this make sense?

@screamerbg
Copy link
Contributor Author

@iriark01
Copy link
Contributor

@AnotherButler can you do a quick run-through please?

@BlackstoneEngineering
Copy link

I assume we've tested it and works on all 3 OS's? Im super pumped for this, cant wait to make a video about it!

README.md Outdated
- Ctrl+e - Toggle local echo
- Ctrl+h - Help
- Ctrl+t - Menu escape key
- _Even more shortcuts are available through the Menu shortcut. Check the help within the serial terminal (Ctrl+h).__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the last bullet should say:

More shortcuts can be viewed within the serial terminal's help menu (Ctrl+h).

README.md Outdated
- Ctrl+t - Menu escape key
- _Even more shortcuts are available through the Menu shortcut. Check the help within the serial terminal (Ctrl+h).__

You can also add the --sterm option to mbed compile -f to compile a new program, flash the program/firmware image to the connected target and then open the serial terminal to it's COM port:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this line needs references to commands wrapped in code tags:

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

@@ -514,6 +514,32 @@ $ mbed export -i uvision -m K64F

Mbed CLI creates a `.uvprojx` file in the projectfiles/uvision folder. You can open the project file with uVision.

### 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 will attempt to detect the connected Mbed targets and their COM ports.
Copy link
Contributor

@yennster yennster May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mbed CLI will attempt to detect the connected Mbed targets and their COM ports.

Does this mean you can use the mbed sterm command with multiple Mbed boards plugged into the computer at the same time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It would detect all and iterate through them (one by one, not simultaneously).

@screamerbg screamerbg requested a review from AnotherButler May 16, 2018 13:19
@screamerbg screamerbg merged commit 66f734d into ARMmbed:master May 16, 2018
@screamerbg
Copy link
Contributor Author

@BlackstoneEngineering it's now live.

@jeromecoutant
Copy link
Contributor

Hi @screamerbg

As in test_api.py, greentea is able to detect the used baud rate:
baud_rate = cfg['platform.stdio-baud-rate'].value

Do you think it is possible to get the same feature within 'mbed compile xxx -f --sterm' command ?

Thx

@theotherjimmy
Copy link
Contributor

@screamerbg If we were to implement this feature, it would involve calling mbed compile --config to extract the parameter. That seems pretty excessive, implementation wise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants