From 096adca0c88cd779b3e5e391e42db1d46f87bba1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 27 Jun 2024 11:19:16 +1000 Subject: [PATCH] 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 --- ports/stm32/pin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm32/pin.h b/ports/stm32/pin.h index 04479bd042..33f34ebcc2 100644 --- a/ports/stm32/pin.h +++ b/ports/stm32/pin.h @@ -45,8 +45,8 @@ typedef struct { typedef struct { mp_obj_base_t base; qstr name; - uint32_t port : 4; - uint32_t pin : 5; // Some ARM processors use 32 bits/PORT + uint32_t port : 4; // Allows GPIOA through GPIOP + uint32_t pin : 4; // ST MCUs have a maximum of 16 pins per port uint32_t num_af : 4; uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT uint32_t adc_num : 3; // 1 bit per ADC