Skip to content

Commit ea32e6d

Browse files
committed
Fix unreliable writes to cyw43.
We use a pio and dma to write to the cyw43 chip using spi. Normally you write an address and then read the data from that address, so the pio program does does a write then read. If you just want to write data in the case of uploading firmware we use the fdebug_tx_stall flag to work out if the pio has stalled waiting to write more data. The theory is that this flag will also get set if the bus is busy. So we mistakenly think a write to cyw43 has completed. Wait for the dma write to complete before waiting for the pio to stall. Fixes raspberrypi#2206
1 parent c54475d commit ea32e6d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,13 @@ int cyw43_spi_transfer(cyw43_int_t *self, const uint8_t *tx, size_t tx_length, u
308308

309309
dma_channel_configure(bus_data->dma_out, &out_config, &bus_data->pio->txf[bus_data->pio_sm], tx, tx_length / 4, true);
310310

311+
pio_sm_set_enabled(bus_data->pio, bus_data->pio_sm, true);
312+
dma_channel_wait_for_finish_blocking(bus_data->dma_out);
313+
311314
uint32_t fdebug_tx_stall = 1u << (PIO_FDEBUG_TXSTALL_LSB + bus_data->pio_sm);
312315
bus_data->pio->fdebug = fdebug_tx_stall;
313-
pio_sm_set_enabled(bus_data->pio, bus_data->pio_sm, true);
314316
while (!(bus_data->pio->fdebug & fdebug_tx_stall)) {
315-
tight_loop_contents(); // todo timeout
317+
tight_loop_contents();
316318
}
317319
__compiler_memory_barrier();
318320
pio_sm_set_enabled(bus_data->pio, bus_data->pio_sm, false);

0 commit comments

Comments
 (0)