mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-23 04:08:57 +08:00
fix:[CAN][STM32]open时立刻启动can_start,还未完成其他配置,可能导致异常
This commit is contained in:
parent
ea5f58c668
commit
6bdaaf47c3
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@ -174,8 +174,6 @@ static rt_err_t _can_config(struct rt_can_device *can, struct can_configure *cfg
|
||||
|
||||
/* default filter config */
|
||||
HAL_CAN_ConfigFilter(&drv_can->CanHandle, &drv_can->FilterConfig);
|
||||
/* can start */
|
||||
HAL_CAN_Start(&drv_can->CanHandle);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@ -321,7 +319,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
rt_uint32_t id_l = 0;
|
||||
rt_uint32_t mask_h = 0;
|
||||
rt_uint32_t mask_l = 0;
|
||||
rt_uint32_t mask_l_tail = 0; //CAN_FxR2 bit [2:0]
|
||||
rt_uint32_t mask_l_tail = 0; /*CAN_FxR2 bit [2:0]*/
|
||||
|
||||
if (RT_NULL == arg)
|
||||
{
|
||||
@ -458,7 +456,6 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
}
|
||||
break;
|
||||
case RT_CAN_CMD_GET_STATUS:
|
||||
{
|
||||
rt_uint32_t errtype;
|
||||
errtype = drv_can->CanHandle.Instance->ESR;
|
||||
drv_can->device.status.rcverrcnt = errtype >> 24;
|
||||
@ -467,8 +464,19 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
drv_can->device.status.errcode = errtype & 0x07;
|
||||
|
||||
rt_memcpy(arg, &drv_can->device.status, sizeof(drv_can->device.status));
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case RT_CAN_CMD_START:
|
||||
argval = (rt_uint32_t) arg;
|
||||
if (argval == 0)
|
||||
{
|
||||
HAL_CAN_Stop(&drv_can->CanHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_CAN_Start(&drv_can->CanHandle);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@ -435,7 +435,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
|
||||
}
|
||||
|
||||
can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_CAN_INT_ERR);
|
||||
|
||||
can->ops->control(can, RT_CAN_CMD_START, RT_FALSE);
|
||||
CAN_UNLOCK(can);
|
||||
|
||||
return RT_EOK;
|
||||
|
@ -111,7 +111,8 @@ enum CANBAUD
|
||||
* res = rt_device_control(can_dev, RT_CAN_CMD_SET_FILTER, &cfg);
|
||||
* RT_ASSERT(res == RT_EOK);
|
||||
* #endif
|
||||
*
|
||||
* res = RT_TRUE;
|
||||
* res = rt_device_control(can_dev, RT_CAN_CMD_START, &res);
|
||||
* while (1)
|
||||
* {
|
||||
* // hdr 值为 - 1,表示直接从 uselist 链表读取数据
|
||||
@ -345,6 +346,7 @@ struct rt_can_ops;
|
||||
#define RT_CAN_CMD_SET_CANFD 0x1A
|
||||
#define RT_CAN_CMD_SET_BAUD_FD 0x1B
|
||||
#define RT_CAN_CMD_SET_BITTIMING 0x1C
|
||||
#define RT_CAN_CMD_START 0x1D
|
||||
|
||||
#define RT_DEVICE_CAN_INT_ERR 0x1000
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user