@@ -60,6 +60,8 @@ struct can_driver_stm32_instance_s {
60
60
FDCAN_GlobalTypeDef * can ;
61
61
};
62
62
63
+ static void stm32_can_tx_handler_I (struct can_driver_stm32_instance_s * instance );
64
+
63
65
static struct can_driver_stm32_instance_s can1_instance ;
64
66
65
67
RUN_ON (CAN_INIT ) {
@@ -277,10 +279,11 @@ static void can_driver_stm32_start(void* ctx, bool silent, bool auto_retransmit,
277
279
FDCAN_IE_RF0NE | // RX FIFO 0 new message
278
280
FDCAN_IE_RF0FE | // Rx FIFO 1 FIFO Full
279
281
FDCAN_IE_RF1NE | // RX FIFO 1 new message
280
- FDCAN_IE_RF1FE ; // Rx FIFO 1 FIFO Full
281
- instance -> can -> IE |= FDCAN_IE_TCFE | (1UL <<27 ); // Transmit Canceled interrupt enable, it doubles as
282
+ FDCAN_IE_RF1FE | // Rx FIFO 1 FIFO Full
283
+ FDCAN_IE_BOE ; // bus off
284
+ instance -> can -> IE |= FDCAN_IE_TCFE | FDCAN_IE_PEAE ; // Transmit Canceled interrupt enable, it doubles as
282
285
// transmit failed in Disabled AutoRetransmission mode.
283
- instance -> can -> ILS = FDCAN_ILS_TCL | FDCAN_ILS_TCFL | ( 1UL << 27 ) ; //Set Line 1 for Transmit Complete Event Interrupt
286
+ instance -> can -> ILS = FDCAN_ILS_TCL | FDCAN_ILS_TCFL | FDCAN_ILS_PEAE | FDCAN_ILS_BOE ; //Set Line 1 for Transmit Complete Event Interrupt
284
287
instance -> can -> TXBTIE = (1 << NUM_TX_MAILBOXES ) - 1 ;
285
288
instance -> can -> ILE = 0x3 ; // Enable both interrupt handlers
286
289
@@ -418,11 +421,9 @@ static void stm32_can_rx_handler(struct can_driver_stm32_instance_s* instance) {
418
421
chSysUnlockFromISR ();
419
422
}
420
423
421
- static void stm32_can_tx_handler (struct can_driver_stm32_instance_s * instance ) {
424
+ static void stm32_can_tx_handler_I (struct can_driver_stm32_instance_s * instance ) {
422
425
systime_t t_now = chVTGetSystemTimeX ();
423
426
424
- chSysLockFromISR ();
425
-
426
427
for (uint8_t i = 0 ; i < NUM_TX_MAILBOXES ; i ++ ) {
427
428
if (instance -> tx_bits_processed & (1UL << i )) {
428
429
continue ;
@@ -442,7 +443,11 @@ static void stm32_can_tx_handler(struct can_driver_stm32_instance_s* instance) {
442
443
can_driver_tx_request_complete_I (instance -> frontend , i , false, t_now );
443
444
}
444
445
}
446
+ }
445
447
448
+ static void stm32_can_tx_handler (struct can_driver_stm32_instance_s * instance ) {
449
+ chSysLockFromISR ();
450
+ stm32_can_tx_handler_I (instance );
446
451
chSysUnlockFromISR ();
447
452
}
448
453
@@ -458,15 +463,22 @@ static void stm32_can_interrupt_handler(struct can_driver_stm32_instance_s *inst
458
463
if (instance -> can -> IR & FDCAN_IR_TC ) {
459
464
instance -> can -> IR = FDCAN_IR_TC ;
460
465
stm32_can_tx_handler (instance );
466
+
461
467
}
462
468
463
469
if (instance -> can -> IR & FDCAN_IR_TCF ) {
464
470
instance -> can -> IR = FDCAN_IR_TCF ;
465
471
stm32_can_tx_handler (instance );
466
472
}
467
473
468
- if (instance -> can -> IR & (1UL << 27 )) {
469
- instance -> can -> IR = (1UL << 27 );
474
+ if (instance -> can -> IR & FDCAN_IR_PEA ) {
475
+ instance -> can -> IR = FDCAN_IR_PEA ;
476
+ stm32_can_tx_handler (instance );
477
+ }
478
+
479
+ if (instance -> can -> IR & FDCAN_IR_BO ) {
480
+ instance -> can -> IR = FDCAN_IR_BO ;
481
+ instance -> can -> CCCR &= ~FDCAN_CCCR_INIT ;
470
482
stm32_can_tx_handler (instance );
471
483
}
472
484
}
0 commit comments