Skip to content

Commit

Permalink
stm32/spi: Round up prescaler calc to never exceed requested baudrate.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dpgeorge committed Aug 10, 2018
1 parent ca0d78c commit 86e0b25
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ports/stm32/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 86e0b25

Please sign in to comment.