-
Notifications
You must be signed in to change notification settings - Fork 178
New feature: Serial Terminal #650
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
Conversation
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.
Seems slick. @SenRamakri @deepikabhavnani Have a look and see if there is a natural way to plugin or incorporate the necessary logic for upcoming binary trace expansion.
It seems odd to me that compile would open a serial terminal. I fear we are turning |
mbed/mbed.py
Outdated
@@ -34,6 +34,7 @@ | |||
import zipfile | |||
import argparse | |||
import tempfile | |||
from mbed_cdc import mbed_cdc |
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.
This import should probably be scoped in some way. maybe from mbed.mbed_cdc
or from .mbed_cdc
. Further, this seems very redundant: from thing import thing
.
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.
This is not a must have, this works in python 2
try: | ||
from mbed_host_tests.host_tests_toolbox import flash_dev | ||
except (IOError, ImportError, OSError): | ||
error("The '-f/--flash' option requires that the 'mbed-greentea' python module is installed.\nYou can install mbed-greentea by running 'pip install mbed-greentea'.", 1) |
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.
This is not strictly true. The -f/--flash
option requires mbed-host-tests
.
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.
I'd rather encourage the user to install mbed-greentea
which will pull in all the needed modules behind it. In this case, the product is mbed-greentea
, not host-tests.
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.
Sure, that works. If mbed-host-tests
is not something the user should ever install standalone, I'll merge it with greentea.
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.
In case this was not clean: this is resolved.
mbed/mbed_cdc.py
Outdated
@@ -0,0 +1,111 @@ | |||
|
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.
License?
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.
Added. Thanks
mbed/mbed_cdc.py
Outdated
@@ -0,0 +1,111 @@ | |||
|
|||
def mbed_cdc(port, reset=False, sterm=False, baudrate=9600, timeout= 10, print_term_header=True): |
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.
Could we drop mbed
from the name of this function? it adds no meaning here. I think this is more a run_serial_term
or something similar.
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.
But it's not a standard serial terminal and it's rather for Mbed needs. So I'd rather not use a generic name. Also the whole file would rather go in https://github.com/ARMmbed/mbed-sterm, and this function name will be the contract.
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.
Understood. This is resolved.
mbed/mbed_cdc.py
Outdated
except (IOError, ImportError, OSError): | ||
return False | ||
|
||
def get_instance(*args, **kwargs): |
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.
This function does not capture any state. Could you move it outside of the body of the mbed_cdc
function?
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 does - see port
in printed message.
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.
port is the first parameter. It seems weird to capture it and pass it in.
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.
This is just a minor style comment. Not a blocker.
mbed/mbed_cdc.py
Outdated
except: | ||
result = False | ||
|
||
def cdc_term(serial_instance): |
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.
I'm pretty sure that this function does not capture any state either. Could you move this function out of mbed_cdc
?
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 uses other variables from the wrapper function, e.g. imports and cdc_reset()
mbed/mbed_cdc.py
Outdated
console_print('[QUIT]') | ||
term.stop() | ||
term.alive = False | ||
break |
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.
This break is not needed; the loop already checks for term.alive
mbed/mbed_cdc.py
Outdated
def cdc_reset(serial_instance): | ||
try: | ||
serial_instance.sendBreak() | ||
except: |
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.
This except will catch ctrl+c
. You probably did not mean to do that.
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.
Then perhaps you could fix it in mbed-host-tests
as well? :) https://github.com/ARMmbed/htrun/blob/master/mbed_host_tests/host_tests_plugins/module_reset_mbed.py#L77
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.
Yep! Just a second.
mbed/mbed_cdc.py
Outdated
except: | ||
try: | ||
serial_instance.setBreak(False) # For Linux the following setBreak() is needed to release the reset signal on the target mcu. | ||
except: |
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.
This except will catch ctrl+c
. You probably did not mean to do that.
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.
See previous comment
mbed/mbed_cdc.py
Outdated
serial_port.reset_input_buffer() | ||
if reset: | ||
cdc_reset(serial_port) | ||
result = True |
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.
cdc_reset
may set result
to False
. This statement ignores that assignment, effectively throwing away the reset failure.
mbed/mbed_cdc.py
Outdated
term.console.write(echo_text) | ||
term.writer = input_handler | ||
|
||
if print_term_header: |
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.
If you're referring to this by Nope something else.port
, why not just pass it in?
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.
Not sure what you meant. Could you elaborate?
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.
Please ignore, I was mistaken.
@screamerbg All that remains to be fixed is the two |
Why is this only an option to detect/compile? Can we start it by itself? like, "mbed startserial [other options if multiple targets are detected]" OR "mbed sterm". |
@SenRamakri How is |
If "mbed detect -s" take options in case of multiple targets, then yes, we don't need "mbed sterm". |
@SenRamakri What do you mean by "take options in case of multiple targets"? What options would it take? how do they apply to multiple targets? |
Offline discussion with @theotherjimmy here confirmed that "mbed detect" does pick one of many targets if required. So, "mbed detect -s" does support what I was looking for. Thanks for confirming, @theotherjimmy |
So glad this is taking off @screamerbg ! I'll take a look at the README tomorrow 😄 |
@screamerbg Is there a way to change the baud rate for the serial monitor? Right now it looks like it defaults to |
Does this feature support terminal codes (ANSI/VT100) ? |
@yennster You can change the baudrate form within the terminal using Ctrl+T + B combo. There's no commandline flag (yet) |
@jupe The implementation invokes PySerial miniterm. This is from miniterm's documentation: This is a console application that provides a small terminal application. Miniterm itself does not implement any terminal features such as VT102 compatibility. However it may inherit these features from the terminal it is run. For example on GNU/Linux running from an xterm it will support the escape sequences of the xterm. On Windows the typical console window is dumb and does not support any escapes. When ANSI.sys is loaded it supports some escapes. http://pyserial.readthedocs.io/en/latest/tools.html#module-serial.tools.miniterm On Mac terminal it provides a fully featured ANSI support. Had a chance to try it with an ANSI embedded program @stevew817 wrote. |
I tried this with mbed-client-cli which provides ANSI support. Couple comments / proposals:
|
Follow up PR #664 |
Mbed CLI already has a -f option to automatically flash the program to the connected board after compiling. This PR takes the next natural next step to add serial terminal via
-s/--sterm
option ("s" for serial) tombed compile
andmbed detect
.Workflow
This PR extends
mbed compile
andmbed detect
by adding-s/--sterm
option. The option can be chained with-f/--flash
(withmbed compile
) or-r/--reset
(withmbed detect
), meaning that Mbed CLI will first apply the new firmware image, reset the MCU/target/board and then open serial terminal.The serial terminal offers few commonly used shortcuts:
There are much more options behind the terminal menu (Ctrl+T).
The implementation is based on PySerial, which is one of the fundamental libraries for Mbed Greentea (
mbed test
). Therefore there are no additional dependencies.Example usage with
mbed compile
Example use with
mbed detect
Inspired by @yennster's request (#639).
@yennster Do you think you could look into adding help for this feature in the README.md?