From a282faf26caa5441716adda1603120ac3a3916fb Mon Sep 17 00:00:00 2001 From: zuozuojia <2674928186@qq.com> Date: Wed, 5 Jan 2022 20:32:40 +0800 Subject: [PATCH] [bsp/stm32] fix the bug of 'can' being stucked when short cricuit the canH and canL, change some wrong annotations --- bsp/stm32/libraries/HAL_Drivers/drv_can.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_can.c b/bsp/stm32/libraries/HAL_Drivers/drv_can.c index 4e58b4015d..da3f81424f 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_can.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_can.c @@ -343,7 +343,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg) } /** * ID | CAN_FxR1[31:24] | CAN_FxR1[23:16] | CAN_FxR1[15:8] | CAN_FxR1[7:0] | - * MASK | CAN_FxR2[31:24] | CAN_FxR1[23:16] | CAN_FxR1[15:8] | CAN_FxR1[7:0] | + * MASK | CAN_FxR2[31:24] | CAN_FxR2[23:16] | CAN_FxR2[15:8] | CAN_FxR2[7:0] | * STD ID | STID[10:3] | STDID[2:0] |<- 21bit ->| * EXT ID | EXTID[28:21] | EXTID[20:13] | EXTID[12:5] | EXTID[4:0] IDE RTR 0| * @note the 32bit STD ID must << 21 to fill CAN_FxR1[31:21] and EXT ID must << 3, @@ -482,7 +482,7 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t if (HAL_IS_BIT_SET(hcan->Instance->TSR, CAN_TSR_TME0) != SET) { /* Change CAN state */ - hcan->State = HAL_CAN_STATE_ERROR; + // hcan->State = HAL_CAN_STATE_ERROR; /* Return function status */ return -RT_ERROR; } @@ -491,7 +491,7 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t if (HAL_IS_BIT_SET(hcan->Instance->TSR, CAN_TSR_TME1) != SET) { /* Change CAN state */ - hcan->State = HAL_CAN_STATE_ERROR; + // hcan->State = HAL_CAN_STATE_ERROR; /* Return function status */ return -RT_ERROR; } @@ -500,7 +500,7 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t if (HAL_IS_BIT_SET(hcan->Instance->TSR, CAN_TSR_TME2) != SET) { /* Change CAN state */ - hcan->State = HAL_CAN_STATE_ERROR; + // hcan->State = HAL_CAN_STATE_ERROR; /* Return function status */ return -RT_ERROR; } @@ -732,6 +732,10 @@ void CAN1_TX_IRQHandler(void) /* Write 0 to Clear transmission status flag RQCPx */ SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP2); } + else + { + rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 0 << 8); + } rt_interrupt_leave(); } @@ -852,6 +856,10 @@ void CAN2_TX_IRQHandler(void) /* Write 0 to Clear transmission status flag RQCPx */ SET_BIT(hcan->Instance->TSR, CAN_TSR_RQCP2); } + else + { + rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 0 << 8); + } rt_interrupt_leave(); } -- GitLab