NUCLEO_G0B1RE fails to build if CAN is enabled
Port, board and/or hardware
NUCLEO_G0B1RE
MicroPython version
v1.26.1
Reproduction
make BOARD=NUCLEO_G0B1RE -j20
with
#define MICROPY_HW_CAN1_TX (pin_D1)
#define MICROPY_HW_CAN1_RX (pin_D0)
in mpconfigboard.h
Expected behaviour
Successful build
Observed behaviour
In file included from ../../py/mpstate.h:35,
from ../../py/runtime.h:29,
from pin.c:27:
build-NUCLEO_G0B1RE/genhdr/pins_af_const.h:60:49: error: 'GPIO_AF3_CAN1' undeclared here (not in a function); did you mean 'GPIO_AF3_FDCAN1'?
60 | { MP_ROM_QSTR(MP_QSTR_AF3_CAN1), MP_ROM_INT(GPIO_AF3_CAN1) },
| ^~~~~~~~~~~~~
../../py/obj.h:90:67: note: in definition of macro 'MP_OBJ_NEW_SMALL_INT'
90 | #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
| ^~~~~~~~~
build-NUCLEO_G0B1RE/genhdr/pins_af_const.h:60:38: note: in expansion of macro 'MP_ROM_INT'
60 | { MP_ROM_QSTR(MP_QSTR_AF3_CAN1), MP_ROM_INT(GPIO_AF3_CAN1) },
| ^~~~~~~~~~
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
CC eth_phy.c
make: *** [../../py/mkrules.mk:101: build-NUCLEO_G0B1RE/pin.o] Error 1
make: *** Waiting for unfinished jobs....
fdcan.c: In function 'can_init':
fdcan.c:204:30: error: 'FDCAN1_IT0_IRQn' undeclared (first use in this function); did you mean 'TIM16_FDCAN_IT0_IRQn'?
204 | NVIC_SetPriority(FDCAN1_IT0_IRQn, IRQ_PRI_CAN);
| ^~~~~~~~~~~~~~~
| TIM16_FDCAN_IT0_IRQn
fdcan.c:204:30: note: each undeclared identifier is reported only once for each function it appears in
pyb_can.c: In function 'pyb_can_rxcallback':
pyb_can.c:78:37: error: 'FDCAN1_IT0_IRQn' undeclared (first use in this function); did you mean 'CAN1_RX0_IRQn'?
78 | #define CAN1_RX0_IRQn FDCAN1_IT0_IRQn
| ^~~~~~~~~~~~~~~
pyb_can.c:926:44: note: in expansion of macro 'CAN1_RX0_IRQn'
926 | irq = (fifo == CAN_RX_FIFO0) ? CAN1_RX0_IRQn : CAN1_RX1_IRQn;
| ^~~~~~~~~~~~~
pyb_can.c:78:37: note: each undeclared identifier is reported only once for each function it appears in
78 | #define CAN1_RX0_IRQn FDCAN1_IT0_IRQn
| ^~~~~~~~~~~~~~~
pyb_can.c:926:44: note: in expansion of macro 'CAN1_RX0_IRQn'
926 | irq = (fifo == CAN_RX_FIFO0) ? CAN1_RX0_IRQn : CAN1_RX1_IRQn;
| ^~~~~~~~~~~~~
fdcan.c:206:30: error: 'FDCAN1_IT1_IRQn' undeclared (first use in this function)
206 | NVIC_SetPriority(FDCAN1_IT1_IRQn, IRQ_PRI_CAN);
| ^~~~~~~~~~~~~~~
pyb_can.c:79:37: error: 'FDCAN1_IT1_IRQn' undeclared (first use in this function); did you mean 'CAN1_RX1_IRQn'?
79 | #define CAN1_RX1_IRQn FDCAN1_IT1_IRQn
| ^~~~~~~~~~~~~~~
pyb_can.c:926:60: note: in expansion of macro 'CAN1_RX1_IRQn'
926 | irq = (fifo == CAN_RX_FIFO0) ? CAN1_RX0_IRQn : CAN1_RX1_IRQn;
| ^~~~~~~~~~~~~
fdcan.c: In function 'can_deinit':
fdcan.c:233:29: error: 'FDCAN1_IT0_IRQn' undeclared (first use in this function); did you mean 'TIM16_FDCAN_IT0_IRQn'?
233 | HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn);
| ^~~~~~~~~~~~~~~
| TIM16_FDCAN_IT0_IRQn
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make: *** [../../py/mkrules.mk:101: build-NUCLEO_G0B1RE/pyb_can.o] Error 1
fdcan.c:234:29: error: 'FDCAN1_IT1_IRQn' undeclared (first use in this function)
234 | HAL_NVIC_DisableIRQ(FDCAN1_IT1_IRQn);
| ^~~~~~~~~~~~~~~
fdcan.c: In function 'can_receive':
fdcan.c:324:74: error: 'FDCAN_InitTypeDef' has no member named 'RxFifo0ElmtSize'
324 | address = (uint32_t *)(can->msgRam.RxFIFO0SA + (index * can->Init.RxFifo0ElmtSize * 4));
| ^
fdcan.c:331:74: error: 'FDCAN_InitTypeDef' has no member named 'RxFifo1ElmtSize'
331 | address = (uint32_t *)(can->msgRam.RxFIFO1SA + (index * can->Init.RxFifo1ElmtSize * 4));
| ^
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make: *** [../../py/mkrules.mk:101: build-NUCLEO_G0B1RE/fdcan.o] Error 1
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
stm32/make-pins.py: Fix GPIO AF constant for FDCAN peripherals.
This PR fixes the build failure on NUCLEO_G0B1RE (and other STM32G0 boards) when CAN is enabled.
Problem
The STM32G0 series uses FDCAN instead of the older bxCAN. The make-pins.py script correctly maps "FDCAN" to "CAN" for the MicroPython API naming, but was incorrectly generating GPIO_AFx_CANx instead of GPIO_AFx_FDCANx for the underlying HAL GPIO constant.
This caused build failures when MICROPY_HW_CAN1_TX was defined:
error: 'GPIO_AF3_CAN1' undeclared here
Solution
Map "CAN" back to "FDCAN" when generating the GPIO constant name in print_af_const().
Before:
{ MP_ROM_QSTR(MP_QSTR_AF3_CAN1), MP_ROM_INT(GPIO_AF3_CAN1) }, // Wrong - fails on G0
After:
{ MP_ROM_QSTR(MP_QSTR_AF3_CAN1), MP_ROM_INT(GPIO_AF3_FDCAN1) }, // Correct
The MicroPython API name (AF3_CAN1) remains unchanged for compatibility.
Fixes #18312