diff --git a/main.c b/main.c index ba6950e34c..a3cc01d165 100644 --- a/main.c +++ b/main.c @@ -62,6 +62,7 @@ #include "supervisor/shared/workflow.h" #include "supervisor/usb.h" #include "supervisor/workflow.h" +#include "supervisor/shared/external_flash/external_flash.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Processor.h" @@ -836,6 +837,12 @@ int __attribute__((used)) main(void) { // Start the debug serial serial_early_init(); + #if !INTERNAL_FLASH_FILESYSTEM + // Set up anything that might need to get done before we try to use SPI flash + // This is needed for some boards where flash relies on GPIO setup to work + external_flash_setup(); + #endif + // Create a new filesystem only if we're not in a safe mode. // A power brownout here could make it appear as if there's // no SPI flash filesystem, and we might erase the existing one. diff --git a/ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c b/ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c index 289d68af29..9e862b3c01 100644 --- a/ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c +++ b/ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c @@ -26,6 +26,9 @@ #include "supervisor/board.h" #include "mpconfigboard.h" +#include "common-hal/microcontroller/Pin.h" +#include "hal/include/hal_gpio.h" +#include "supervisor/shared/external_flash/external_flash.h" void board_init(void) { } @@ -39,3 +42,20 @@ void reset_board(void) { void board_deinit(void) { } + +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 + gpio_set_pin_function(PIN_PB22, GPIO_PIN_FUNCTION_OFF); + gpio_set_pin_direction(PIN_PB22, GPIO_DIRECTION_OUT); + gpio_set_pin_level(PIN_PB22, true); + + // Set the HOLD pin high + gpio_set_pin_function(PIN_PB23, GPIO_PIN_FUNCTION_OFF); + gpio_set_pin_direction(PIN_PB23, GPIO_DIRECTION_OUT); + gpio_set_pin_level(PIN_PB23, true); +} diff --git a/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h b/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h index 3c4ef44b88..15fbcc45de 100644 --- a/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h +++ b/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h @@ -27,3 +27,7 @@ // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 + +// The external flash chip has WP (write-protect) and hold pins we should ignore +#define IGNORE_PIN_PB22 +#define IGNORE_PIN_PB23 diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 081048181e..535bd2f698 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -49,7 +49,6 @@ CFLAGS += -DMICROPY_PY_USELECT=$(MICROPY_PY_USELECT) MICROPY_PY_USELECT_SELECT ?= $(MICROPY_PY_USELECT) CFLAGS += -DMICROPY_PY_USELECT_SELECT=$(MICROPY_PY_USELECT_SELECT) - CIRCUITPY_AESIO ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO) diff --git a/supervisor/board.h b/supervisor/board.h index 605c16f5dc..e3f0af79a3 100644 --- a/supervisor/board.h +++ b/supervisor/board.h @@ -47,5 +47,4 @@ void reset_board(void); // disabling USB, BLE or flash) because CircuitPython may continue to run. void board_deinit(void); - #endif // MICROPY_INCLUDED_SUPERVISOR_BOARD_H diff --git a/supervisor/shared/external_flash/external_flash.c b/supervisor/shared/external_flash/external_flash.c index 33d618276c..7da45fdc99 100644 --- a/supervisor/shared/external_flash/external_flash.c +++ b/supervisor/shared/external_flash/external_flash.c @@ -588,3 +588,6 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, } return 0; // success } + +void MP_WEAK external_flash_setup(void) { +} diff --git a/supervisor/shared/external_flash/external_flash.h b/supervisor/shared/external_flash/external_flash.h index db5c677eb0..7966b64674 100644 --- a/supervisor/shared/external_flash/external_flash.h +++ b/supervisor/shared/external_flash/external_flash.h @@ -47,4 +47,9 @@ void supervisor_external_flash_flush(void); +// Configure anything that needs to get set up before the external flash +// is init'ed. For example, if GPIO needs to be configured to enable the +// flash chip, as is the case on some boards. +void external_flash_setup(void); + #endif // MICROPY_INCLUDED_SUPERVISOR_SHARED_EXTERNAL_FLASH_EXTERNAL_FLASH_H