Klipper3d / klipper

Klipper is a 3d-printer firmware
GNU General Public License v3.0
8.95k stars 5.16k forks source link

stm32: fix support for USARTs on STM32G0B0 #6545

Closed rcambrj closed 2 months ago

rcambrj commented 2 months ago

Fixes a bug where selecting (at least) USART5 on the STM32G0B0 would lead to this build error -

expand error ``` % make Creating symbolic link out/board Building out/autoconf.h Compiling out/src/sched.o Compiling out/src/command.o Compiling out/src/basecmd.o Compiling out/src/debugcmds.o Compiling out/src/initial_pins.o Compiling out/src/gpiocmds.o Compiling out/src/stepper.o Compiling out/src/endstop.o Compiling out/src/trsync.o Compiling out/src/adccmds.o Compiling out/src/spicmds.o Compiling out/src/i2ccmds.o Compiling out/src/pwmcmds.o Compiling out/src/buttons.o Compiling out/src/tmcuart.o Compiling out/src/neopixel.o Compiling out/src/pulse_counter.o Compiling out/src/lcd_st7920.o Compiling out/src/lcd_hd44780.o Compiling out/src/spi_software.o Compiling out/src/i2c_software.o Compiling out/src/thermocouple.o Compiling out/src/sensor_adxl345.o Compiling out/src/sensor_angle.o Compiling out/src/sensor_mpu9250.o Compiling out/src/sensor_lis2dw.o Compiling out/src/sensor_bulk.o Compiling out/src/stm32/watchdog.o Compiling out/src/stm32/gpio.o Compiling out/src/stm32/clockline.o Compiling out/src/stm32/dfu_reboot.o Compiling out/src/generic/crc16_ccitt.o Compiling out/src/generic/armcm_boot.o Compiling out/src/generic/armcm_irq.o Compiling out/src/generic/armcm_reset.o Compiling out/src/generic/timer_irq.o Compiling out/src/stm32/stm32f0_timer.o Compiling out/src/stm32/stm32g0.o Compiling out/src/stm32/gpioperiph.o Compiling out/src/stm32/stm32f0_adc.o Compiling out/src/stm32/stm32f0_i2c.o Compiling out/src/stm32/spi.o Compiling out/src/stm32/stm32f0_serial.o In file included from out/board-generic/board/armcm_boot.h:4, from src/stm32/stm32f0_serial.c:8: src/stm32/stm32f0_serial.c: In function 'serial_init': src/stm32/stm32f0_serial.c:87:23: error: 'USART5_IRQn' undeclared (first use in this function); did you mean 'USART2_IRQn'? 87 | #define USARTx_IRQn USART5_IRQn | ^~~~~~~~~~~ src/ctr.h:36:22: note: in definition of macro 'DECL_CTR_INT' 36 | (REQUEST), { args }, 0 } | ^~~~ out/board-generic/board/armcm_boot.h:10:58: note: in expansion of macro 'CTR_INT' 10 | DECL_CTR_INT("DECL_ARMCM_IRQ " __stringify(FUNC), 1, CTR_INT(NUM)) | ^~~~~~~ out/board-generic/board/armcm_boot.h:14:9: note: in expansion of macro 'DECL_ARMCM_IRQ' 14 | DECL_ARMCM_IRQ(FUNC, (NUM)); \ | ^~~~~~~~~~~~~~ src/stm32/stm32f0_serial.c:156:5: note: in expansion of macro 'armcm_enable_irq' 156 | armcm_enable_irq(USARTx_IRQHandler, USARTx_IRQn, 0); | ^~~~~~~~~~~~~~~~ src/stm32/stm32f0_serial.c:156:41: note: in expansion of macro 'USARTx_IRQn' 156 | armcm_enable_irq(USARTx_IRQHandler, USARTx_IRQn, 0); | ^~~~~~~~~~~ src/stm32/stm32f0_serial.c:87:23: note: each undeclared identifier is reported only once for each function it appears in 87 | #define USARTx_IRQn USART5_IRQn | ^~~~~~~~~~~ src/ctr.h:36:22: note: in definition of macro 'DECL_CTR_INT' 36 | (REQUEST), { args }, 0 } | ^~~~ out/board-generic/board/armcm_boot.h:10:58: note: in expansion of macro 'CTR_INT' 10 | DECL_CTR_INT("DECL_ARMCM_IRQ " __stringify(FUNC), 1, CTR_INT(NUM)) | ^~~~~~~ out/board-generic/board/armcm_boot.h:14:9: note: in expansion of macro 'DECL_ARMCM_IRQ' 14 | DECL_ARMCM_IRQ(FUNC, (NUM)); \ | ^~~~~~~~~~~~~~ src/stm32/stm32f0_serial.c:156:5: note: in expansion of macro 'armcm_enable_irq' 156 | armcm_enable_irq(USARTx_IRQHandler, USARTx_IRQn, 0); | ^~~~~~~~~~~~~~~~ src/stm32/stm32f0_serial.c:156:41: note: in expansion of macro 'USARTx_IRQn' 156 | armcm_enable_irq(USARTx_IRQHandler, USARTx_IRQn, 0); | ^~~~~~~~~~~ make: *** [Makefile:64: out/src/stm32/stm32f0_serial.o] Error 1 ```

My Ender3 is now running a BTT SKR E3 mini v3.0 with an STM32G0B0. Pins PD2 and PD3 (USART5) are broken out to header pins, labelled simply I/O.

With this change, I've successfully connected the klipper host via these pins.

KevinOConnor commented 2 months ago

Thanks. It seems fine to me, but in order for me to commit directly the commit needs to have a signed-off-by line. See https://www.klipper3d.org/CONTRIBUTING.html

-Kevin

rcambrj commented 2 months ago

@KevinOConnor thanks for taking a look. I amended the commit as requested.

KevinOConnor commented 2 months ago

Thanks.

-Kevin