Skip to content

Commit 096adca

Browse files
committed
stm32/pin: Decrease machine_pin_obj_t.pin width from 5 to 4 bits.
Compiling using arm-none-eabi-gcc 14.1.0 with -O2 will give warnings about possible overflow indexing extint arrays, such as `pyb_extint_callback`. This is due to `machine_pin_obj_t.pin` having a bit-width of 5, and so a possible value up to 31, which is usually larger than `PYB_EXTI_NUM_VECTORS`. To fix this, change `machine_pin_obj_t.pin` to a bit-width of 4. Only 4 bits are needed for ST MCUs, which have up to 16 pins per port. Signed-off-by: Damien George <[email protected]>
1 parent 74f5237 commit 096adca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ports/stm32/pin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ typedef struct {
4545
typedef struct {
4646
mp_obj_base_t base;
4747
qstr name;
48-
uint32_t port : 4;
49-
uint32_t pin : 5; // Some ARM processors use 32 bits/PORT
48+
uint32_t port : 4; // Allows GPIOA through GPIOP
49+
uint32_t pin : 4; // ST MCUs have a maximum of 16 pins per port
5050
uint32_t num_af : 4;
5151
uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
5252
uint32_t adc_num : 3; // 1 bit per ADC

0 commit comments

Comments
 (0)