Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,22 +410,20 @@ static void cleanup_after_vm(mp_obj_t exception) {
wifi_user_reset();
#endif

// reset_board_buses() first because it may release pins from the never_reset state, so that
// reset_port() can reset them.
// reset_board_buses() first to preserve display buses and deinit others.
#if CIRCUITPY_BOARD
reset_board_buses();
#endif
reset_port();
reset_board();

// Free the heap last because other modules may reference heap memory and need to shut down.
// Flush before GC might free file objects.
filesystem_flush();

// Runs finalisers while shutting down the heap.
// Runs finalisers while shutting down the heap. Finalizers call deinit on all user objects.
stop_mp();

// Don't reset pins until finalisers have run.
reset_all_pins();
// Port-wide cleanup after finalizers have run.
reset_port();
reset_board();

// Let the workflows know we've reset in case they want to restart.
supervisor_workflow_reset();
Expand Down Expand Up @@ -804,8 +802,6 @@ static bool __attribute__((noinline)) run_code_py(safe_mode_t safe_mode, bool *s
#if CIRCUITPY_ALARM_PRESERVE_DIOS
common_hal_alarm_clear_pin_preservations();
#endif
// Reset pins, as if there was a hard reset.
reset_all_pins();
// Pretend that the next run is the first run, as if we were reset.
*simulate_reset = true;
}
Expand Down Expand Up @@ -1020,9 +1016,6 @@ int __attribute__((used)) main(void) {
// initialise the cpu and peripherals
set_safe_mode(port_init());

// All ports need pins reset, after never-reset pins are marked in port_init();
reset_all_pins();

port_heap_init();


Expand Down
6 changes: 0 additions & 6 deletions ports/analog/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
return;
}

// Never reset I2C obj when reload
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
common_hal_never_reset_pin(self->sda);
common_hal_never_reset_pin(self->scl);
}

// Check I2C status, deinited or not
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
return self->sda == NULL;
Expand Down
8 changes: 0 additions & 8 deletions ports/analog/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
return;
}

// Never reset SPI when reload
void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
common_hal_never_reset_pin(self->mosi);
common_hal_never_reset_pin(self->miso);
common_hal_never_reset_pin(self->sck);
common_hal_never_reset_pin(self->nss);
}

// Check SPI status, deinited or not
bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
return self->sck == NULL;
Expand Down
10 changes: 0 additions & 10 deletions ports/analog/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ typedef enum {
typedef enum {
UART_FREE = 0,
UART_BUSY,
UART_NEVER_RESET,
} uart_status_t;

static uint32_t timeout_ms = 0;
Expand All @@ -74,7 +73,6 @@ static uint32_t timeout_ms = 0;
static uint8_t uarts_active = 0;
static uart_status_t uart_status[NUM_UARTS];
static volatile int uart_err;
static uint8_t uart_never_reset_mask = 0;
static busio_uart_obj_t *context;

static bool isValidBaudrate(uint32_t baudrate) {
Expand Down Expand Up @@ -449,12 +447,4 @@ bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
return !(MXC_UART_GetStatus(self->uart_regs) & (MXC_F_UART_STATUS_TX_BUSY));
}

void common_hal_busio_uart_never_reset(busio_uart_obj_t *self) {
common_hal_never_reset_pin(self->tx_pin);
common_hal_never_reset_pin(self->rx_pin);
common_hal_never_reset_pin(self->cts_pin);
common_hal_never_reset_pin(self->rts_pin);
uart_never_reset_mask |= (1 << (self->uart_id));
}

#endif // CIRCUITPY_BUSIO_UART
5 changes: 0 additions & 5 deletions ports/analog/common-hal/digitalio/DigitalInOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS];

void common_hal_digitalio_digitalinout_never_reset(
digitalio_digitalinout_obj_t *self) {
common_hal_never_reset_pin(self->pin);
}

bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
return self->pin == NULL;
}
Expand Down
23 changes: 0 additions & 23 deletions ports/analog/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,8 @@ static uint32_t claimed_pins[NUM_GPIO_PORTS];
// defined in board.c
extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS];

static uint32_t never_reset_pins[NUM_GPIO_PORTS];

#define INVALID_PIN 0xFF // id for invalid pin

void reset_all_pins(void) {
// reset all pins except for never_reset_pins
for (int i = 0; i < NUM_GPIO_PORTS; i++) {
for (int j = 0; j < 32; j++) {
if (!(never_reset_pins[i] & (1 << j))) {
reset_pin_number(i, j);
}
}
// set claimed pins to never_reset pins
claimed_pins[i] = never_reset_pins[i];
}
}

void reset_pin_number(uint8_t pin_port, uint8_t pin_pad) {
if ((pin_port == INVALID_PIN) || (pin_port > NUM_GPIO_PORTS)) {
Expand Down Expand Up @@ -84,15 +70,6 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
return !(claimed_pins[pin->port] & (pin->mask));
}

void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) {
if ((pin != NULL) && (pin->mask != INVALID_PIN)) {
never_reset_pins[pin->port] |= (1 << pin->mask);

// any never reset pin must also be claimed
claimed_pins[pin->port] |= (1 << pin->mask);
}
}

void common_hal_reset_pin(const mcu_pin_obj_t *pin) {
if (pin == NULL) {
return;
Expand Down
1 change: 0 additions & 1 deletion ports/analog/common-hal/microcontroller/Pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "peripherals/pins.h"

void reset_all_pins(void);
// reset_pin_number takes the pin number instead of the pointer so that objects don't
// need to store a full pointer.
void reset_pin_number(uint8_t pin_port, uint8_t pin_pad);
1 change: 0 additions & 1 deletion ports/analog/supervisor/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

void init_usb_hardware(void) {
// USB GPIOs are non-configurable on MAX32 devices
// No need to add them to the never_reset list for mcu/Pin API.

// 1 ms SysTick initialized in board.c

Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/aloriumtech_evo_m51/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "common-hal/microcontroller/Pin.h"

void board_init(void) {
never_reset_pin_number(PIN_PB20);
REG_PORT_DIRSET1 = PORT_PB20; // PB20 as output
REG_PORT_OUTCLR1 = PORT_PB20; // PB20 cleared
PORT->Group[1].PINCFG[20].reg |= PORT_PINCFG_PMUXEN; // Mux enabled on PB20
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/hallowing_m0_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
bus->base.type = &fourwire_fourwire_type;
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
common_hal_busio_spi_never_reset(spi);
common_hal_fourwire_fourwire_construct(bus,
spi,
MP_OBJ_FROM_PTR(&pin_PA28), // Command or data
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/hallowing_m4_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/monster_m4sk/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/openbook_m4/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pewpew_lcd/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pewpew_m4/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pybadge/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pycubed/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
void board_init(void) {
pwmio_pwmout_obj_t pwm;
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pwmio_pwmout_never_reset(&pwm);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pycubed_mram/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
void board_init(void) {
pwmio_pwmout_obj_t pwm;
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pwmio_pwmout_never_reset(&pwm);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pycubed_mram_v05/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
void board_init(void) {
pwmio_pwmout_obj_t pwm;
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pwmio_pwmout_never_reset(&pwm);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pycubed_v05/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
void board_init(void) {
pwmio_pwmout_obj_t pwm;
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pwmio_pwmout_never_reset(&pwm);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
1 change: 0 additions & 1 deletion ports/atmel-samd/boards/pygamer/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down
4 changes: 0 additions & 4 deletions ports/atmel-samd/boards/seeeduino_wio_terminal/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
Expand Down Expand Up @@ -104,9 +103,6 @@ void board_init(void) {
common_hal_digitalio_digitalinout_set_value(&USB_HOST_ENABLE, false);

// Never reset
common_hal_digitalio_digitalinout_never_reset(&CTR_5V);
common_hal_digitalio_digitalinout_never_reset(&CTR_3V3);
common_hal_digitalio_digitalinout_never_reset(&USB_HOST_ENABLE);

// reset pin after fake deep sleep
reset_pin_number(pin_PA18.number);
Expand Down
2 changes: 0 additions & 2 deletions ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

void external_flash_setup(void) {
// Do not reset the external flash write-protect and hold pins high
never_reset_pin_number(PIN_PB22);
never_reset_pin_number(PIN_PB23);

// note: using output instead of input+pullups because the pullups are a little weak
// Set the WP pin high
Expand Down
4 changes: 0 additions & 4 deletions ports/atmel-samd/boards/uchip/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@

void board_init(void) {
// BOOST_ENABLE
never_reset_pin_number(PIN_PA14);
// VEXT_SELECT
never_reset_pin_number(PIN_PA15);
// USB_DETECT
never_reset_pin_number(PIN_PA28);
// USB_HOST_EN
never_reset_pin_number(PIN_PA27);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ static mp_obj_t _bhb_read_adc(void);

static mp_obj_t _bhb_init_adc(void) {
claim_pin(&pin_PB08);
common_hal_never_reset_pin(&pin_PB08);

/* Enable the APB clock for the ADC. */
PM->APBCMASK.reg |= PM_APBCMASK_ADC;
Expand Down
9 changes: 0 additions & 9 deletions ports/atmel-samd/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
self->scl_pin = scl->number;
claim_pin(sda);
claim_pin(scl);

// Prevent bulk sercom reset from resetting us. The finalizer will instead.
never_reset_sercom(self->i2c_desc.device.hw);
}

bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
Expand All @@ -135,7 +132,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return;
}
allow_reset_sercom(self->i2c_desc.device.hw);

i2c_m_sync_disable(&self->i2c_desc);
i2c_m_sync_deinit(&self->i2c_desc);
Expand Down Expand Up @@ -242,8 +238,3 @@ mp_negative_errno_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint1

return common_hal_busio_i2c_read(self, addr, in_data, in_len);
}

void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
never_reset_pin_number(self->scl_pin);
never_reset_pin_number(self->sda_pin);
}
8 changes: 0 additions & 8 deletions ports/atmel-samd/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
spi_m_sync_enable(&self->spi_desc);
}

void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
never_reset_sercom(self->spi_desc.dev.prvt);

never_reset_pin_number(self->clock_pin);
never_reset_pin_number(self->MOSI_pin);
never_reset_pin_number(self->MISO_pin);
}

bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
return self->clock_pin == NO_PIN;
Expand All @@ -192,7 +185,6 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
if (common_hal_busio_spi_deinited(self)) {
return;
}
allow_reset_sercom(self->spi_desc.dev.prvt);

spi_m_sync_disable(&self->spi_desc);
spi_m_sync_deinit(&self->spi_desc);
Expand Down
16 changes: 0 additions & 16 deletions ports/atmel-samd/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,6 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
usart_async_enable(usart_desc_p);
}

void common_hal_busio_uart_never_reset(busio_uart_obj_t *self) {
for (size_t i = 0; i < MP_ARRAY_SIZE(sercom_insts); i++) {
const Sercom *sercom = sercom_insts[i];
Sercom *hw = (Sercom *)(self->usart_desc.device.hw);

// Reserve pins for active UART only
if (sercom == hw) {
never_reset_sercom(hw);
never_reset_pin_number(self->rx_pin);
never_reset_pin_number(self->tx_pin);
never_reset_pin_number(self->rts_pin);
never_reset_pin_number(self->cts_pin);
}
}
return;
}

bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
return self->rx_pin == NO_PIN && self->tx_pin == NO_PIN;
Expand Down
Loading
Loading