Skip to content
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

7.2.4 Feather RP2040 GPIO0 board.UART() problem #6219

Closed
dhalbert opened this issue Apr 1, 2022 · 2 comments
Closed

7.2.4 Feather RP2040 GPIO0 board.UART() problem #6219

dhalbert opened this issue Apr 1, 2022 · 2 comments
Labels
bug rp2040 Raspberry Pi RP2040
Milestone

Comments

@dhalbert
Copy link
Collaborator

dhalbert commented Apr 1, 2022

7.2.4 and some earlier versions have a problem with GPIO0 being used for board.UART() on the Feather RP2040. The following program will hang and then USB will disconnect after 10 iterations, due to the gc.collect().,

This is related to #6213 and was found after fixing that bug by setting ringbuf->buf to NULL in ringbuf_free().

import board
import gc
import time

time.sleep(5)
uart = board.UART()
uart.baudrate = 115200

i = 0
while True:
    if i % 10 == 0:
        gc.collect()
    data = f"abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz: {i}\n"
    print(data, end="")
    uart.write(bytes(data, "utf-8"))
    i += 1
    time.sleep(0.0)

If you remove the early gc.collect(), it hangs later, when a gc is necessary, after about 867 iterations or something like that.

import board
import gc
import time

time.sleep(5)
uart = board.UART()
uart.baudrate = 115200

i = 0
while True:
    if i % 10 == 0:
        gc.collect()
    data = f"abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz: {i}\n"
    print(data, end="")
    uart.write(bytes(data, "utf-8"))
    i += 1
    time.sleep(0.0)

The default pins for board.UART() are (from mpconfigboard.h):

#define DEFAULT_UART_BUS_RX (&pin_GPIO1)
#define DEFAULT_UART_BUS_TX (&pin_GPIO0)

If GPIO0 is changed to another TX-capable UART0 pin, then the problem does not happen. I have looked for some issue about the pin->number being zero being treated specially, but haven't found it yet.

@dhalbert dhalbert added this to the 7.2.x milestone Apr 1, 2022
@dhalbert dhalbert added bug rp2040 Raspberry Pi RP2040 labels Apr 1, 2022
@dhalbert
Copy link
Collaborator Author

dhalbert commented Apr 1, 2022

This is affected by whether or not the TX and/or RX pins are connected to another board. I was testing with them connected to a QT Py RP2040 that was not powered. TX->RX, RX->TX, and common ground. Without the connection, I don't see the failure. To be continued.

So I don't think it's GPIO0 per se, it's that GPIO was connected to something.

@dhalbert
Copy link
Collaborator Author

dhalbert commented Apr 4, 2022

Closing in favor of #6237.

@dhalbert dhalbert closed this as completed Apr 4, 2022
KurtE pushed a commit to KurtE/circuitpython that referenced this issue Apr 21, 2022
Rework the ADC implementation to follow the improved ADC/ADCBlock API.
This adds support for calibrated voltage readings and the ADC2 block.  The
ADC API is backwards compatible with what it was before this change.

Resolves adafruit#6219.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rp2040 Raspberry Pi RP2040
Projects
None yet
Development

No branches or pull requests

1 participant