File tree Expand file tree Collapse file tree
common-hal/microcontroller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1111,6 +1111,8 @@ void gc_collect(void) {
11111111 // have lost their references in the VM even though they are mounted.
11121112 gc_collect_root ((void * * )& MP_STATE_VM (vfs_mount_table ), sizeof (mp_vfs_mount_t ) / sizeof (mp_uint_t ));
11131113
1114+ port_gc_collect ();
1115+
11141116 background_callback_gc_collect ();
11151117
11161118 #if CIRCUITPY_ALARM
@@ -1143,6 +1145,10 @@ void gc_collect(void) {
11431145 gc_collect_end ();
11441146}
11451147
1148+ // Ports may provide an implementation of this function if it is needed
1149+ MP_WEAK void port_gc_collect () {
1150+ }
1151+
11461152void NORETURN nlr_jump_fail (void * val ) {
11471153 reset_into_safe_mode (SAFE_MODE_NLR_JUMP_FAIL );
11481154 while (true) {
Original file line number Diff line number Diff line change 2828#include "shared-bindings/microcontroller/__init__.h"
2929#include "shared-bindings/microcontroller/Pin.h"
3030
31+ #include "py/gc.h"
32+
3133STATIC bool claimed_pins [IOMUXC_SW_PAD_CTL_PAD_COUNT ];
3234STATIC bool never_reset_pins [IOMUXC_SW_PAD_CTL_PAD_COUNT ];
3335
@@ -147,6 +149,11 @@ typedef struct {
147149
148150volatile static pin_change_interrupt_data pcid [MP_ARRAY_SIZE (s_gpioBases )][32 ];
149151
152+ // The 'data' pointers may be to gc objects, they must be kept alive.
153+ void pin_gc_collect () {
154+ gc_collect_root ((void * * )& pcid , sizeof (pcid ) / sizeof (void * ));
155+ }
156+
150157void enable_pin_change_interrupt (const mcu_pin_obj_t * pin , gpio_change_interrupt_t func , void * data ) {
151158 int instance = GPIO_GetInstance (pin -> gpio );
152159 volatile pin_change_interrupt_data * pci = & pcid [instance ][pin -> number ];
Original file line number Diff line number Diff line change @@ -48,5 +48,6 @@ extern bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin);
4848typedef void (gpio_change_interrupt_t )(void * data );
4949void disable_pin_change_interrupt (const mcu_pin_obj_t * pin );
5050void enable_pin_change_interrupt (const mcu_pin_obj_t * pin , gpio_change_interrupt_t func , void * data );
51+ void pin_gc_collect (void );
5152
5253#endif // MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_MICROCONTROLLER_PIN_H
Original file line number Diff line number Diff line change @@ -555,6 +555,10 @@ void port_idle_until_interrupt(void) {
555555 common_hal_mcu_enable_interrupts ();
556556}
557557
558+ void port_gc_collect (void ) {
559+ pin_gc_collect ();
560+ }
561+
558562// Catch faults where the memory access violates MPU settings.
559563void MemManage_Handler (void );
560564__attribute__((used )) void PLACE_IN_ITCM (MemManage_Handler )(void ) {
Original file line number Diff line number Diff line change @@ -128,4 +128,8 @@ void port_post_boot_py(bool heap_valid);
128128// A default weak implementation is provided that does nothing.
129129void port_boot_info (void );
130130
131+ // Some ports want to mark additional pointers as gc roots.
132+ // A default weak implementation is provided that does nothing.
133+ void port_gc_collect (void );
134+
131135#endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H
You can’t perform that action at this time.
0 commit comments