Browse Source

[bsp/stm32] fix the bug of 'can' being stucked when short cricuit the canH and canL, change some wrong annotations

zuozuojia 3 years ago
parent
commit
a282faf26c
1 changed files with 12 additions and 4 deletions
  1. 12 4
      bsp/stm32/libraries/HAL_Drivers/drv_can.c

+ 12 - 4
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();
 }