-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
RP2040: Support for UART #4224
RP2040: Support for UART #4224
Conversation
Tested by connecting a gps Breakout to TX0/RX0 on Pins GP12/13 and running the gps_echotest.py script. worked normally. |
oh wow, this is awesome. let me try it too :) |
ok GPS tested, 9600 baud and works as expected. will try some RX/TX loopback tests |
tested all common baud rates from 1200 to 115200 with
|
@ladyada Did gps_simpletest work for you? It is not seeing a fix for me.... echotest works fine..... |
i didnt test fix cause thats a 'sit it outdoors' thing and its really cold out :D |
hopefully not related to UART -- trying to figure it out.... |
There may be an issue -- the gps.update is faiong in _read_sentence here:
https://github.com/adafruit/Adafruit_CircuitPython_GPS/blob/master/adafruit_gps.py#L200 |
is there potentially an issue with this not returning the correct value for bytes in the uart?
|
Thanks! @ladyada and @jerryneedell for the extensive testing... 👍
Seems like /*! \brief Determine whether data is waiting in the RX FIFO
* \ingroup hardware_uart
*
* \param uart UART instance. \ref uart0 or \ref uart1
* \return 0 if no data available, otherwise the number of bytes, at least, that can be read
*
* \note HW limitations mean this function will return either 0 or 1.
*/
static inline bool uart_is_readable(uart_inst_t *uart) {
// PL011 doesn't expose levels directly, so return values are only 0 or 1
return !(uart_get_hw(uart)->fr & UART_UARTFR_RXFE_BITS);
} |
yeha we should be buffering the UART data internally |
yup... that's what I was thinking for a workaround |
just "for fun" I changed the gps code to continue as long as anything was in the UART and now both the gps_simpltest.py and gps_time_source.py examples work.
Not a fix, but it's nice to see it running |
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 this! I think we do need to add buffering before we merge this because the API explicitly allows setting the buffer size.
We can either copy other ports and use an interrupt to write into a ring buffer. Or, we can use the RP2040 ring DMA while constraining the buffer sizes to powers of two.
I'd be happy to add the buffering next week if you'd like to hand it off.
I see. I have added internal buffering now. |
@microdev - sorry... It does not work at all. Even the "echotest" now just returns a steady stream of "HHHHHHH" characters. the "simpletest" crashes due to a memory allocation error..... |
did a simple test -- with nothing connected -- same result with GPS connected.
|
FYI _ I built CP with this PR and tested it with the GPS -- both the echotest and simpletest now work normally. |
- add internal buffering - rtc initialization fix
Tested using: import board
import busio
import random
uart = busio.UART(board.GP0, None, baudrate=9600)
uart.write("|-".encode("UTF-8")) # Clear display
uart.write("Hello world! ".encode("UTF-8")) # Show some text.
uart.write("Rand: ".encode("UTF-8"))
rand = str(random.randint(0, 100))
uart.write(rand.encode("UTF-8")) # So I can see that it's working every time, print a random number. and a SparkFun Serial LCD. I can verify that it is reliably writing, and that the random value is different every time. |
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 improvements. Unfortunately, UART has a lot of corner cases. Let me know if you'd like to hand off the PR to me.
As an aside the 32 is too large, new issue is #56. I'll do a PR for it, once my previous PR gets past PyLint and the examples duplicate-code annoyance. |
@tannewt Thanks! for the review. I have addressed the current set of suggestions. |
- address suggested changes - refine uart instance availibility checks - improve pin validation and rx buffer handling
* Always clear the peripheral interrupt so we don't hang when full * Store the ringbuf in the object so it gets collected when we're alive * Make UART objects have a finaliser so they are deinit when their memory is freed * Copy bytes into the ringbuf from the FIFO after we read to ensure the interrupt is enabled ASAP * Copy bytes into the ringbuf from the FIFO before measuring our rx available because the interrupt is based on a threshold (not > 0). For example, a single byte won't trigger an interrupt.
Ok, I've fixed a couple more issues I spotted. If folks could test and review, that'd be awesome. |
Reran gsp_echotest and gps_simpletest -- both still work normally. |
Gah, I had my debug text files in there for a bit. re-did that last commit and the CI needs to run 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.
Thank you @microdev1
Thanks! everyone for collaborating on this. 👍 |
Thank you for working hard on the PR, its a wonderful and helpful addition! |
No description provided.