Skip to content

Commit b626deb

Browse files
authored
Merge pull request #2214 from xeonxu/fix_can
修复CAN驱动部分问题
2 parents d55a9cd + 52729bb commit b626deb

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

bsp/stm32f4xx-HAL/drivers/drv_can.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,16 @@ void CAN2_SCE_IRQHandler(void)
362362
*/
363363
void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan)
364364
{
365-
/* TODO Error Callback */
366-
/* Prevent unused argument(s) compilation warning */
367-
UNUSED(hcan);
368-
/* NOTE : This function Should not be modified, when the callback is needed,
369-
the HAL_CAN_ErrorCallback could be implemented in the user file
370-
*/
365+
__HAL_CAN_ENABLE_IT(hcan, CAN_IT_EWG |
366+
CAN_IT_EPV |
367+
CAN_IT_BOF |
368+
CAN_IT_LEC |
369+
CAN_IT_ERR |
370+
CAN_IT_FMP0|
371+
CAN_IT_FOV0|
372+
CAN_IT_FMP1|
373+
CAN_IT_FOV1|
374+
CAN_IT_TME);
371375
}
372376

373377
/**

components/drivers/can/can.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
405405

406406
rt_free(rx_fifo);
407407
dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX;
408+
can->can_rx = RT_NULL;
408409
/* configure low level device */
409410
can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
410411
}
@@ -418,6 +419,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
418419

419420
rt_free(tx_fifo);
420421
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
422+
can->can_tx = RT_NULL;
421423
/* configure low level device */
422424
can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_TX);
423425
}

0 commit comments

Comments
 (0)