rp2040: add a delay on SCK polarity change

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
Timofey Titovets 2025-05-20 04:10:52 +02:00 committed by KevinOConnor
parent b1011e3fb1
commit 14685bf77f

View File

@ -10,6 +10,7 @@
#include "internal.h" // pclock, gpio_peripheral
#include "hardware/structs/spi.h" // spi_hw_t
#include "hardware/regs/resets.h" // RESETS_RESET_SPI*_BITS
#include "board/misc.h" // timer_is_before
DECL_ENUMERATION("spi_bus", "spi0_gpio0_gpio3_gpio2", 0);
@ -115,10 +116,16 @@ spi_prepare(struct spi_config config)
spi_hw_t *spi = config.spi;
if (spi->cr0 == config.cr0 && spi->cpsr == config.cpsr)
return;
uint32_t diff = spi->cr0 ^ config.cr0;
spi->cr1 = 0;
spi->cr0 = config.cr0;
spi->cpsr = config.cpsr;
spi->cr1 = SPI_SSPCR1_SSE_BITS;
// Give time for state to update before caller changes CS pin
uint32_t end = timer_read_time() + timer_from_us(1);
if (diff & SPI_SSPCR0_SPO_BITS)
while (timer_is_before(timer_read_time(), end))
;
}
void