What resources are used by the WiFi stack? #12112
-
Hello, on the WiFi Support page, it is stated that the WiFi stack requires both flash and RAM. Does it use resources beyond that? I'm particularly interested in DMA channels and PIOs because my application uses both and I observe differences in behavior of my code with and without WiFi. As MicroPython does not support DMA, I'm using direct register access which might collide with whatever allocation scheme is used by the network stack, but I'm speculating. Any information on this would be appreciated! Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
Yes, the rp2040 uses PIO to talk to the cyw43 wifi chip. (i.e. it's not using the regular SDIO mode that we use on the other ports like the Pyboard D, rather a special SPI mode that uses a PIO).
There's no Python-level API for DMA but parts of MicroPython do use DMA (e.g. SPI). It's possible the cyw43 driver does also. A quick look at |
Beta Was this translation helpful? Give feedback.
-
@jimmo Thank you for the pointer to the cyw43 driver - It does indeed look as if both a sizeable PIO program and two DMA channels are used, and that the driver uses the I'm currently working on a project where I use both PIO blocks and interestingly, things mostly work - I had problems when trying to use state machine 0, and that is probably caused by its use in the cyw43 driver. When choosing a higher state machine number, though, things work fine - I find that surprising, given that both cyw43_bus_pio_spi.pio and my own PIO program occupy much of a PIO block's address space of 32 words. Is it possible to quickly switch between PIO programs, and that this is done by the WiFi driver? Regarding DMA, I have been observing that things work most of the time, but sometimes I get DMA transfer failures that I have no explanation for. Given that I'm statically allocating my DMA channel numbers, but the WiFi driver uses I think both problems should addressed in MicroPython by making the the PIO driver claim state machines when the user uses them and unclaiming them when usage ends. Also, it would make sense to expose the |
Beta Was this translation helpful? Give feedback.
-
For the DMA side I think a |
Beta Was this translation helpful? Give feedback.
-
@rkompass I'll try to come up with a PR to add a |
Beta Was this translation helpful? Give feedback.
-
The main-tainer of the repositoy is Damien with support by Jimmo. And yes, keeping a PR up-to-date is an ongoing work. I have no clear opinion whether a stand alone DMA class is useful or not. Usually DMA is used by the drivers for certain peripherals which embed the source & target of the transfer. Only the RP2 PIO seems one where these are exposed to Python scripts, and there it is useful. |
Beta Was this translation helpful? Give feedback.
@jimmo Thank you for the pointer to the cyw43 driver - It does indeed look as if both a sizeable PIO program and two DMA channels are used, and that the driver uses the
pio_claim_unused_sm
anddma_claim_unused_channel
to allocate its resources. Looking atrp2_pio.c
in the MicroPython code, however, I could not figure out whether it would make sure that the Python code attempts to use a state machine that is already in use by the WiFi stack (the i2s driver seems to usepio_claim_unused_sm
though).I'm currently working on a project where I use both PIO blocks and interestingly, things mostly work - I had problems when trying to use state machine 0, and that is probably caused by its use in…