From 3e7580dc7dacd57f93c5375d238534731c5817a1 Mon Sep 17 00:00:00 2001 From: zhangjun1996 <2281979437@qq.com> Date: Sat, 15 Jun 2019 18:08:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E9=85=8D=E7=BD=AECAN?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=EF=BC=8C=E5=85=B3=E9=97=ADCAN=EF=BC=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=AE=8C=E5=86=8D=E6=89=93=E5=BC=80=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_can.c | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_can.c b/bsp/stm32/libraries/HAL_Drivers/drv_can.c index 2a48985c43..5f5feb268a 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_can.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_can.c @@ -806,10 +806,18 @@ static rt_err_t drv_control(struct rt_can_device *can, int cmd, void *arg) if (argval != can->config.mode) { can->config.mode = argval; + if (HAL_CAN_Stop(&drv_can->CanHandle) != HAL_OK) + { + return RT_ERROR; + } if (HAL_CAN_Init(&drv_can->CanHandle) != HAL_OK) { return RT_ERROR; } + if (HAL_CAN_Start(&drv_can->CanHandle) != HAL_OK) + { + return RT_ERROR; + } } break; case RT_CAN_CMD_SET_BAUD: @@ -844,10 +852,18 @@ static rt_err_t drv_control(struct rt_can_device *can, int cmd, void *arg) drv_init->TimeSeg2 = BAUD_DATA(BS2, baud_index); drv_init->Prescaler = BAUD_DATA(RRESCL, baud_index); + if (HAL_CAN_Stop(&drv_can->CanHandle) != HAL_OK) + { + return RT_ERROR; + } if (HAL_CAN_Init(&drv_can->CanHandle) != HAL_OK) { return RT_ERROR; } + if (HAL_CAN_Start(&drv_can->CanHandle) != HAL_OK) + { + return RT_ERROR; + } } break; case RT_CAN_CMD_SET_PRIV: @@ -860,10 +876,18 @@ static rt_err_t drv_control(struct rt_can_device *can, int cmd, void *arg) if (argval != can->config.privmode) { can->config.privmode = argval; + if (HAL_CAN_Stop(&drv_can->CanHandle) != HAL_OK) + { + return RT_ERROR; + } if (HAL_CAN_Init(&drv_can->CanHandle) != HAL_OK) { return RT_ERROR; } + if (HAL_CAN_Start(&drv_can->CanHandle) != HAL_OK) + { + return RT_ERROR; + } } break; case RT_CAN_CMD_GET_STATUS: