diff --git a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c index c5237c8a8e..9c7f4a256f 100644 --- a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c @@ -41,9 +41,6 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_08, &pin_GPIO_SD_07, &pin_GPIO_SD_06, - // USB Pins - &pin_USB_OTG1_DN, - &pin_USB_OTG1_DP, NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/boards/imxrt1015_evk/board.c b/ports/mimxrt10xx/boards/imxrt1015_evk/board.c index 568945a3eb..06b3dd22d5 100644 --- a/ports/mimxrt10xx/boards/imxrt1015_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1015_evk/board.c @@ -40,9 +40,6 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_09, &pin_GPIO_SD_B1_10, &pin_GPIO_SD_B1_11, - // USB Pins - &pin_USB_OTG1_DN, - &pin_USB_OTG1_DP, NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/boards/imxrt1020_evk/board.c b/ports/mimxrt10xx/boards/imxrt1020_evk/board.c index f814afd956..540e416525 100644 --- a/ports/mimxrt10xx/boards/imxrt1020_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1020_evk/board.c @@ -42,10 +42,6 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_09, &pin_GPIO_SD_B1_10, &pin_GPIO_SD_B1_11, - - // USB Pins - &pin_USB_OTG1_DN, - &pin_USB_OTG1_DP, NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/boards/imxrt1040_evk/board.c b/ports/mimxrt10xx/boards/imxrt1040_evk/board.c index 0e97d87b60..6ab54be8a6 100644 --- a/ports/mimxrt10xx/boards/imxrt1040_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1040_evk/board.c @@ -44,9 +44,6 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_10, &pin_GPIO_SD_B1_11, - &pin_USB_OTG1_DN, - &pin_USB_OTG1_DP, - NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/boards/imxrt1050_evkb/board.c b/ports/mimxrt10xx/boards/imxrt1050_evkb/board.c index 8a34fc4210..6e31888c53 100644 --- a/ports/mimxrt10xx/boards/imxrt1050_evkb/board.c +++ b/ports/mimxrt10xx/boards/imxrt1050_evkb/board.c @@ -45,8 +45,8 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_11, // USB Pins - &pin_GPIO_AD_B0_01, - &pin_GPIO_AD_B0_03, + &pin_GPIO_AD_B0_01, // ID Pin + &pin_GPIO_AD_B0_03, // OC/Fault Pin NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/boards/imxrt1060_evk/board.c b/ports/mimxrt10xx/boards/imxrt1060_evk/board.c index f27f549c64..4a2e6e0913 100644 --- a/ports/mimxrt10xx/boards/imxrt1060_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1060_evk/board.c @@ -50,8 +50,8 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_11, // USB Pins - &pin_GPIO_AD_B0_01, - &pin_GPIO_AD_B0_03, + &pin_GPIO_AD_B0_01, // ID Pin + &pin_GPIO_AD_B0_03, // OC/Fault Pin NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Pin.c b/ports/mimxrt10xx/common-hal/microcontroller/Pin.c index 9f9e306dd9..2cd53e9560 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Pin.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Pin.c @@ -31,8 +31,8 @@ #include "py/gc.h" -STATIC bool claimed_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT]; -STATIC bool never_reset_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT]; +STATIC bool claimed_pins[PAD_COUNT]; +STATIC bool never_reset_pins[PAD_COUNT]; // Default is that no pins are forbidden to reset. MP_WEAK const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { @@ -55,10 +55,10 @@ STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { // and GPIO port and number, used to store claimed and reset tagging. The two number // systems are not related and one cannot determine the other without a pin object void reset_all_pins(void) { - for (uint8_t i = 0; i < IOMUXC_SW_PAD_CTL_PAD_COUNT; i++) { + for (uint8_t i = 0; i < PAD_COUNT; i++) { claimed_pins[i] = never_reset_pins[i]; } - for (uint8_t i = 0; i < IOMUXC_SW_PAD_CTL_PAD_COUNT; i++) { + for (uint8_t i = 0; i < PAD_COUNT; i++) { mcu_pin_obj_t *pin = mcu_pin_globals.map.table[i].value; if (never_reset_pins[pin->mux_idx]) { continue; @@ -90,6 +90,11 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin) { disable_pin_change_interrupt(pin); never_reset_pins[pin->mux_idx] = false; claimed_pins[pin->mux_idx] = false; + + // This should never be true, but protect against it anyway. + if (pin->mux_reg == 0) { + return; + } *(uint32_t *)pin->mux_reg = pin->mux_reset; *(uint32_t *)pin->cfg_reg = pin->pad_reset; } diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h index 8e901f0980..2b63b84ecb 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h @@ -40,5 +40,7 @@ #include "pin_names.h" #undef FORMAT_PIN -#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +// Pads can be reset. Other pins like USB cannot be. +#define PAD_COUNT (43) +#define PIN_COUNT (PAD_COUNT + 2) extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h index 8655bf872f..9c66fc82f3 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h @@ -40,5 +40,7 @@ #include "pin_names.h" #undef FORMAT_PIN -#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +// Pads can be reset. Other pins like USB cannot be. +#define PAD_COUNT (56) +#define PIN_COUNT (PAD_COUNT + 2) extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h index b4f991a879..5d4f992e89 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h @@ -40,5 +40,7 @@ #include "pin_names.h" #undef FORMAT_PIN -#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +// Pads can be reset. Other pins like USB cannot be. +#define PAD_COUNT (93) +#define PIN_COUNT (PAD_COUNT + 2) extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h index f666962907..c62c0ecaa0 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h @@ -40,5 +40,7 @@ #include "pin_names.h" #undef FORMAT_PIN -#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +// Pads can be reset. Other pins like USB cannot be. +#define PAD_COUNT (112) +#define PIN_COUNT (PAD_COUNT + 2) extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h index 4ee8d2ae28..e02f1208bd 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h @@ -40,5 +40,7 @@ #include "pin_names.h" #undef FORMAT_PIN -#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 4) +// Pads can be reset. Other pins like USB cannot be. +#define PAD_COUNT (124) +#define PIN_COUNT (PAD_COUNT + 4) extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h index 6f746f3b4c..135d9f9565 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h @@ -40,5 +40,7 @@ #include "pin_names.h" #undef FORMAT_PIN -#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 4) +// Pads can be reset. Other pins like USB cannot be. +#define PAD_COUNT (124) +#define PIN_COUNT (PAD_COUNT + 4) extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h index 35be6dd36e..786b0a248c 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h @@ -40,5 +40,7 @@ #include "pin_names.h" #undef FORMAT_PIN -#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 0) +// Pads can be reset. Other pins like USB cannot be. +#define PAD_COUNT (145) +#define PIN_COUNT (PAD_COUNT + 0) extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/tools/gen_peripherals_data.py b/ports/mimxrt10xx/tools/gen_peripherals_data.py index 4193ae7228..d87e9022b2 100644 --- a/ports/mimxrt10xx/tools/gen_peripherals_data.py +++ b/ports/mimxrt10xx/tools/gen_peripherals_data.py @@ -190,6 +190,7 @@ for device in devices: split_pin = name.split("_") pin_name = "_".join(split_pin[4:]) if pin_name not in all_pins: + print("skip", pin_name) continue gpio_base = "_".join(split_pin[4:-1]) @@ -278,7 +279,10 @@ for device in devices: pins_c.append("") pins_h.append("") - pins_h.append(f"#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + {len(usb_pins)})") + + pins_h.append("// Pads can be reset. Other pins like USB cannot be.") + pins_h.append(f"#define PAD_COUNT ({pin_number})") + pins_h.append(f"#define PIN_COUNT (PAD_COUNT + {len(usb_pins)})") pins_h.append(f"extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT];") pins_h.append("")