-
Notifications
You must be signed in to change notification settings - Fork 1.3k
usb_cdc.data on Macropad RP2040 #7456
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
Comments
I reproduced the issue on the pico, but there is a twist, the A burst of data like this adds the data to the buffer, and triggers a read or two.
|
@mscreations Does your experience match what @Neradoc reported? How are you sending characters on the host computer side? I will do a bisect and track this down. |
Here is the script I'm using to send data to the macro pad. https://github.com/mscreations/CircuitPython_Macropad/blob/master/Macropad.ps1 |
This new behavior is caused by #7100, which fixed a worse problem: #6018: if an attempt was made to read from a CDC device when USB was not (yet) connected, TinyUSB could read from the wrong endpoint and everything would crash. I noticed this because when I enabled @mscreations It appears your host computer script may write and then disconnect immediately. Can you confirm that? That's what @Neradoc is simulating by writing to the port from the command line. The write sends the characters down, and then immediately disconnects. CircuitPython reads one character, and then TinyUSB notices the disconnect, and then we won't return any more characters, because we notice we are disconnected. Can you wait long enough before you disconnect for the write to complete and the RP2040 to finish reading what was sent? Perhaps the MacroPad should send some kind of acknowledgment back to your script. When TinyUSB notices the disconnect, it resets the connection information. The fact that it used to be possible to read the rest of the buffered characters may have been an accident. |
The script I use to send data to the macropad does not close the serial port immediately after writing. It only closes the port if the script exits abnormally or on Ctrl+C. I did find something else which is that the device is not seeing that the serial port has a connection when I connect using my script. I added in a line to skip getting serial input if the port is not connected (eg usb_cdc.data.connected). This at least allows the device to not throw an exception or sit waiting indefinitely for input. It also doesn't seem to see when I use the application from https://github.com/xhargh/MacropadApplicationDetector. HOWEVER, if I connect using putty, the device recognizes that it is connected and works the way I'm expecting. So that makes me wonder what Putty does differently when opening the serial port to allow the device to recognize it's connected. |
@mscreations You can check whether TinyUSB thinks it is still connected by doing Note also this interesting note, which I had forgotten about, in our documentation:
Perhaps your ps1 script and the https://github.com/xhargh/MacropadApplicationDetector app are not setting |
Bingo. I was just coming back to report that all the code I've tried and used isn't asserting DtrEnable by default. Once I did that my code runs perfectly (well mostly. still have some code bugs from new v8 changes unrelated to this serial issue.) I am going to close this as it is resolved as far as I'm concerned. |
That's fantastic, thanks for the follow-up! |
Original issue which caused us to add the documentation note: #4345 |
I still think that the fact that |
@Neradoc -- these are good questions. I agree that we shouldn't have I think @hathach might have an opinion here about what the semantics should be. But it may require TinyUSB changes. For now, we could not return |
I tried remembering whether there ever was a connection using a boolean that was set and remained set even if the connection went away. Confusingly, this did not work, and I could not read characters, even though the code change was very simple. I spent a while trying to track down what was going on, but it wasn't clear. I'm going to give up on this for now. |
CircuitPython version
Code/REPL
Behavior
usb_cdc.data.read(1)
times out (time is printed out > 5.0 seconds every time) and no data is read.Description
When I'm trying to utilize the usb_cdc.data serial, the data.read times out rather than reading the data that is in the buffer. My testing involved, installing the version of circuit python under test, erasing the filesystem, and then changing boot.py and code.py to my test case, so it should not be remnant of old code. I have also verified this issue on multiple macro pad devices.
Additional information
I've verified this issue can be reproduced on the versions listed above. The last version that this same code works on is 8.0.0-beta.3.
The text was updated successfully, but these errors were encountered: