diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2018-05-26 16:39:05 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2018-05-26 16:39:05 +0000 |
commit | d8ede4fbf03bb484d84ced5ce3a2f5c582c4e6a3 (patch) | |
tree | 00194b5ebe37b1b5bb9c06c41b4ae70cd43e2a26 /os/hal/ports/STM32/LLD/USARTv1/hal_serial_lld.c | |
parent | 1121ec7880860f4c3a71fd6d0500e815b105d329 (diff) | |
download | ChibiOS-d8ede4fbf03bb484d84ced5ce3a2f5c582c4e6a3.tar.gz ChibiOS-d8ede4fbf03bb484d84ced5ce3a2f5c582c4e6a3.tar.bz2 ChibiOS-d8ede4fbf03bb484d84ced5ce3a2f5c582c4e6a3.zip |
Fixed bug #951.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12054 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/hal/ports/STM32/LLD/USARTv1/hal_serial_lld.c')
-rw-r--r-- | os/hal/ports/STM32/LLD/USARTv1/hal_serial_lld.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/os/hal/ports/STM32/LLD/USARTv1/hal_serial_lld.c b/os/hal/ports/STM32/LLD/USARTv1/hal_serial_lld.c index 6b837356a..17d08b7a3 100644 --- a/os/hal/ports/STM32/LLD/USARTv1/hal_serial_lld.c +++ b/os/hal/ports/STM32/LLD/USARTv1/hal_serial_lld.c @@ -99,6 +99,7 @@ static const SerialConfig default_config = * @param[in] config the architecture-dependent serial driver configuration
*/
static void usart_init(SerialDriver *sdp, const SerialConfig *config) {
+ uint32_t fck;
USART_TypeDef *u = sdp->usart;
/* Baud rate setting.*/
@@ -107,9 +108,16 @@ static void usart_init(SerialDriver *sdp, const SerialConfig *config) { #else
if (sdp->usart == USART1)
#endif
- u->BRR = STM32_PCLK2 / config->speed;
+ fck = STM32_PCLK2 / config->speed;
else
- u->BRR = STM32_PCLK1 / config->speed;
+ fck = STM32_PCLK1 / config->speed;
+
+ /* Correcting USARTDIV when oversampling by 8 instead of 16.
+ Fraction is still 4 bits wide, but only lower 3 bits used.
+ Mantissa is doubled, but Fraction is left the same.*/
+ if (config->cr1 & USART_CR1_OVER8)
+ fck = ((fck & ~7) * 2) | (fck & 7);
+ u->BRR = fck;
/* Note that some bits are enforced.*/
u->CR2 = config->cr2 | USART_CR2_LBDIE;
|