summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2018-02-16 17:22:33 -0800
committerScott Shawcroft <scott.shawcroft@gmail.com>2018-02-19 14:02:04 -0800
commitf20d5723aab3e6b5eea316235767c5e28a2dac2d (patch)
tree5b715f70fef8f03f001d6f5af28fee3641c402fb
parent4710a2adba74cfaff4faf1aa8e2a490ef21a9ce5 (diff)
Reorganize things. Reading jdec works.
-rw-r--r--ports/atmel-samd/Makefile4
-rw-r--r--ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h6
-rw-r--r--ports/atmel-samd/external_flash/common_commands.h40
-rw-r--r--ports/atmel-samd/external_flash/devices/AT25DF081A.h (renamed from ports/atmel-samd/boards/flash_AT25DF081A.h)0
-rw-r--r--ports/atmel-samd/external_flash/devices/GD25Q16C.h (renamed from ports/atmel-samd/boards/flash_GD25Q16C.h)0
-rw-r--r--ports/atmel-samd/external_flash/devices/S25FL064L.h (renamed from ports/atmel-samd/boards/flash_S25FL064L.h)0
-rw-r--r--ports/atmel-samd/external_flash/devices/S25FL116K.h54
-rw-r--r--ports/atmel-samd/external_flash/devices/S25FL216K.h (renamed from ports/atmel-samd/boards/flash_S25FL216K.h)0
-rw-r--r--ports/atmel-samd/external_flash/devices/W25Q32BV.h (renamed from ports/atmel-samd/boards/flash_W25Q32BV.h)0
-rw-r--r--ports/atmel-samd/external_flash/devices/W25Q80DV.h (renamed from ports/atmel-samd/boards/flash_W25Q80DV.h)0
-rw-r--r--ports/atmel-samd/external_flash/external_flash.c (renamed from ports/atmel-samd/external_flash.c)34
-rw-r--r--ports/atmel-samd/external_flash/external_flash.h (renamed from ports/atmel-samd/external_flash.h)0
-rw-r--r--ports/atmel-samd/external_flash/qspi_flash.c153
-rw-r--r--ports/atmel-samd/external_flash/spi_flash.c (renamed from ports/atmel-samd/spi_flash.c)0
-rw-r--r--ports/atmel-samd/external_flash/spi_flash_api.h (renamed from ports/atmel-samd/spi_flash_api.h)4
-rw-r--r--ports/atmel-samd/qspi_flash.c74
16 files changed, 265 insertions, 104 deletions
diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile
index abf5bf12e..a5d1fd7c0 100644
--- a/ports/atmel-samd/Makefile
+++ b/ports/atmel-samd/Makefile
@@ -252,10 +252,10 @@ ifeq ($(INTERNAL_FLASH_FILESYSTEM),1)
SRC_C += internal_flash.c
endif
ifeq ($(SPI_FLASH_FILESYSTEM),1)
-SRC_C += external_flash.c spi_flash.c
+SRC_C += external_flash/external_flash.c external_flash/spi_flash.c
endif
ifeq ($(QSPI_FLASH_FILESYSTEM),1)
-SRC_C += external_flash.c qspi_flash.c
+SRC_C += external_flash/external_flash.c external_flash/qspi_flash.c
endif
SRC_COMMON_HAL = \
diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h
index fdf98625e..6ced2ca70 100644
--- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h
@@ -40,7 +40,7 @@
#define AUTORESET_DELAY_MS 500
-#include "external_flash.h"
+#include "external_flash/external_flash.h"
// If you change this, then make sure to update the linker scripts as well to
// make sure you don't overwrite code
@@ -49,5 +49,5 @@
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
-#include "flash_S25FL216K.h"
-#include "flash_GD25Q16C.h"
+#include "external_flash/devices/S25FL216K.h"
+#include "external_flash/devices/GD25Q16C.h"
diff --git a/ports/atmel-samd/external_flash/common_commands.h b/ports/atmel-samd/external_flash/common_commands.h
new file mode 100644
index 000000000..ca1e87782
--- /dev/null
+++ b/ports/atmel-samd/external_flash/common_commands.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013, 2014 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_COMMON_COMMANDS_H
+#define MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_COMMON_COMMANDS_H
+
+#define CMD_READ_JEDEC_ID 0x9f
+#define CMD_READ_DATA 0x03
+#define CMD_SECTOR_ERASE 0x20
+// #define CMD_SECTOR_ERASE CMD_READ_JEDEC_ID
+#define CMD_DISABLE_WRITE 0x04
+#define CMD_ENABLE_WRITE 0x06
+#define CMD_PAGE_PROGRAM 0x02
+// #define CMD_PAGE_PROGRAM CMD_READ_JEDEC_ID
+#define CMD_READ_STATUS 0x05
+#define CMD_WRITE_STATUS_BYTE1 0x01
+
+#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_COMMON_COMMANDS_H
diff --git a/ports/atmel-samd/boards/flash_AT25DF081A.h b/ports/atmel-samd/external_flash/devices/AT25DF081A.h
index ba0fc6659..ba0fc6659 100644
--- a/ports/atmel-samd/boards/flash_AT25DF081A.h
+++ b/ports/atmel-samd/external_flash/devices/AT25DF081A.h
diff --git a/ports/atmel-samd/boards/flash_GD25Q16C.h b/ports/atmel-samd/external_flash/devices/GD25Q16C.h
index 90ec6de5c..90ec6de5c 100644
--- a/ports/atmel-samd/boards/flash_GD25Q16C.h
+++ b/ports/atmel-samd/external_flash/devices/GD25Q16C.h
diff --git a/ports/atmel-samd/boards/flash_S25FL064L.h b/ports/atmel-samd/external_flash/devices/S25FL064L.h
index 40cfa4cf0..40cfa4cf0 100644
--- a/ports/atmel-samd/boards/flash_S25FL064L.h
+++ b/ports/atmel-samd/external_flash/devices/S25FL064L.h
diff --git a/ports/atmel-samd/external_flash/devices/S25FL116K.h b/ports/atmel-samd/external_flash/devices/S25FL116K.h
new file mode 100644
index 000000000..4928bd04e
--- /dev/null
+++ b/ports/atmel-samd/external_flash/devices/S25FL116K.h
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL116K_H
+#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL116K_H
+
+// Settings for the Cypress (was Spansion) S25FL116K 2MiB SPI flash.
+// Datasheet: http://www.cypress.com/file/196886/download
+
+// The total flash size in bytes.
+#define SPI_FLASH_TOTAL_SIZE (1 << 21) // 2 MiB
+
+// The size of the smallest erase unit thats erased with command 0x20.
+#define SPI_FLASH_ERASE_SIZE (1 << 12) // 4 KiB
+
+// The size of a page that is programmed with page program command 0x02.
+#define SPI_FLASH_PAGE_SIZE (256) // 256 bytes
+
+// These are the first three response bytes to the JEDEC ID command 0x9f that is
+// used to confirm we're talking to the flash we expect.
+#ifndef SPI_FLASH_JEDEC_MANUFACTURER
+#define SPI_FLASH_JEDEC_MANUFACTURER 0x01
+#define SPI_FLASH_SECTOR_PROTECTION false
+#else
+#define SPI_FLASH_JEDEC_MANUFACTURER_2 0x01
+#define SPI_FLASH_SECTOR_PROTECTION_2 false
+#endif
+#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
+#define SPI_FLASH_JEDEC_CAPACITY 0x15
+
+#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL216K_H
diff --git a/ports/atmel-samd/boards/flash_S25FL216K.h b/ports/atmel-samd/external_flash/devices/S25FL216K.h
index 61b6b7514..61b6b7514 100644
--- a/ports/atmel-samd/boards/flash_S25FL216K.h
+++ b/ports/atmel-samd/external_flash/devices/S25FL216K.h
diff --git a/ports/atmel-samd/boards/flash_W25Q32BV.h b/ports/atmel-samd/external_flash/devices/W25Q32BV.h
index ae730fc6a..ae730fc6a 100644
--- a/ports/atmel-samd/boards/flash_W25Q32BV.h
+++ b/ports/atmel-samd/external_flash/devices/W25Q32BV.h
diff --git a/ports/atmel-samd/boards/flash_W25Q80DV.h b/ports/atmel-samd/external_flash/devices/W25Q80DV.h
index 1e8003867..1e8003867 100644
--- a/ports/atmel-samd/boards/flash_W25Q80DV.h
+++ b/ports/atmel-samd/external_flash/devices/W25Q80DV.h
diff --git a/ports/atmel-samd/external_flash.c b/ports/atmel-samd/external_flash/external_flash.c
index 45406462d..c046047e4 100644
--- a/ports/atmel-samd/external_flash.c
+++ b/ports/atmel-samd/external_flash/external_flash.c
@@ -28,6 +28,8 @@
#include <stdint.h>
#include <string.h>
+#include "external_flash/spi_flash_api.h"
+#include "external_flash/common_commands.h"
#include "extmod/vfs.h"
#include "extmod/vfs_fat.h"
#include "py/misc.h"
@@ -35,7 +37,6 @@
#include "py/runtime.h"
#include "lib/oofatfs/ff.h"
#include "peripherals.h"
-#include "spi_flash_api.h"
#include "supervisor/shared/rgb_led_status.h"
//#include "shared_dma.h"
@@ -47,17 +48,6 @@
#define NO_SECTOR_LOADED 0xFFFFFFFF
-#define CMD_READ_JEDEC_ID 0x9f
-#define CMD_READ_DATA 0x03
-#define CMD_SECTOR_ERASE 0x20
-// #define CMD_SECTOR_ERASE CMD_READ_JEDEC_ID
-#define CMD_DISABLE_WRITE 0x04
-#define CMD_ENABLE_WRITE 0x06
-#define CMD_PAGE_PROGRAM 0x02
-// #define CMD_PAGE_PROGRAM CMD_READ_JEDEC_ID
-#define CMD_READ_STATUS 0x05
-#define CMD_WRITE_STATUS_BYTE1 0x01
-
static bool spi_flash_is_initialised = false;
struct spi_m_sync_descriptor spi_flash_desc;
@@ -74,20 +64,18 @@ static uint32_t dirty_mask;
// Wait until both the write enable and write in progress bits have cleared.
static bool wait_for_flash_ready(void) {
- uint8_t read_status_request[2] = {CMD_READ_STATUS, 0x00};
- uint8_t read_status_response[2] = {0x00, 0x00};
+ uint8_t read_status_response[1] = {0x00};
bool ok = true;
// Both the write enable and write in progress bits should be low.
do {
- ok = spi_flash_command(read_status_request, read_status_response, 2);
- } while (ok && (read_status_response[1] & 0x3) != 0);
+ ok = spi_flash_read_command(CMD_READ_STATUS, read_status_response, 1);
+ } while (ok && (read_status_response[0] & 0x3) != 0);
return ok;
}
// Turn on the write enable bit so we can program and erase the flash.
static bool write_enable(void) {
- uint8_t enable_write_request[1] = {CMD_ENABLE_WRITE};
- return spi_flash_command(enable_write_request, 0, 1);
+ return spi_flash_command(CMD_ENABLE_WRITE);
}
// Read data_length's worth of bytes starting at address into data.
@@ -207,9 +195,8 @@ void external_flash_init(void) {
gpio_set_pin_level(MICROPY_HW_LED_MSC, false);
#endif
- uint8_t jedec_id_request[4] = {CMD_READ_JEDEC_ID, 0x00, 0x00, 0x00};
uint8_t jedec_id_response[4] = {0x00, 0x00, 0x00, 0x00};
- spi_flash_command(jedec_id_request, jedec_id_response, 4);
+ spi_flash_read_command(CMD_READ_JEDEC_ID, jedec_id_response, 4);
uint8_t manufacturer = jedec_id_response[1];
if ((jedec_id_response[1] == SPI_FLASH_JEDEC_MANUFACTURER
@@ -234,13 +221,12 @@ void external_flash_init(void) {
write_enable();
// Turn off sector protection
- uint8_t disable_protect_request[2] = {CMD_WRITE_STATUS_BYTE1, 0x00};
- spi_flash_command(disable_protect_request, NULL, 2);
+ uint8_t data[1] = {0x00};
+ spi_flash_write_command(CMD_WRITE_STATUS_BYTE1, data, 1);
}
// Turn off writes in case this is a microcontroller only reset.
- uint8_t disable_write_request[1] = {CMD_DISABLE_WRITE};
- spi_flash_command(disable_write_request, NULL, 1);
+ spi_flash_command(CMD_DISABLE_WRITE);
wait_for_flash_ready();
diff --git a/ports/atmel-samd/external_flash.h b/ports/atmel-samd/external_flash/external_flash.h
index 5a43b10c8..5a43b10c8 100644
--- a/ports/atmel-samd/external_flash.h
+++ b/ports/atmel-samd/external_flash/external_flash.h
diff --git a/ports/atmel-samd/external_flash/qspi_flash.c b/ports/atmel-samd/external_flash/qspi_flash.c
new file mode 100644
index 000000000..42d4e5a42
--- /dev/null
+++ b/ports/atmel-samd/external_flash/qspi_flash.c
@@ -0,0 +1,153 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016, 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "spi_flash_api.h"
+
+#include <stdint.h>
+#include <string.h>
+
+#include "external_flash/common_commands.h"
+
+#include "atmel_start_pins.h"
+#include "hal_gpio.h"
+
+bool spi_flash_command(uint8_t command) {
+ QSPI->INSTRCTRL.bit.INSTR = command;
+
+ QSPI->INSTRFRAME.reg = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI |
+ QSPI_INSTRFRAME_ADDRLEN_24BITS |
+ QSPI_INSTRFRAME_TFRTYPE_READ |
+ QSPI_INSTRFRAME_INSTREN;
+
+ QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
+
+ while( !QSPI->INTFLAG.bit.INSTREND );
+
+ QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
+
+ return true;
+}
+
+bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) {
+ QSPI->INSTRCTRL.bit.INSTR = command;
+
+ QSPI->INSTRFRAME.reg = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI |
+ QSPI_INSTRFRAME_ADDRLEN_24BITS |
+ QSPI_INSTRFRAME_TFRTYPE_READ |
+ QSPI_INSTRFRAME_INSTREN |
+ QSPI_INSTRFRAME_DATAEN;
+
+ memcpy(response, (uint8_t *) QSPI_AHB, length);
+
+ QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
+
+ while( !QSPI->INTFLAG.bit.INSTREND );
+
+ QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
+
+ return true;
+}
+
+bool spi_flash_write_command(uint8_t command, uint8_t* data, uint32_t length) {
+ QSPI->INSTRCTRL.bit.INSTR = command;
+
+ QSPI->INSTRFRAME.reg = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI |
+ QSPI_INSTRFRAME_ADDRLEN_24BITS |
+ QSPI_INSTRFRAME_TFRTYPE_WRITE |
+ QSPI_INSTRFRAME_INSTREN;
+
+ if (data != NULL) {
+ QSPI->INSTRFRAME.bit.DATAEN = true;
+
+ memcpy((uint8_t *) QSPI_AHB, data, length);
+ }
+
+ QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
+
+ while( !QSPI->INTFLAG.bit.INSTREND );
+
+ QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
+
+ return true;
+}
+
+bool spi_flash_sector_command(uint8_t command, uint32_t address) {
+// QSPI->INSTRCTRL.bit.INSTR = command;
+// QSPI->INSTRADDR.reg = addr;
+// uint32_t iframe = QSPI->INSTRFRAME.reg;
+//
+// iframe = QSPI_INSTRFRAME_WIDTH(instr->ioFormat) | instr->options |
+// QSPI_INSTRFRAME_OPTCODELEN(instr->opcodeLen) | (instr->addrLen << QSPI_INSTRFRAME_ADDRLEN_Pos) |
+// ( instr->continuousRead << QSPI_INSTRFRAME_CRMODE_Pos) | QSPI_INSTRFRAME_TFRTYPE(instr->type) | QSPI_INSTRFRAME_DUMMYLEN(instr->dummylen);
+//
+// QSPI->INSTRFRAME.reg = iframe;
+ return true;
+}
+
+bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length) {
+ return true;
+}
+
+bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length) {
+ return true;
+}
+
+
+void spi_flash_init(void) {
+ MCLK->APBCMASK.bit.QSPI_ = true;
+ MCLK->AHBMASK.bit.QSPI_ = true;
+ MCLK->AHBMASK.bit.QSPI_2X_ = false; // Only true if we are doing DDR.
+
+ QSPI->CTRLA.reg = QSPI_CTRLA_SWRST;
+ // We don't need to wait because we're running as fast as the CPU.
+
+ QSPI->BAUD.bit.BAUD = 10;
+ QSPI->CTRLB.reg = QSPI_CTRLB_MODE_MEMORY |
+ QSPI_CTRLB_DATALEN_8BITS |
+ QSPI_CTRLB_CSMODE_LASTXFER;
+
+ QSPI->CTRLA.bit.ENABLE = 1;
+
+ // The QSPI is only connected to one set of pins in the SAMD51 so we can hard code it.
+ uint32_t pins[6] = {PIN_PA08, PIN_PA09, PIN_PA10, PIN_PA11, PIN_PB10, PIN_PB11};
+ for (uint8_t i = 0; i < 6; i++) {
+ gpio_set_pin_direction(pins[i], GPIO_DIRECTION_IN);
+ gpio_set_pin_pull_mode(pins[i], GPIO_PULL_OFF);
+ gpio_set_pin_function(pins[i], GPIO_PIN_FUNCTION_H);
+ }
+
+ // Verify that QSPI mode is enabled.
+ uint8_t status;
+ spi_flash_read_command(0x35, &status, 1);
+
+ if ((status & 0x2) == 0) {
+ uint8_t full_status[3] = { 0, status | 0x2, 0x70};
+ spi_flash_command(CMD_ENABLE_WRITE);
+ spi_flash_write_command(0x01, full_status, 3);
+ }
+
+ asm("nop");
+}
diff --git a/ports/atmel-samd/spi_flash.c b/ports/atmel-samd/external_flash/spi_flash.c
index 9695067f1..9695067f1 100644
--- a/ports/atmel-samd/spi_flash.c
+++ b/ports/atmel-samd/external_flash/spi_flash.c
diff --git a/ports/atmel-samd/spi_flash_api.h b/ports/atmel-samd/external_flash/spi_flash_api.h
index d758faa77..b858ff0ea 100644
--- a/ports/atmel-samd/spi_flash_api.h
+++ b/ports/atmel-samd/external_flash/spi_flash_api.h
@@ -31,7 +31,9 @@
// This API is implemented for both normal SPI peripherals and QSPI peripherals.
-bool spi_flash_command(uint8_t* request, uint8_t* response, uint32_t length);
+bool spi_flash_command(uint8_t command);
+bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length);
+bool spi_flash_write_command(uint8_t command, uint8_t* data, uint32_t length);
bool spi_flash_sector_command(uint8_t command, uint32_t address);
bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length);
bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length);
diff --git a/ports/atmel-samd/qspi_flash.c b/ports/atmel-samd/qspi_flash.c
deleted file mode 100644
index 3fa53a898..000000000
--- a/ports/atmel-samd/qspi_flash.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2016, 2017 Scott Shawcroft for Adafruit Industries
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "spi_flash_api.h"
-
-#include <stdint.h>
-
-#include "atmel_start_pins.h"
-#include "hal_gpio.h"
-
-bool spi_flash_command(uint8_t* request, uint8_t* response, uint32_t length) {
- return true;
-}
-
-bool spi_flash_sector_command(uint8_t command, uint32_t address) {
- return true;
-}
-
-bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length) {
- return true;
-}
-
-bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length) {
- return true;
-}
-
-
-void spi_flash_init(void) {
- MCLK->APBCMASK.bit.QSPI_ = true;
- MCLK->AHBMASK.bit.QSPI_ = true;
- MCLK->AHBMASK.bit.QSPI_2X_ = false; // Only true if we are doing DDR.
-
- QSPI->CTRLA.reg = QSPI_CTRLA_SWRST;
- // We don't need to wait because we're running as fast as the CPU.
-
- QSPI->BAUD.bit.BAUD = 2;
- QSPI->CTRLB.reg = QSPI_CTRLB_MODE_MEMORY |
- QSPI_CTRLB_CSMODE_NORELOAD |
- QSPI_CTRLB_DATALEN_8BITS |
- QSPI_CTRLB_CSMODE_LASTXFER;
-
- QSPI->CTRLA.bit.ENABLE = 1;
-
- // The QSPI is only connected to one set of pins in the SAMD51 so we can hard code it.
- uint32_t pins[6] = {PIN_PA08, PIN_PA09, PIN_PA10, PIN_PA11, PIN_PB10, PIN_PB11};
- for (uint8_t i = 0; i < 6; i++) {
- gpio_set_pin_direction(pins[i], GPIO_DIRECTION_IN);
- gpio_set_pin_pull_mode(pins[i], GPIO_PULL_OFF);
- gpio_set_pin_function(pins[i], GPIO_PIN_FUNCTION_H);
- }
-}