Skip to content

Samd51 mm flash #6289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 18, 2022
Merged
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
7 changes: 7 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion py/circuitpy_mpconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion supervisor/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions supervisor/shared/external_flash/external_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
5 changes: 5 additions & 0 deletions supervisor/shared/external_flash/external_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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