Skip to content

Commit

Permalink
ensure message is sent again on NACK
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Mar 27, 2024
1 parent 567dbfe commit d1fc60b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
CANx->RF0R &= ~(CAN_RF0R_FOVR0);
}
can_health[can_number].can_core_reset_cnt += 1U;
llcan_clear_send(CANx);
llcan_clear_send(CANx, can_health[can_number].last_error != 3U);
}
}

Expand Down
2 changes: 1 addition & 1 deletion board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
((ir_reg & FDCAN_IR_BO) != 0)) {
can_health[can_number].can_core_reset_cnt += 1U;
can_health[can_number].total_tx_lost_cnt += (FDCAN_TX_FIFO_EL_CNT - (FDCANx->TXFQS & FDCAN_TXFQS_TFFL)); // TX FIFO msgs will be lost after reset
llcan_clear_send(FDCANx);
llcan_clear_send(FDCANx, true);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions board/stm32f4/llbxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ bool llcan_init(CAN_TypeDef *CANx) {
return ret;
}

void llcan_clear_send(CAN_TypeDef *CANx) {
CANx->TSR |= CAN_TSR_ABRQ0; // Abort message transmission on error interrupt
void llcan_clear_send(CAN_TypeDef *CANx, bool abort) {
if (abort) {
CANx->TSR |= CAN_TSR_ABRQ0; // Abort message transmission on error interrupt
}
CANx->MSR |= CAN_MSR_ERRI; // Clear error interrupt
}
8 changes: 5 additions & 3 deletions board/stm32h7/llfdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,12 @@ bool llcan_init(FDCAN_GlobalTypeDef *FDCANx) {
return ret;
}

void llcan_clear_send(FDCAN_GlobalTypeDef *FDCANx) {
void llcan_clear_send(FDCAN_GlobalTypeDef *FDCANx, bool abort) {
// from datasheet: "Transmit cancellation is not intended for Tx FIFO operation."
// so we need to clear pending transmission manually by resetting FDCAN core
FDCANx->IR |= 0x3FCFFFFFU; // clear all interrupts
bool ret = llcan_init(FDCANx);
UNUSED(ret);
if (abort) {
bool ret = llcan_init(FDCANx);
UNUSED(ret);
}
}

0 comments on commit d1fc60b

Please sign in to comment.