SerialUSB.available() is hanging
I'm currently having an issue with SerialUSB.available() hanging, but it's only under very specific circumstances and it's difficult to replicate. I'm trying to track down why this is happening.
The best details I can give about the issue is this:
- My sketch is using a lot of of the program memory (about 62%) on the SAMD21. That is 163068 bytes out of max 262144 bytes.
- There is also quite a bit of RAM usage. Upon starting the sketch, I initialize a lot of global objects that use a decent amount of memory. They use about 22920 bytes (69%) of RAM, leaving 9848 bytes for local variables.
- SerialUSB.available() works perfectly fine for the majority of the time. At one point, I am using the PubSubClient library to connect to PubNub's MQTT service. Soon after calling the "connect" function (which then call's into WiFi101's WiFiClient "connect" function), I then call SerialUSB.available() again. At this point, it hangs. Immediately before calling SerialUSB.available(), there are 3755 bytes of RAM available in between the stack and heap.
My only thought is that somehow something is corrupting the memory being used by SerialUSB, but I have no idea where to even begin looking into that. Where does SerialUSB maintain its buffer in memory? How big is it? I know I haven't given a whole lot to go off of, but any ideas where I could look based on the description I've given?
Could this be related to "Cannot receive the data when data length exactly 64 or 128 bytes" ? Assuming it's not fixed yet.
If you're transferring data using raw write() commands from the host, you could randomly be hitting data which is a multiple of 64/128 bytes.