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
STM32: UART support #2211
STM32: UART support #2211
Conversation
Maybe look at the STM32 Arduino core for inspiration? https://github.com/stm32duino/Arduino_Core_STM32/blob/master/cores/arduino/stm32/uart.c et al |
Or the MicroPython STM32 port? |
@dhalbert I'll see what I can dig out of micropython. It has a very different interface but maybe I can glean their strategy on the interrupts. |
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.
Here are some initial comments. I'm headed out now for the day but will look at the rest tonight.
firmware.bin.zip |
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 double check that this PR doesn't change the version of TinyUSB. The Spresense build is failing because tinyusb is an older version that what is checked in.
I don't know why it's crashing after soft reset. The backtrace of the crash should provide info to help hunt it down. The busio_uart_obj_t data will be left alone until the next vm run where it may be allocated for something else and cleared. I'd suggest clearing the pointer array in uart_reset as well to make sure other memory isn't accidentally referenced on a subsequent run.
ports/stm32f4/mpconfigport.h
Outdated
@@ -40,6 +40,7 @@ | |||
#include "py/circuitpy_mpconfig.h" | |||
|
|||
#define MICROPY_PORT_ROOT_POINTERS \ | |||
void *cpy_uart_obj_all[6]; \ |
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.
Want to use MAX_UART
here?
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 above. I could just have this definition in every mpconfigboard.h file if that's better, though.
@tannewt on the subject of tinyusb, I often find I have a hard time keeping it synced when merging in upstream/master. It only every happens with tinyusb, too. There are no messages or conflicts or anything to signify that the wrong version is taking priority during the merge. Do you have any idea what that might be? |
@hierophect Merging and changing branches doesn't automatically update submodules. After merging and before committing I recommend running |
To get TinyUSB back to the checked in version I recommend looking on github for the hash and then locally change to |
Yes, I usually do:
|
@ladyada Do you think you could give this latest binary a run? I'm trying to get a better handle on what's wrong with it, which is proving tricky without better python experience. It's structurally very similar to stm32duino, but it just doesn't seem to be delivering on the basics these libraries need from it. |
bin if git CI is still down |
@ladyada New bin, should have fixed all crashes and buffer errors. |
yay verified this works a lot better, this is ready to merge/release to folks. open an issue to add dma/non-blocking writes and we can get feedback ask well |
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.
tested functionality on STM32F405
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.
Good job getting this going using the HAL. I think it'd be simpler to not use the HAL for the RX interrupt but don't want to block if others disagree. The main thing will be to make sure the interrupt bits are cleared after you handle it. (The peripheral interrupt bits get merged into the interrupt line to the CPU.)
Hey @tannewt, my current approach is inspired by stm32duino, which is completely HAL based. I opted to follow the way they did things as I felt it'd make stuff more readable to contributors who are familiar with that system. It's also a little closer to NRF, and avoids exposing all the parity and wordlength management 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.
Some q's and a few things to fix.
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 have one non-blocking comment. Will change review to comment so it can be merged after approval from @dhalbert
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.
OK, let's go with this now! I agree with @tannewt that there is a chance you may lose characters due to disabling/enabling, but we can revisit that after some user testing.
This PR adds UART support to the STM32 series of development boards. As required by boards such as the GPS Featherwing, the current implementation allows for unexpected reception of data via a ring buffer. Transmits, however, are blocking. Since the UART HAL does not allow for passing context pointers, UART objects are tracked in global state.
This iteration is currently a bit hacked together. I'd probably be a good idea to revisit the module in the future to remove unnecessary HAL features and streamline the code for improved speed/maintainability.