Browse Source

stm32/spi: Round up prescaler calc to never exceed requested baudrate.

Requesting a baudrate of X should never configure the peripheral to have a
baudrate greater than X because connected hardware may not be able to
handle higher speeds.  This patch makes sure to round the prescaler up so
that the actual baudrate is rounded down.
pull/4045/merge
Damien George 6 years ago
parent
commit
86e0b25532
  1. 2
      ports/stm32/spi.c

2
ports/stm32/spi.c

@ -214,7 +214,7 @@ STATIC void spi_set_params(const spi_t *spi_obj, uint32_t prescale, int32_t baud
spi_clock = HAL_RCC_GetPCLK2Freq();
}
#endif
prescale = spi_clock / baudrate;
prescale = (spi_clock + baudrate - 1) / baudrate;
}
if (prescale <= 2) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; }
else if (prescale <= 4) { init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; }

Loading…
Cancel
Save