stm32/uart: Fix LPUART1 baudrate set/get.

It needs to use a different function because the formula to compute the
baudrate on LPUART1 is different to a normal UART.

Fixes issue #7466.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-07-26 13:03:42 +10:00
parent ee49ae8f82
commit fef2114404
5 changed files with 23 additions and 0 deletions

View File

@ -54,6 +54,7 @@
#include "stm32h7xx_hal_usart.h"
#include "stm32h7xx_hal_wwdg.h"
#include "stm32h7xx_ll_adc.h"
#include "stm32h7xx_ll_lpuart.h"
#include "stm32h7xx_ll_pwr.h"
#include "stm32h7xx_ll_rtc.h"
#include "stm32h7xx_ll_usart.h"

View File

@ -47,6 +47,7 @@
#include "stm32l0xx_hal_usart.h"
#include "stm32l0xx_hal_wwdg.h"
#include "stm32l0xx_ll_adc.h"
#include "stm32l0xx_ll_lpuart.h"
#include "stm32l0xx_ll_rtc.h"
#include "stm32l0xx_ll_usart.h"

View File

@ -51,6 +51,7 @@
#include "stm32l4xx_hal_usart.h"
#include "stm32l4xx_hal_wwdg.h"
#include "stm32l4xx_ll_adc.h"
#include "stm32l4xx_ll_lpuart.h"
#include "stm32l4xx_ll_rtc.h"
#include "stm32l4xx_ll_usart.h"

View File

@ -42,6 +42,7 @@
#include "stm32wbxx_hal_uart.h"
#include "stm32wbxx_hal_usart.h"
#include "stm32wbxx_ll_adc.h"
#include "stm32wbxx_ll_lpuart.h"
#include "stm32wbxx_ll_rtc.h"
#include "stm32wbxx_ll_usart.h"

View File

@ -746,6 +746,15 @@ uint32_t uart_get_source_freq(pyb_uart_obj_t *self) {
}
uint32_t uart_get_baudrate(pyb_uart_obj_t *self) {
#if defined(LPUART1)
if (self->uart_id == PYB_LPUART_1) {
return LL_LPUART_GetBaudRate(self->uartx, uart_get_source_freq(self)
#if defined(STM32H7) || defined(STM32WB)
, self->uartx->PRESC
#endif
);
}
#endif
return LL_USART_GetBaudRate(self->uartx, uart_get_source_freq(self),
#if defined(STM32H7) || defined(STM32WB)
self->uartx->PRESC,
@ -754,6 +763,16 @@ uint32_t uart_get_baudrate(pyb_uart_obj_t *self) {
}
void uart_set_baudrate(pyb_uart_obj_t *self, uint32_t baudrate) {
#if defined(LPUART1)
if (self->uart_id == PYB_LPUART_1) {
LL_LPUART_SetBaudRate(self->uartx, uart_get_source_freq(self),
#if defined(STM32H7) || defined(STM32WB)
LL_LPUART_PRESCALER_DIV1,
#endif
baudrate);
return;
}
#endif
LL_USART_SetBaudRate(self->uartx, uart_get_source_freq(self),
#if defined(STM32H7) || defined(STM32WB)
LL_USART_PRESCALER_DIV1,