Closed dehne closed 3 months ago
The LED on the PicoW is driven by the WiFi chip and controlled via SPI messages from the Pico to the CYW. My guess is that you are causing re-entrancy in the SPI. Basically there's one SPI going on to the CYW for some operation and in the middle you start another one. So everyone gets confused and I'd be surprised if the CYW or Pico can recover comms after that. You could also be breaking internal state for the WiFi chip driver in doing so.
If you disable the LED flash, or flash an external LED on some other real GPIO pin, I bet this won't happen. Can you give it a go (increment some global counter or something instead to verify your periodic calls are happening)?
(Also, I have a strong suspicion that your busywait for
loop will be optimized completely away. You can try adding a memory barrier or incrementing that global value mentioned above to disallow that optimization.)
In net, it's illegal to do a write to LED_BUILTIN on the PicoW from an interrupt. Regular Picos, LED_BUILTIN is a simple GPIO and it is fine to do.
Many thanks for your quick response; I'm sure your diagnosis is correct. This issue can be closed.
In the code I'm actually building (as opposed to the demonstration code), using an external LED is exactly what I do, and, of course, there's no problem.
(And, yes, you're probably right that the compiler has probably optimized the busy-wait loop away.)
The code below demonstrates what appears to be a problem in Arduino-Pico. In particular, with unexpected behavior when simultaneously using WiFi, the Raspberry Pi Pico W's "repeating timer" functionality and the built-in LED used inside the repeating timer callback function.
I can run with WiFi and a repeating timer callback so long as I don't use the built-in LED from inside the repeating timer callback. It will run for many hours without reporting a problem. Similarly, I can run just fine using the built-in LED in the repeating timer callback so long as WiFi is not connected. But if I connect to WiFi and use the built-in LED from inside the repeating timer callback, at some point the Pico seems to start spending a lot of time in code that's not mine. This doesn't happen immediately, sometimes in a few minutes, sometimes longer, but -- so far -- always less than 30 mins.
I haven't tried using the WiFi and the built-in LED without the repeating timer. (I'm guessing that's been done by lots of people and works okay.)
Am I missing something?