From 5b2929a0e69a4f3667ae9f0dbbfe3677ebc840ad Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Fri, 28 Oct 2022 19:02:28 +0300 Subject: [PATCH] esp32/machine_pin: Fix size of machine_pin_irq_handler array. Set the size of machine_pin_irq_handler array to GPIO_NUM_MAX: - Min GPIO_NUM_MAX is 22 for IDF_TARGET_ESP32C3. - Max GPIO_NUM_MAX is 49 for IDF_TARGET_ESP32S3. The MP_REGISTER_ROOT_POINTER entry must be hard-coded, because the location that it's evaluated by the compiler does not include the relevant IDF header to get a definition of GPIO_NUM_MAX. --- ports/esp32/machine_pin.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/esp32/machine_pin.c b/ports/esp32/machine_pin.c index 4f6f948d52..8a892d2316 100644 --- a/ports/esp32/machine_pin.c +++ b/ports/esp32/machine_pin.c @@ -64,7 +64,7 @@ typedef struct _machine_pin_irq_obj_t { gpio_num_t id; } machine_pin_irq_obj_t; -STATIC const machine_pin_obj_t machine_pin_obj[] = { +STATIC const machine_pin_obj_t machine_pin_obj[GPIO_NUM_MAX] = { #if CONFIG_IDF_TARGET_ESP32 {{&machine_pin_type}, GPIO_NUM_0}, @@ -225,7 +225,7 @@ STATIC const machine_pin_obj_t machine_pin_obj[] = { }; // forward declaration -STATIC const machine_pin_irq_obj_t machine_pin_irq_object[]; +STATIC const machine_pin_irq_obj_t machine_pin_irq_object[GPIO_NUM_MAX]; void machine_pins_init(void) { static bool did_install = false; @@ -545,7 +545,7 @@ MP_DEFINE_CONST_OBJ_TYPE( STATIC const mp_obj_type_t machine_pin_irq_type; -STATIC const machine_pin_irq_obj_t machine_pin_irq_object[] = { +STATIC const machine_pin_irq_obj_t machine_pin_irq_object[GPIO_NUM_MAX] = { #if CONFIG_IDF_TARGET_ESP32 {{&machine_pin_irq_type}, GPIO_NUM_0}, @@ -732,4 +732,4 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &machine_pin_irq_locals_dict ); -MP_REGISTER_ROOT_POINTER(mp_obj_t machine_pin_irq_handler[40]); +MP_REGISTER_ROOT_POINTER(mp_obj_t machine_pin_irq_handler[49]); // 49 is the biggest of GPIO_NUM_MAX's