diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c index 4dbb0a0006..3d5cbf6790 100644 --- a/ports/atmel-samd/audio_dma.c +++ b/ports/atmel-samd/audio_dma.c @@ -432,4 +432,6 @@ void audio_dma_evsys_handler(void) { } } +MP_REGISTER_ROOT_POINTER(mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT]); + #endif diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 6fb969e47b..19e95f1e96 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -270,13 +270,4 @@ #include "peripherals/samd/dma.h" -#if CIRCUITPY_AUDIOCORE -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS \ - mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT]; -#else -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS -#endif - #endif // __INCLUDED_MPCONFIGPORT_H diff --git a/ports/broadcom/mpconfigport.h b/ports/broadcom/mpconfigport.h index e77725cca3..6b73edaee8 100644 --- a/ports/broadcom/mpconfigport.h +++ b/ports/broadcom/mpconfigport.h @@ -57,7 +57,4 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS - #endif // __INCLUDED_MPCONFIGPORT_H diff --git a/ports/cxd56/mpconfigport.h b/ports/cxd56/mpconfigport.h index 3560e72855..a0f5c0c1e1 100644 --- a/ports/cxd56/mpconfigport.h +++ b/ports/cxd56/mpconfigport.h @@ -45,7 +45,4 @@ #define MICROPY_BYTES_PER_GC_BLOCK (32) -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS \ - #endif // __INCLUDED_MPCONFIGPORT_H diff --git a/ports/espressif/bindings/espnow/ESPNow.c b/ports/espressif/bindings/espnow/ESPNow.c index 211cb080d4..1f544758d1 100644 --- a/ports/espressif/bindings/espnow/ESPNow.c +++ b/ports/espressif/bindings/espnow/ESPNow.c @@ -368,3 +368,5 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &espnow_stream_p, unary_op, &espnow_unary_op ); + +MP_REGISTER_ROOT_POINTER(struct _espnow_obj_t *espnow_singleton); diff --git a/ports/espressif/common-hal/_bleio/ble_events.c b/ports/espressif/common-hal/_bleio/ble_events.c index a072a80623..e5c4608cd7 100644 --- a/ports/espressif/common-hal/_bleio/ble_events.c +++ b/ports/espressif/common-hal/_bleio/ble_events.c @@ -126,3 +126,5 @@ int ble_event_run_handlers(struct ble_gap_event *event) { #endif return 0; } + +MP_REGISTER_ROOT_POINTER(struct ble_event_handler_entry *ble_event_handler_entries); diff --git a/ports/espressif/mpconfigport.h b/ports/espressif/mpconfigport.h index e4733356bb..481a2f4517 100644 --- a/ports/espressif/mpconfigport.h +++ b/ports/espressif/mpconfigport.h @@ -37,23 +37,6 @@ #include "py/circuitpy_mpconfig.h" -#if CIRCUITPY_BLEIO -#define BLEIO_ROOT_POINTERS struct ble_event_handler_entry *ble_event_handler_entries; -#else -#define BLEIO_ROOT_POINTERS -#endif - -#if CIRCUITPY_ESPNOW -#define ESPNOW_ROOT_POINTERS struct _espnow_obj_t *espnow_singleton; -#else -#define ESPNOW_ROOT_POINTERS -#endif - -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS \ - BLEIO_ROOT_POINTERS \ - ESPNOW_ROOT_POINTERS - #define MICROPY_NLR_SETJMP (1) #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 diff --git a/ports/litex/mpconfigport.h b/ports/litex/mpconfigport.h index cedc3badc3..9b214c5799 100644 --- a/ports/litex/mpconfigport.h +++ b/ports/litex/mpconfigport.h @@ -34,8 +34,6 @@ #include "py/circuitpy_mpconfig.h" -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS #define MICROPY_NLR_SETJMP (1) #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 diff --git a/ports/mimxrt10xx/mpconfigport.h b/ports/mimxrt10xx/mpconfigport.h index 7cc17494bf..eedfaaec15 100644 --- a/ports/mimxrt10xx/mpconfigport.h +++ b/ports/mimxrt10xx/mpconfigport.h @@ -52,10 +52,7 @@ extern uint8_t _ld_default_stack_size; #include "py/circuitpy_mpconfig.h" -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS \ - // TODO: -// mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT]; +// mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT] as an MP_REGISTER_ROOT_POINTER. #endif // __INCLUDED_MPCONFIGPORT_H diff --git a/ports/nrf/bluetooth/ble_drv.c b/ports/nrf/bluetooth/ble_drv.c index e3914e6a18..48c40d7082 100644 --- a/ports/nrf/bluetooth/ble_drv.c +++ b/ports/nrf/bluetooth/ble_drv.c @@ -196,3 +196,5 @@ void SD_EVT_IRQHandler(void) { ble_serial_enable(); #endif } + +MP_REGISTER_ROOT_POINTER(ble_drv_evt_handler_entry_t *ble_drv_evt_handler_entries); diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c index ce8ee8c7cf..f5f6335e5e 100644 --- a/ports/nrf/common-hal/neopixel_write/__init__.c +++ b/ports/nrf/common-hal/neopixel_write/__init__.c @@ -333,3 +333,5 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, // Update the next start. next_start_raw_ticks = port_get_raw_ticks(NULL) + 4; } + +MP_REGISTER_ROOT_POINTER(uint16_t *pixels_pattern_heap); diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 4726d51c55..d97d9277d0 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -204,11 +204,4 @@ #error RAM size regions do not use all of RAM #endif - -#define MICROPY_PORT_ROOT_POINTERS \ - CIRCUITPY_COMMON_ROOT_POINTERS \ - uint16_t *pixels_pattern_heap; \ - ble_drv_evt_handler_entry_t *ble_drv_evt_handler_entries; \ - - #endif // NRF5_MPCONFIGPORT_H__ diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index b5bd8c069c..8ea58acc3c 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -487,4 +487,5 @@ void isr_dma_0(void) { } } +MP_REGISTER_ROOT_POINTER(mp_obj_t playing_audio[NUM_DMA_CHANNELS]); #endif diff --git a/ports/raspberrypi/common-hal/countio/Counter.c b/ports/raspberrypi/common-hal/countio/Counter.c index e360b6f06b..a6c98f113f 100644 --- a/ports/raspberrypi/common-hal/countio/Counter.c +++ b/ports/raspberrypi/common-hal/countio/Counter.c @@ -111,3 +111,5 @@ void counter_interrupt_handler(void) { self->count += 65536; } } + +MP_REGISTER_ROOT_POINTER(mp_obj_t counting[NUM_PWM_SLICES]); diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 629811ab9f..573996a269 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -1098,3 +1098,5 @@ bool common_hal_rp2pio_statemachine_get_writing(rp2pio_statemachine_obj_t *self) int common_hal_rp2pio_statemachine_get_pending(rp2pio_statemachine_obj_t *self) { return self->pending_buffers; } + +MP_REGISTER_ROOT_POINTER(mp_obj_t background_pio[NUM_DMA_CHANNELS]); diff --git a/ports/raspberrypi/mpconfigport.h b/ports/raspberrypi/mpconfigport.h index 4458107974..0c5f2d3402 100644 --- a/ports/raspberrypi/mpconfigport.h +++ b/ports/raspberrypi/mpconfigport.h @@ -55,12 +55,6 @@ // This also includes mpconfigboard.h. #include "py/circuitpy_mpconfig.h" -#define MICROPY_PORT_ROOT_POINTERS \ - mp_obj_t counting[NUM_PWM_SLICES]; \ - mp_obj_t playing_audio[NUM_DMA_CHANNELS]; \ - mp_obj_t background_pio[NUM_DMA_CHANNELS]; \ - CIRCUITPY_COMMON_ROOT_POINTERS; - #if CIRCUITPY_CYW43 #include "pico/cyw43_arch.h" #define MICROPY_PY_LWIP_ENTER cyw43_arch_lwip_begin(); diff --git a/ports/silabs/mpconfigport.h b/ports/silabs/mpconfigport.h index ba498dd763..ce7739ccca 100644 --- a/ports/silabs/mpconfigport.h +++ b/ports/silabs/mpconfigport.h @@ -65,9 +65,4 @@ #include "py/circuitpy_mpconfig.h" -#define MICROPY_PORT_ROOT_POINTERS \ - void *cpy_uart_obj_all[MAX_UART]; \ - void *cpy_i2c_obj_all[MAX_I2C]; \ - CIRCUITPY_COMMON_ROOT_POINTERS - #endif // EFR32_MPCONFIGPORT_H__ diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c index b78aff8e4f..7c3a0d59ad 100644 --- a/ports/stm/common-hal/busio/I2C.c +++ b/ports/stm/common-hal/busio/I2C.c @@ -400,3 +400,5 @@ void I2C3_EV_IRQHandler(void) { void I2C4_EV_IRQHandler(void) { call_hal_irq(4); } + +MP_REGISTER_ROOT_POINTER(void *cpy_i2c_obj_all[MAX_I2C]); diff --git a/ports/stm/common-hal/busio/UART.c b/ports/stm/common-hal/busio/UART.c index 59e98409c7..7635c4aaf3 100644 --- a/ports/stm/common-hal/busio/UART.c +++ b/ports/stm/common-hal/busio/UART.c @@ -674,3 +674,5 @@ STATIC void uart_assign_irq(busio_uart_obj_t *self, USART_TypeDef *USARTx) { } #endif } + +MP_REGISTER_ROOT_POINTER(void *cpy_uart_obj_all[MAX_UART]); diff --git a/ports/stm/mpconfigport.h b/ports/stm/mpconfigport.h index 94fccd53e9..fc1f4ae336 100644 --- a/ports/stm/mpconfigport.h +++ b/ports/stm/mpconfigport.h @@ -60,9 +60,4 @@ extern uint8_t _ld_default_stack_size; #define MAX_I2C 4 #define MAX_SPI 6 -#define MICROPY_PORT_ROOT_POINTERS \ - void *cpy_uart_obj_all[MAX_UART]; \ - void *cpy_i2c_obj_all[MAX_I2C]; \ - CIRCUITPY_COMMON_ROOT_POINTERS - #endif // __INCLUDED_MPCONFIGPORT_H diff --git a/py/mpconfig.h b/py/mpconfig.h index 0ce5d50b57..ca205a6e8c 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1769,11 +1769,6 @@ typedef double mp_float_t; #define MICROPY_PORT_CONSTANTS #endif -// Any root pointers for GC scanning - see mpstate.c -#ifndef MICROPY_PORT_ROOT_POINTERS -#define MICROPY_PORT_ROOT_POINTERS -#endif - /*****************************************************************************/ /* Hooks for a port to wrap functions with attributes */ diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index de07916bba..03ba3c4165 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -352,7 +352,7 @@ MP_DEFINE_CONST_OBJ_TYPE( displayio_group_type, MP_QSTR_Group, MP_TYPE_FLAG_ITER_IS_GETITER, - .make_new, displayio_group_make_new, + make_new, displayio_group_make_new, locals_dict, &displayio_group_locals_dict, subscr, group_subscr, unary_op, group_unary_op, diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 7c36a2d46b..dcf0f7bd9b 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -141,7 +141,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val // Convert a tuple or list to a bytearray. if (mp_obj_is_type(value, &mp_type_tuple) || mp_obj_is_type(value, &mp_type_list)) { - value = mp_type_bytes.make_new(&mp_type_bytes, 1, 0, &value); + value = MP_OBJ_TYPE_GET_SLOT(&mp_type_bytes, make_new)(&mp_type_bytes, 1, 0, &value); } uint32_t color; diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 13188c0d14..8d130d2a70 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -148,6 +148,7 @@ STATIC const mp_rom_map_elem_t pulseio_pulseout_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pulseio_pulseout_locals_dict, pulseio_pulseout_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( + pulseio_pulseout_type, MP_QSTR_PulseOut, MP_TYPE_FLAG_NONE, make_new, pulseio_pulseout_make_new, diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index 50f4264b24..27544059eb 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -145,7 +145,6 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_ITER_IS_ITERNEXT, make_new, terminalio_terminal_make_new, locals_dict, (mp_obj_dict_t *)&terminalio_terminal_locals_dict, - getiter, mp_identity_getiter, - iternext, mp_stream_unbuffered_iter, + iter, mp_stream_unbuffered_iter, protocol, &terminalio_terminal_stream_p ); diff --git a/supervisor/shared/external_flash/external_flash.c b/supervisor/shared/external_flash/external_flash.c index 5b1e0b1793..79c6a6987f 100644 --- a/supervisor/shared/external_flash/external_flash.c +++ b/supervisor/shared/external_flash/external_flash.c @@ -33,6 +33,7 @@ #include "supervisor/shared/external_flash/common_commands.h" #include "extmod/vfs.h" #include "extmod/vfs_fat.h" +#include "py/gc.h" #include "py/misc.h" #include "py/obj.h" #include "py/runtime.h" @@ -367,7 +368,8 @@ static bool allocate_ram_cache(void) { return true; } - if (MP_STATE_MEM(gc_pool_start) == 0) { + // Couldn't allocate outside the heap. Is the heap available? + if (!gc_alloc_possible()) { return false; } @@ -414,7 +416,7 @@ static void release_ram_cache(void) { if (supervisor_cache != NULL) { free_memory(supervisor_cache); supervisor_cache = NULL; - } else if (MP_STATE_MEM(gc_pool_start)) { + } else if (gc_alloc_possible()) { m_free(MP_STATE_VM(flash_ram_cache)); } MP_STATE_VM(flash_ram_cache) = NULL; @@ -462,7 +464,7 @@ static bool flush_ram_cache(bool keep_cache) { write_flash(current_sector + (i * pages_per_block + j) * SPI_FLASH_PAGE_SIZE, MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j], SPI_FLASH_PAGE_SIZE); - if (!keep_cache && supervisor_cache == NULL && MP_STATE_MEM(gc_pool_start)) { + if (!keep_cache && supervisor_cache == NULL && gc_alloc_possible()) { m_free(MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j]); } }