Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions bsp/stm32/libraries/HAL_Drivers/drivers/drv_can.c
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions components/drivers/can/dev_can.c
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion components/drivers/include/drivers/dev_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 链表读取数据
Expand Down Expand Up @@ -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

Expand Down
Loading