Skip to content

Commit 6425e93

Browse files
authored
Merge pull request #6289 from stonehippo/samd51_mm_flash
Samd51 mm flash
2 parents 87b3998 + a068b6b commit 6425e93

File tree

7 files changed

+39
-2
lines changed

7 files changed

+39
-2
lines changed

main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "supervisor/shared/workflow.h"
6363
#include "supervisor/usb.h"
6464
#include "supervisor/workflow.h"
65+
#include "supervisor/shared/external_flash/external_flash.h"
6566

6667
#include "shared-bindings/microcontroller/__init__.h"
6768
#include "shared-bindings/microcontroller/Processor.h"
@@ -836,6 +837,12 @@ int __attribute__((used)) main(void) {
836837
// Start the debug serial
837838
serial_early_init();
838839

840+
#if !INTERNAL_FLASH_FILESYSTEM
841+
// Set up anything that might need to get done before we try to use SPI flash
842+
// This is needed for some boards where flash relies on GPIO setup to work
843+
external_flash_setup();
844+
#endif
845+
839846
// Create a new filesystem only if we're not in a safe mode.
840847
// A power brownout here could make it appear as if there's
841848
// no SPI flash filesystem, and we might erase the existing one.

ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include "supervisor/board.h"
2828
#include "mpconfigboard.h"
29+
#include "common-hal/microcontroller/Pin.h"
30+
#include "hal/include/hal_gpio.h"
31+
#include "supervisor/shared/external_flash/external_flash.h"
2932

3033
void board_init(void) {
3134
}
@@ -39,3 +42,20 @@ void reset_board(void) {
3942

4043
void board_deinit(void) {
4144
}
45+
46+
void external_flash_setup(void) {
47+
// Do not reset the external flash write-protect and hold pins high
48+
never_reset_pin_number(PIN_PB22);
49+
never_reset_pin_number(PIN_PB23);
50+
51+
// note: using output instead of input+pullups because the pullups are a little weak
52+
// Set the WP pin high
53+
gpio_set_pin_function(PIN_PB22, GPIO_PIN_FUNCTION_OFF);
54+
gpio_set_pin_direction(PIN_PB22, GPIO_DIRECTION_OUT);
55+
gpio_set_pin_level(PIN_PB22, true);
56+
57+
// Set the HOLD pin high
58+
gpio_set_pin_function(PIN_PB23, GPIO_PIN_FUNCTION_OFF);
59+
gpio_set_pin_direction(PIN_PB23, GPIO_DIRECTION_OUT);
60+
gpio_set_pin_level(PIN_PB23, true);
61+
}

ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
// USB is always used internally so skip the pin objects for it.
2828
#define IGNORE_PIN_PA24 1
2929
#define IGNORE_PIN_PA25 1
30+
31+
// The external flash chip has WP (write-protect) and hold pins we should ignore
32+
#define IGNORE_PIN_PB22
33+
#define IGNORE_PIN_PB23

py/circuitpy_mpconfig.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ CFLAGS += -DMICROPY_PY_USELECT=$(MICROPY_PY_USELECT)
4949
MICROPY_PY_USELECT_SELECT ?= $(MICROPY_PY_USELECT)
5050
CFLAGS += -DMICROPY_PY_USELECT_SELECT=$(MICROPY_PY_USELECT_SELECT)
5151

52-
5352
CIRCUITPY_AESIO ?= $(CIRCUITPY_FULL_BUILD)
5453
CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)
5554

supervisor/board.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ void reset_board(void);
4747
// disabling USB, BLE or flash) because CircuitPython may continue to run.
4848
void board_deinit(void);
4949

50-
5150
#endif // MICROPY_INCLUDED_SUPERVISOR_BOARD_H

supervisor/shared/external_flash/external_flash.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,6 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num,
588588
}
589589
return 0; // success
590590
}
591+
592+
void MP_WEAK external_flash_setup(void) {
593+
}

supervisor/shared/external_flash/external_flash.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@
4747

4848
void supervisor_external_flash_flush(void);
4949

50+
// Configure anything that needs to get set up before the external flash
51+
// is init'ed. For example, if GPIO needs to be configured to enable the
52+
// flash chip, as is the case on some boards.
53+
void external_flash_setup(void);
54+
5055
#endif // MICROPY_INCLUDED_SUPERVISOR_SHARED_EXTERNAL_FLASH_EXTERNAL_FLASH_H

0 commit comments

Comments
 (0)