raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.81k stars 955 forks source link

Communication with cyw43 fails at system clock speeds <= 60MHz #1392

Closed MichaelBell closed 3 months ago

MichaelBell commented 1 year ago

It's sometimes useful to run the RP2040 quite slowly to reduce power consumption. I'm not sure whether it is reasonable to expect Wifi to continue to work at low clock speeds - but I think it is reasonable to at least expect to be able to use the CYW43 GPIO.

However, at around 60MHz and below setting/reading the GPIO from the CYW43 doesn't work. This means you can't determine whether VBUS is present, and can't control the LED.

A simple repro is to add set_sys_clock_48mhz() to the top of the pico_w blink example.

index 149b477..600e2a2 100644
--- a/pico_w/wifi/blink/picow_blink.c
+++ b/pico_w/wifi/blink/picow_blink.c
@@ -8,6 +8,7 @@
 #include "pico/cyw43_arch.h"

 int main() {
+    set_sys_clock_48mhz();
     stdio_init_all();
     if (cyw43_arch_init()) {
         printf("Wi-Fi init failed");
mvds00 commented 1 year ago

WiFi works flawlessly for us with the Pi Pico running at 12 MHz from xosc. Set clock divider at 1 and spi program spi_gap01_sample0. Running at 48 MHz (to enable USB stdio) clock divider 2 and spi program spi_gap0_sample1 can be used, IIRC.

peterharperuk commented 3 months ago

I seem to be able to be able to use cyw43 to flash the led when running from xosc by calling the new function cyw43_set_pio_clock_divisor(1, 0). I didn't seem to have to set CYW43_SPI_PROGRAM_NAME? Anyway - I think this is resolved now as you shouldn't have to hack the code?