-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for a debug console, such as ST-Link VCP. #2837
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
7932501
to
2af65bb
Compare
@tannewt @hierophect Could you have a look through the commit, ignore where it says "TODO"...but I'd like your general comments on the solution. |
@k0d it's an interesting idea to have the serial console simultaneously to USB - is there a particular application that you have this in mind for? Did you check out the port level supervisor/serial.c files that exist in most ports? Most of the time, it's automatic to switch to a serial connection when USB is set to 0 (which you can do from the build command as USB=0). Existing implementations aren't very sophisticated because the use is kind of rare, and they don't use the UART module (by design), so this is definitely a more complete implementation. Perhaps you could work it into the existing model somehow, so if the UART module is available it will default to this debug implementation when USB is disabled? |
The serial.c that exists already works if you don't have USB, but...if you want to continue to use the VCP even when USB is enabled then that does't work. When I'm developing it's much easier to have the VCP instead of the USB. I understand it's not everyone would use this when developing, but I use it all the time. |
@hierophect I thought of using the serial.c implementation, which I could do...but I'd have to tweak some things a bit because if USB is enabled, it uses supervisor/shared/serial.c. I think it'd be better to call it console.c, which in turn uses serial.c/usb.c/display.c depending on what's available? |
@hierophect This is ready for review now, the CI checks are failing due to 'Github timeouts', if there are any real issues...I'll fix them. |
e5259d8
to
e8b1484
Compare
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.
Thank you for the PR!
I think that these changes are too invasive to take as is. (All of the _UNAVAILABLE defines are changing a bunch of stuff.) Instead, I'd like to see this build on top of UART by calling the common_hal constructor directly. The only thing UART will need to do it is a "alert me on a character" callback like tinusb has.
Leveraging the existing UART code will:
- Simplify the configuration in
mpconfigboard.h
to the pins and maybe a baudrate. - Simplify the init code in
debug_init
. - Work on more than just STM out of the box except for ctrl-c which requires the callback.
The common_hal implementation of STM32_UART requires there to be an active 'python session', so it doesn't work in certain situations, this is kind of a higher level than the python uart modules. I find it hard to explain this, but it didn't work...I tired it...that's why this PR took so long to make. |
Did you try statically allocating the struct for it? You should be able to pass in a statically allocated struct to the construct and then |
There are examples of that technique for |
@dhalbert link to an example please? :) |
Also see It's a bit complicated because dynamically allocated heap objects can get copied into the static space: see Another example is the internal connection objects in |
@tannewt @hierophect @dhalbert There is a TODO note in supervisor/shared/serial.c, I actually don't know if we need to fix it. Please advise. |
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.
Looks much much better! Thank you! Just a few more things.
fa295bb
to
421e06a
Compare
Strange, the failed checks don't happen when I build locally...it's also not related to my changes. Known issue? |
The errors may be due to some kind of submodule sync problem: one is from STM, and the other has to do with protomatter. Could you merge from upstream and also do |
@dhalbert That didn't fix it, I also get it when I checkout master. |
I think master is broken. It isn't a problem with this PR. |
Yeah, I saw that the RGBMatrix PR broke things...so I'm just ignoring the CI checks now... :) |
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.
Thank you for the updates to this! It's getting close. Just a few more comments about the UART functionality that needs to work outside of the debug use too.
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.
Looks good to me. I chimed in a bit on the VCP TX/RX pin exposure discussion but it seems to already be resolved. Anything to do with Morpho pins is in the territory of "just change the build yourself" anyway.
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.
One small bug to fix and then this will be ready. Thank you!
@tannewt Can we ignore the failed checks? or should we run it again? |
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.
We can ignore it. Thanks!
This is a work in progress!
Todo:
Make more generic
Enable debug_console when entering REPL