H7: fix lockup on disconnected bus (#1410)

* fix h7 lockup

* love MISRA!

* EW and EP isn't actual errors
This commit is contained in:
Igor Biletskyy
2023-05-12 19:20:42 -07:00
committed by GitHub
parent 822a7367c1
commit 03435947bb
2 changed files with 10 additions and 4 deletions

View File

@@ -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();
}

View File

@@ -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);
}