Skip to content

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

Merged
merged 1 commit into from
May 19, 2020

Conversation

k0d
Copy link

@k0d k0d commented Apr 30, 2020

This is a work in progress!

Todo:
Make more generic
Enable debug_console when entering REPL

@k0d k0d force-pushed the serial-debug branch 2 times, most recently from 7932501 to 2af65bb Compare May 1, 2020 20:36
@k0d
Copy link
Author

k0d commented May 1, 2020

@tannewt @hierophect
This works now...the only thing is that it's not generic, meaning that we should decide where we set the config and how to enable/disable it.

Could you have a look through the commit, ignore where it says "TODO"...but I'd like your general comments on the solution.

@k0d k0d force-pushed the serial-debug branch from 2af65bb to 5a4752a Compare May 2, 2020 18:20
@hierophect
Copy link
Collaborator

hierophect commented May 4, 2020

@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?

@k0d
Copy link
Author

k0d commented May 4, 2020

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.

@k0d
Copy link
Author

k0d commented May 4, 2020

@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?

@k0d k0d force-pushed the serial-debug branch from 5a4752a to 4fad7b8 Compare May 4, 2020 18:29
@k0d k0d marked this pull request as ready for review May 4, 2020 18:45
@k0d
Copy link
Author

k0d commented May 4, 2020

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

@k0d k0d force-pushed the serial-debug branch 2 times, most recently from e5259d8 to e8b1484 Compare May 4, 2020 19:39
@tannewt tannewt requested review from tannewt and hierophect May 4, 2020 22:41
Copy link
Member

@tannewt tannewt left a 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:

  1. Simplify the configuration in mpconfigboard.h to the pins and maybe a baudrate.
  2. Simplify the init code in debug_init.
  3. Work on more than just STM out of the box except for ctrl-c which requires the callback.

@k0d
Copy link
Author

k0d commented May 4, 2020

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:

  1. Simplify the configuration in mpconfigboard.h to the pins and maybe a baudrate.
  2. Simplify the init code in debug_init.
  3. 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.

@tannewt
Copy link
Member

tannewt commented May 5, 2020

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 never_reset it to keep it alive throughout VM runs.

@dhalbert
Copy link
Collaborator

dhalbert commented May 5, 2020

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 never_reset it to keep it alive throughout VM runs.

There are examples of that technique for displayio, such as the SPI object it uses.

@k0d
Copy link
Author

k0d commented May 5, 2020

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 never_reset it to keep it alive throughout VM runs.

There are examples of that technique for displayio, such as the SPI object it uses.

@dhalbert link to an example please? :)

@dhalbert
Copy link
Collaborator

dhalbert commented May 5, 2020

@dhalbert link to an example please? :)

shared-module/displayio/__init__.c and .h. The primary_display_t objects in displays are allocated statically, and include displayio_fourwire_obj_t in a union. Fourwire includes an SPI object: see shared-module/displayio/FourWire.h.

Also see common_hal_busio_spi_never_reset() calls in shared-module/displayio/FourWire.c.

It's a bit complicated because dynamically allocated heap objects can get copied into the static space: see reset_displays() in __init__.c.

Another example is the internal connection objects in ports/nrf/common-hal/_bleio/Adapter.*

@k0d k0d force-pushed the serial-debug branch from e8b1484 to 7c2fc8e Compare May 5, 2020 19:45
@k0d k0d marked this pull request as draft May 5, 2020 19:45
@k0d
Copy link
Author

k0d commented May 5, 2020

@tannewt @hierophect @dhalbert
This PR has been rewritten from scratch, it now uses the common_hal to setup the UART. Much nicer, cleaner and logical! Many thanks to the pointers.

There is a TODO note in supervisor/shared/serial.c, I actually don't know if we need to fix it. Please advise.

@k0d k0d force-pushed the serial-debug branch from 7c2fc8e to db9c02f Compare May 5, 2020 20:08
@k0d k0d marked this pull request as ready for review May 5, 2020 21:02
@k0d k0d requested a review from tannewt May 5, 2020 21:02
@k0d k0d force-pushed the serial-debug branch from db9c02f to 0784746 Compare May 6, 2020 08:15
@tannewt tannewt added this to the 5.x.0 - Features milestone May 6, 2020
Copy link
Member

@tannewt tannewt left a 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.

@k0d k0d force-pushed the serial-debug branch 2 times, most recently from fa295bb to 421e06a Compare May 6, 2020 21:16
@k0d k0d requested a review from tannewt May 6, 2020 21:32
@k0d
Copy link
Author

k0d commented May 6, 2020

Strange, the failed checks don't happen when I build locally...it's also not related to my changes. Known issue?

@dhalbert
Copy link
Collaborator

dhalbert commented May 6, 2020

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 git submodule sync and git submodule update? Also make sure your pushes are from a branch with everything added.

@k0d k0d force-pushed the serial-debug branch from 421e06a to d96695b Compare May 6, 2020 21:48
@k0d
Copy link
Author

k0d commented May 6, 2020

@dhalbert That didn't fix it, I also get it when I checkout master.

@tannewt
Copy link
Member

tannewt commented May 7, 2020

I think master is broken. It isn't a problem with this PR.

@k0d
Copy link
Author

k0d commented May 7, 2020

Yeah, I saw that the RGBMatrix PR broke things...so I'm just ignoring the CI checks now... :)

@k0d k0d force-pushed the serial-debug branch from d96695b to 19f510e Compare May 9, 2020 09:18
Copy link
Member

@tannewt tannewt left a 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.

@k0d k0d requested a review from tannewt May 18, 2020 12:08
hierophect
hierophect previously approved these changes May 18, 2020
Copy link
Collaborator

@hierophect hierophect left a 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.

Copy link
Member

@tannewt tannewt left a 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!

@k0d
Copy link
Author

k0d commented May 19, 2020

@tannewt Can we ignore the failed checks? or should we run it again?

Copy link
Member

@tannewt tannewt left a 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!

@tannewt tannewt merged commit 2c2b533 into adafruit:master May 19, 2020
@k0d k0d deleted the serial-debug branch May 19, 2020 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants