From 03435947bb249dc3ea7338300db5196877ff1b8d Mon Sep 17 00:00:00 2001 From: Igor Biletskyy Date: Fri, 12 May 2023 19:20:42 -0700 Subject: [PATCH] H7: fix lockup on disconnected bus (#1410) * fix h7 lockup * love MISRA! * EW and EP isn't actual errors --- board/drivers/fdcan.h | 7 ++++++- board/stm32h7/llfdcan.h | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/board/drivers/fdcan.h b/board/drivers/fdcan.h index 4dcc3fdf4..706f49439 100644 --- a/board/drivers/fdcan.h +++ b/board/drivers/fdcan.h @@ -64,7 +64,12 @@ void update_can_health_pkt(uint8_t can_number, bool error_irq) { if ((CANx->IR & (FDCAN_IR_TEFL)) != 0) { can_health[can_number].total_tx_lost_cnt += 1U; } - llcan_clear_send(CANx); + // Actually reset can core only on arbitration or data phase errors + if ((CANx->IR & (FDCAN_IR_PED | FDCAN_IR_PEA)) != 0) { + llcan_clear_send(CANx); + } + // Clear error interrupts + CANx->IR |= (FDCAN_IR_PED | FDCAN_IR_PEA | FDCAN_IR_EW | FDCAN_IR_EP | FDCAN_IR_ELO | FDCAN_IR_BO | FDCAN_IR_TEFL | FDCAN_IR_RF0L); } EXIT_CRITICAL(); } diff --git a/board/stm32h7/llfdcan.h b/board/stm32h7/llfdcan.h index e5791fc52..311c6ae9b 100644 --- a/board/stm32h7/llfdcan.h +++ b/board/stm32h7/llfdcan.h @@ -244,7 +244,8 @@ bool llcan_init(FDCAN_GlobalTypeDef *CANx) { } void llcan_clear_send(FDCAN_GlobalTypeDef *CANx) { - CANx->TXBCR = 0xFFFFU; // Abort message transmission on error interrupt - // Clear error interrupts - CANx->IR |= (FDCAN_IR_PED | FDCAN_IR_PEA | FDCAN_IR_EW | FDCAN_IR_EP | FDCAN_IR_ELO | FDCAN_IR_BO | FDCAN_IR_TEFL | FDCAN_IR_RF0L); + // from datasheet: "Transmit cancellation is not intended for Tx FIFO operation." + // so we need to clear pending transmission manually by resetting FDCAN core + bool ret = llcan_init(CANx); + UNUSED(ret); }