mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-02 14:23:19 +08:00
feat[STM32][USART]: add uart error callback support
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
add a control command to register a per-device uart error callback invoke the callback from the HAL uart error hook and clear it before close return -RT_ENOSYS when dma mode is requested without dma support propagate the set-int fallback result in optmode setup to keep control return values explicit
This commit is contained in:
@@ -280,25 +280,39 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
|
||||
{
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
stm32_dma_config(serial, ctrl_arg);
|
||||
#else
|
||||
return -RT_ENOSYS;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
stm32_control(serial, RT_DEVICE_CTRL_SET_INT, (void *)ctrl_arg);
|
||||
{
|
||||
return stm32_control(serial, RT_DEVICE_CTRL_SET_INT, (void *)ctrl_arg);
|
||||
}
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CHECK_OPTMODE: {
|
||||
case RT_DEVICE_CHECK_OPTMODE:
|
||||
{
|
||||
if (ctrl_arg & RT_DEVICE_FLAG_DMA_TX)
|
||||
return RT_SERIAL_TX_BLOCKING_NO_BUFFER;
|
||||
else
|
||||
return RT_SERIAL_TX_BLOCKING_BUFFER;
|
||||
}
|
||||
case RT_DEVICE_CTRL_CLOSE:
|
||||
{
|
||||
uart->error_indicate = RT_NULL;
|
||||
if (HAL_UART_DeInit(&(uart->handle)) != HAL_OK)
|
||||
{
|
||||
RT_ASSERT(0)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UART_CTRL_SET_ERROR_CALLBACK:
|
||||
{
|
||||
uart->error_indicate = (rt_err_t (*)(rt_device_t dev, rt_uint32_t error_code))arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
@@ -1242,6 +1256,10 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
||||
struct stm32_uart *uart = (struct stm32_uart *)huart;
|
||||
LOG_D("%s: %s %d\n", __FUNCTION__, uart->config->name, huart->ErrorCode);
|
||||
UNUSED(uart);
|
||||
if(uart->error_indicate != RT_NULL)
|
||||
{
|
||||
uart->error_indicate(&uart->serial.parent, huart->ErrorCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1304,12 +1322,13 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
#endif /* RT_SERIAL_USING_DMA */
|
||||
|
||||
static const struct rt_uart_ops stm32_uart_ops =
|
||||
{
|
||||
.configure = stm32_configure,
|
||||
.control = stm32_control,
|
||||
.putc = stm32_putc,
|
||||
.getc = stm32_getc,
|
||||
.transmit = stm32_transmit};
|
||||
{
|
||||
.configure = stm32_configure,
|
||||
.control = stm32_control,
|
||||
.putc = stm32_putc,
|
||||
.getc = stm32_getc,
|
||||
.transmit = stm32_transmit
|
||||
};
|
||||
|
||||
int rt_hw_usart_init(void)
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ int rt_hw_usart_init(void);
|
||||
#define UART_RX_DMA_IT_HT_FLAG 0x01
|
||||
#define UART_RX_DMA_IT_TC_FLAG 0x02
|
||||
|
||||
#define UART_CTRL_SET_ERROR_CALLBACK 0x100
|
||||
|
||||
/* stm32 config class */
|
||||
struct stm32_uart_config
|
||||
@@ -66,7 +67,8 @@ struct stm32_uart
|
||||
{
|
||||
UART_HandleTypeDef handle;
|
||||
struct stm32_uart_config *config;
|
||||
|
||||
/* device call back */
|
||||
rt_err_t (*error_indicate)(rt_device_t dev, rt_uint32_t error_code);
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
struct
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user