aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2018-08-10 16:39:47 +1000
committerDamien George2018-08-10 16:39:47 +1000
commit86e0b2553288bf40a22e1e91d161c075295dd4a7 (patch)
treec4ed5fca5ca31b9d9d80202ed0f33fbeb1eb5ad9
parentca0d78cebb20ed67f78491a68b02272aba2ecd13 (diff)
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.
-rw-r--r--ports/stm32/spi.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c
index 7e9864bbc..1aa8d666f 100644
--- a/ports/stm32/spi.c
+++ b/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; }