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.
This commit is contained in:
parent
ca0d78cebb
commit
86e0b25532
|
@ -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…
Reference in New Issue