[stm32]uart v1 加入 err_count
This commit is contained in:
parent
7b8e806e3a
commit
665b2346a8
@ -367,6 +367,12 @@ static rt_size_t stm32_dma_transmit(struct rt_serial_device *serial, rt_uint8_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct err_count
|
||||
{
|
||||
rt_uint32_t count:16;
|
||||
rt_uint32_t error_count:16;
|
||||
} uart_err_count_t;
|
||||
|
||||
/**
|
||||
* Uart common interrupt process. This need add to uart ISR.
|
||||
*
|
||||
@ -375,6 +381,7 @@ static rt_size_t stm32_dma_transmit(struct rt_serial_device *serial, rt_uint8_t
|
||||
static void uart_isr(struct rt_serial_device *serial)
|
||||
{
|
||||
struct stm32_uart *uart;
|
||||
rt_bool_t err_flag = RT_FALSE;
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
rt_size_t recv_total_index, recv_len;
|
||||
rt_base_t level;
|
||||
@ -383,6 +390,7 @@ static void uart_isr(struct rt_serial_device *serial)
|
||||
RT_ASSERT(serial != RT_NULL);
|
||||
uart = rt_container_of(serial, struct stm32_uart, serial);
|
||||
|
||||
err_flag = (&(uart->handle))->Instance->SR & (UART_FLAG_NE | UART_FLAG_FE | UART_FLAG_PE);
|
||||
/* UART in mode Receiver -------------------------------------------------*/
|
||||
if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) &&
|
||||
(__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_RXNE) != RESET))
|
||||
@ -423,15 +431,17 @@ static void uart_isr(struct rt_serial_device *serial)
|
||||
}
|
||||
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_NE) != RESET)
|
||||
{
|
||||
err_flag = RT_TRUE;
|
||||
__HAL_UART_CLEAR_NEFLAG(&uart->handle);
|
||||
}
|
||||
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_FE) != RESET)
|
||||
{
|
||||
uart->serial.config.reserved = 1;
|
||||
err_flag = RT_TRUE;
|
||||
__HAL_UART_CLEAR_FEFLAG(&uart->handle);
|
||||
}
|
||||
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_PE) != RESET)
|
||||
{
|
||||
err_flag = RT_TRUE;
|
||||
__HAL_UART_CLEAR_PEFLAG(&uart->handle);
|
||||
}
|
||||
#if !defined(SOC_SERIES_STM32L4) && !defined(SOC_SERIES_STM32WL) && !defined(SOC_SERIES_STM32F7) && !defined(SOC_SERIES_STM32F0) \
|
||||
@ -467,6 +477,14 @@ static void uart_isr(struct rt_serial_device *serial)
|
||||
UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_RXNE);
|
||||
}
|
||||
}
|
||||
|
||||
uart_err_count_t *err_count = &uart->serial.parent.user_data;
|
||||
err_count->count++;
|
||||
if (err_flag)
|
||||
{
|
||||
err_count->error_count++;
|
||||
__HAL_UART_CLEAR_PEFLAG(&uart->handle);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
|
Loading…
x
Reference in New Issue
Block a user