|
@@ -98,6 +98,53 @@ static struct stm32_uart_config uart_config[] =
|
|
|
|
|
|
static struct stm32_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] = {0};
|
|
|
|
|
|
+rt_uint32_t stm32_uart_get_mask(rt_uint32_t word_length, rt_uint32_t parity)
|
|
|
+{
|
|
|
+ rt_uint32_t mask = 0x00FFU;
|
|
|
+ if (word_length == UART_WORDLENGTH_8B)
|
|
|
+ {
|
|
|
+ if (parity == UART_PARITY_NONE)
|
|
|
+ {
|
|
|
+ mask = 0x00FFU ;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mask = 0x007FU ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+#ifdef UART_WORDLENGTH_9B
|
|
|
+ else if (word_length == UART_WORDLENGTH_9B)
|
|
|
+ {
|
|
|
+ if (parity == UART_PARITY_NONE)
|
|
|
+ {
|
|
|
+ mask = 0x01FFU ;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mask = 0x00FFU ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+#ifdef UART_WORDLENGTH_7B
|
|
|
+ else if (word_length == UART_WORDLENGTH_7B)
|
|
|
+ {
|
|
|
+ if (parity == UART_PARITY_NONE)
|
|
|
+ {
|
|
|
+ mask = 0x007FU ;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mask = 0x003FU ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mask = 0x0000U;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ return mask;
|
|
|
+}
|
|
|
+
|
|
|
static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
|
|
|
{
|
|
|
struct stm32_uart *uart;
|
|
@@ -182,6 +229,7 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
|
|
|
{
|
|
|
return -RT_ERROR;
|
|
|
}
|
|
|
+ uart->DR_mask = stm32_uart_get_mask(uart->handle.Init.WordLength, uart->handle.Init.Parity);
|
|
|
|
|
|
return RT_EOK;
|
|
|
}
|
|
@@ -257,52 +305,7 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
|
|
|
return RT_EOK;
|
|
|
}
|
|
|
|
|
|
-rt_uint32_t stm32_uart_get_mask(rt_uint32_t word_length, rt_uint32_t parity)
|
|
|
-{
|
|
|
- rt_uint32_t mask;
|
|
|
- if (word_length == UART_WORDLENGTH_8B)
|
|
|
- {
|
|
|
- if (parity == UART_PARITY_NONE)
|
|
|
- {
|
|
|
- mask = 0x00FFU ;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mask = 0x007FU ;
|
|
|
- }
|
|
|
- }
|
|
|
-#ifdef UART_WORDLENGTH_9B
|
|
|
- else if (word_length == UART_WORDLENGTH_9B)
|
|
|
- {
|
|
|
- if (parity == UART_PARITY_NONE)
|
|
|
- {
|
|
|
- mask = 0x01FFU ;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mask = 0x00FFU ;
|
|
|
- }
|
|
|
- }
|
|
|
-#endif
|
|
|
-#ifdef UART_WORDLENGTH_7B
|
|
|
- else if (word_length == UART_WORDLENGTH_7B)
|
|
|
- {
|
|
|
- if (parity == UART_PARITY_NONE)
|
|
|
- {
|
|
|
- mask = 0x007FU ;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mask = 0x003FU ;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mask = 0x0000U;
|
|
|
- }
|
|
|
-#endif
|
|
|
- return mask;
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
static int stm32_putc(struct rt_serial_device *serial, char c)
|
|
|
{
|
|
@@ -337,9 +340,9 @@ static int stm32_getc(struct rt_serial_device *serial)
|
|
|
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L5) \
|
|
|
|| defined(SOC_SERIES_STM32G4) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB)|| defined(SOC_SERIES_STM32F3) \
|
|
|
|| defined(SOC_SERIES_STM32U5)
|
|
|
- ch = uart->handle.Instance->RDR & stm32_uart_get_mask(uart->handle.Init.WordLength, uart->handle.Init.Parity);
|
|
|
+ ch = uart->handle.Instance->RDR & uart->DR_mask;
|
|
|
#else
|
|
|
- ch = uart->handle.Instance->DR & stm32_uart_get_mask(uart->handle.Init.WordLength, uart->handle.Init.Parity);
|
|
|
+ ch = uart->handle.Instance->DR & uart->DR_mask;
|
|
|
#endif
|
|
|
}
|
|
|
return ch;
|