diff options
| author | Jonathan Hogg <me@jonathanhogg.com> | 2021-07-12 11:35:25 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-07-16 23:05:30 +1000 |
| commit | eb3029c6697007eac7a76a8bd34452cedbd2c526 (patch) | |
| tree | e048e4dc73128e0e2bbb8ad981f062cdb0964484 | |
| parent | 98c5703027e7db9a030f747f4dd1684407230656 (diff) | |
esp32/machine_spi: Calculate actual attained baudrate.
Calculate the actual baudrate that the hardware is capable of achieving
and remember it so that printing the SPI object will show this. Fixes
#7530.
| -rw-r--r-- | ports/esp32/machine_hw_spi.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c index 98c0abaef..2792216cc 100644 --- a/ports/esp32/machine_hw_spi.c +++ b/ports/esp32/machine_hw_spi.c @@ -144,9 +144,13 @@ STATIC void machine_hw_spi_init_internal( changed = true; } - if (baudrate != -1 && baudrate != self->baudrate) { - self->baudrate = baudrate; - changed = true; + if (baudrate != -1) { + // calculate the actual clock frequency that the SPI peripheral can produce + baudrate = spi_get_actual_clock(APB_CLK_FREQ, baudrate, 0); + if (baudrate != self->baudrate) { + self->baudrate = baudrate; + changed = true; + } } if (polarity != -1 && polarity != self->polarity) { |
