stm32/can: Refactor can.h API to not depend on pyboard can types.

This is necessary for the machine.CAN implementation to use the same
low-level functions.

Includes some refactoring around FIFO selection as there was a footgun
where CAN_FIFO0/1 are 0/1 but FDCAN_RX_FIFO0/1 are not. Added an explicit
type for non-hardware-specific FIFO numbering.

Also moved responsibility for re-enabling CAN receive interrupts into the
higher layer (pyb_can.c layer) after calling can_receive().

Also includes this behaviour change for FDCAN boards:

- Fix for boards with FDCAN not updating error status
  counters (num_error_warning, num_error_passive, num_bus_off). These are
  now updated the same as on boards with CAN Classic controllers, as
  documented.

- Previously FDCAN boards would trigger the RX callback function on error
  events instead (passing undocumented irq numbers 3, 4, 5).
  This behaviour has been removed in favour of the documented behaviour of
  updating the status counters.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
Angus Gratton
2024-10-09 15:55:46 +11:00
committed by Damien George
parent 96ce08e498
commit 9db2398009
7 changed files with 430 additions and 361 deletions

View File

@@ -86,7 +86,7 @@
#include "accel.h"
#include "servo.h"
#include "dac.h"
#include "can.h"
#include "pyb_can.h"
#include "subghz.h"
#if MICROPY_PY_THREAD
@@ -536,7 +536,7 @@ soft_reset:
timer_init0();
#if MICROPY_HW_ENABLE_CAN
can_init0();
pyb_can_init0();
#endif
#if MICROPY_HW_ENABLE_USB
@@ -683,7 +683,7 @@ soft_reset_exit:
pyb_i2c_deinit_all();
#endif
#if MICROPY_HW_ENABLE_CAN
can_deinit_all();
pyb_can_deinit_all();
#endif
#if MICROPY_HW_ENABLE_DAC
dac_deinit_all();