Merge pull request #654 from tannewt/structify_flash_devices
Structify flash devices
This commit is contained in:
commit
15b8455cc4
@ -38,7 +38,7 @@
|
||||
|
||||
#define SPEAKER_ENABLE_PIN (&pin_PA30)
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
@ -47,8 +47,13 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/S25FL216K.h"
|
||||
#include "external_flash/devices/GD25Q16C.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define CALIBRATE_CRYSTALLESS 1
|
||||
|
||||
|
@ -40,5 +40,10 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/S25FL216K.h"
|
||||
#include "external_flash/devices/GD25Q16C.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -42,4 +42,9 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/S25FL064L.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL064L
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -33,13 +33,16 @@
|
||||
#define MICROPY_PORT_B (PORT_PB22 | PORT_PB23 | PORT_PB03 )
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#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.
|
||||
// #define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/GD25Q16C.h"
|
||||
#include "external_flash/devices/W25Q16FW.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES W25Q16FW, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -34,8 +34,6 @@
|
||||
#define MICROPY_PORT_B (PORT_PB03 | PORT_PB22 | PORT_PB23)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#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.
|
||||
// #define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
@ -43,5 +41,10 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/S25FL216K.h"
|
||||
#include "external_flash/devices/GD25Q16C.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#define AUTORESET_DELAY_MS 500
|
||||
|
||||
#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
|
||||
// #define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
@ -29,5 +27,9 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/S25FL116K.h"
|
||||
#include "external_flash/devices/GD25Q16C.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 3
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL116K, S25FL216K, GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -54,5 +54,10 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/S25FL216K.h"
|
||||
#include "external_flash/devices/GD25Q16C.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -48,4 +48,9 @@
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices/W25Q32BV.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES W25Q32BV
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -41,5 +41,9 @@
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
//#include "external_flash/devices/W25Q32BV.h"
|
||||
#include "external_flash/devices/S25FL216K.h"
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
204
ports/atmel-samd/external_flash/devices.h
Normal file
204
ports/atmel-samd/external_flash/devices.h
Normal file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC
|
||||
*
|
||||
* 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_DEVICES_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t total_size;
|
||||
uint16_t start_up_time_us;
|
||||
|
||||
// Three response bytes to 0x9f JEDEC ID command.
|
||||
uint8_t manufacturer_id;
|
||||
uint8_t memory_type;
|
||||
uint8_t capacity;
|
||||
|
||||
// Max clock speed for all operations and the fastest read mode.
|
||||
uint8_t max_clock_speed_mhz;
|
||||
bool has_sector_protection : 1;
|
||||
|
||||
// Supports the 0x0b fast read command with 8 dummy cycles.
|
||||
bool supports_fast_read : 1;
|
||||
|
||||
// Supports the fast read, quad output command 0x6b with 8 dummy cycles.
|
||||
bool supports_qspi : 1;
|
||||
|
||||
// Requires quad enable set in status bit 9.
|
||||
bool has_quad_enable : 1;
|
||||
|
||||
// Supports the quad input page program command 0x32. This is known as 1-1-4 because it only
|
||||
// uses all four lines for data.
|
||||
bool supports_qspi_writes: 1;
|
||||
} external_flash_device;
|
||||
|
||||
// Settings for the Adesto Tech AT25DF081A 1MiB SPI flash. Its on the SAMD21
|
||||
// Xplained board.
|
||||
// Datasheet: https://www.adestotech.com/wp-content/uploads/doc8715.pdf
|
||||
#define AT25DF081A {\
|
||||
.total_size = (1 << 20), /* 1 MiB */ \
|
||||
.start_up_time_us = 10000, \
|
||||
.manufacturer_id = 0x1f, \
|
||||
.memory_type = 0x45, \
|
||||
.capacity = 0x01, \
|
||||
.max_clock_speed_mhz = 85, \
|
||||
.has_sector_protection = true, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = false, \
|
||||
.has_quad_enable = false, \
|
||||
.supports_qspi_writes = false, \
|
||||
}
|
||||
|
||||
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
|
||||
// Datasheet: http://www.gigadevice.com/wp-content/uploads/2017/12/DS-00086-GD25Q16C-Rev2.6.pdf
|
||||
#define GD25Q16C {\
|
||||
.total_size = (1 << 21), /* 2 MiB */ \
|
||||
.start_up_time_us = 5000, \
|
||||
.manufacturer_id = 0xc8, \
|
||||
.memory_type = 0x40, \
|
||||
.capacity = 0x15, \
|
||||
.max_clock_speed_mhz = 104, /* if we need 120 then we can turn on high performance mode */ \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = true, \
|
||||
.has_quad_enable = true, \
|
||||
.supports_qspi_writes = true, \
|
||||
}
|
||||
|
||||
// Settings for the Cypress (was Spansion) S25FL064L 8MiB SPI flash.
|
||||
// Datasheet: http://www.cypress.com/file/316661/download
|
||||
#define S25FL064L {\
|
||||
.total_size = (1 << 23), /* 8 MiB */ \
|
||||
.start_up_time_us = 300, \
|
||||
.manufacturer_id = 0x01, \
|
||||
.memory_type = 0x60, \
|
||||
.capacity = 0x17, \
|
||||
.max_clock_speed_mhz = 108, \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = true, \
|
||||
.has_quad_enable = true, \
|
||||
.supports_qspi_writes = true, \
|
||||
}
|
||||
|
||||
// Settings for the Cypress (was Spansion) S25FL116K 2MiB SPI flash.
|
||||
// Datasheet: http://www.cypress.com/file/196886/download
|
||||
#define S25FL116K {\
|
||||
.total_size = (1 << 21), /* 2 MiB */ \
|
||||
.start_up_time_us = 10000, \
|
||||
.manufacturer_id = 0x01, \
|
||||
.memory_type = 0x40, \
|
||||
.capacity = 0x15, \
|
||||
.max_clock_speed_mhz = 108, \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = true, \
|
||||
.has_quad_enable = true, \
|
||||
.supports_qspi_writes = false, \
|
||||
}
|
||||
|
||||
// Settings for the Cypress (was Spansion) S25FL216K 2MiB SPI flash.
|
||||
// Datasheet: http://www.cypress.com/file/197346/download
|
||||
#define S25FL216K {\
|
||||
.total_size = (1 << 21), /* 2 MiB */ \
|
||||
.start_up_time_us = 10000, \
|
||||
.manufacturer_id = 0x01, \
|
||||
.memory_type = 0x40, \
|
||||
.capacity = 0x15, \
|
||||
.max_clock_speed_mhz = 65, \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = false, \
|
||||
.has_quad_enable = false, \
|
||||
.supports_qspi_writes = false, \
|
||||
}
|
||||
|
||||
// Settings for the Winbond W25Q16FW 2MiB SPI flash.
|
||||
// Datasheet: https://www.winbond.com/resource-files/w25q16fw%20revj%2005182017%20sfdp.pdf
|
||||
#define W25Q16FW {\
|
||||
.total_size = (1 << 21), /* 2 MiB */ \
|
||||
.start_up_time_us = 5000, \
|
||||
.manufacturer_id = 0xef, \
|
||||
.memory_type = 0x60, \
|
||||
.capacity = 0x15, \
|
||||
.max_clock_speed_mhz = 133, \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = true, \
|
||||
.has_quad_enable = true, \
|
||||
.supports_qspi_writes = true, \
|
||||
}
|
||||
|
||||
// Settings for the Winbond W25Q16JV 2MiB SPI flash.
|
||||
// Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf
|
||||
#define W25Q16JV {\
|
||||
.total_size = (1 << 21), /* 2 MiB */ \
|
||||
.start_up_time_us = 5000, \
|
||||
.manufacturer_id = 0xef, \
|
||||
.memory_type = 0x40, \
|
||||
.capacity = 0x15, \
|
||||
.max_clock_speed_mhz = 133, \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = true, \
|
||||
.has_quad_enable = true, \
|
||||
.supports_qspi_writes = true, \
|
||||
}
|
||||
|
||||
// Settings for the Winbond W25Q32BV 2MiB SPI flash.
|
||||
// Datasheet: https://www.winbond.com/resource-files/w25q32bv_revi_100413_wo_automotive.pdf
|
||||
#define W25Q32BV {\
|
||||
.total_size = (1 << 22), /* 4 MiB */ \
|
||||
.start_up_time_us = 10000, \
|
||||
.manufacturer_id = 0xef, \
|
||||
.memory_type = 0x60, \
|
||||
.capacity = 0x16, \
|
||||
.max_clock_speed_mhz = 104, \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = true, \
|
||||
.has_quad_enable = true, \
|
||||
.supports_qspi_writes = false, \
|
||||
}
|
||||
|
||||
// Settings for the Winbond W25Q80DL 1MiB SPI flash.
|
||||
// Datasheet: https://www.winbond.com/resource-files/w25q80dv%20dl_revh_10022015.pdf
|
||||
#define W25Q80DL {\
|
||||
.total_size = (1 << 20), /* 1 MiB */ \
|
||||
.start_up_time_us = 5000, \
|
||||
.manufacturer_id = 0xef, \
|
||||
.memory_type = 0x60, \
|
||||
.capacity = 0x14, \
|
||||
.max_clock_speed_mhz = 104, \
|
||||
.has_sector_protection = false, \
|
||||
.supports_fast_read = true, \
|
||||
.supports_qspi = true, \
|
||||
.has_quad_enable = true, \
|
||||
.supports_qspi_writes = false, \
|
||||
}
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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_AT25DF081A_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_AT25DF081A_H
|
||||
|
||||
// Settings for the Adesto Tech AT25DF081A 1MiB SPI flash. Its on the SAMD21
|
||||
// Xplained board.
|
||||
// Datasheet: https://www.adestotech.com/wp-content/uploads/doc8715.pdf
|
||||
|
||||
// The total flash size in bytes.
|
||||
#define SPI_FLASH_TOTAL_SIZE (1 << 20) // 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. The data sheet calls
|
||||
// them something else so we just match it byte for byte.
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER 0x1F
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x45
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x01
|
||||
|
||||
#define SPI_FLASH_SECTOR_PROTECTION
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_AT25DF081A_H
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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_GD25Q16C_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H
|
||||
|
||||
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
|
||||
// Datasheet: http://www.gigadevice.com/product/download/410.html?locale=en_US
|
||||
|
||||
// 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
|
||||
|
||||
#ifndef SPI_FLASH_JEDEC_MANUFACTURER
|
||||
// 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.
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER 0xc8
|
||||
#define SPI_FLASH_SECTOR_PROTECTION true
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
|
||||
#else
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0xc8
|
||||
#define SPI_FLASH_SECTOR_PROTECTION_2 true
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE_2 0x40
|
||||
#endif
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x15
|
||||
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
||||
* Copyright (c) 2017 Dave Astels
|
||||
*
|
||||
* 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_S25FL064L_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL064L_H
|
||||
|
||||
// Settings for the Cypress (was Spansion) S25FL064L 8MiB SPI flash.
|
||||
// Datasheet: http://www.cypress.com/file/316661/download
|
||||
|
||||
// The total flash size in bytes.
|
||||
#define SPI_FLASH_TOTAL_SIZE (1 << 23) // 8 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
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x60
|
||||
#else
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0x013
|
||||
#define SPI_FLASH_SECTOR_PROTECTION_2 false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE_2 0x60
|
||||
#endif
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x17
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL216K_H
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
|
||||
#else
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0x01
|
||||
#define SPI_FLASH_SECTOR_PROTECTION_2 false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE_2 0x40
|
||||
#endif
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x15
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL216K_H
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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_S25FL216K_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL216K_H
|
||||
|
||||
// Settings for the Cypress (was Spansion) S25FL216K 2MiB SPI flash.
|
||||
// Datasheet: http://www.cypress.com/file/197346/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
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
|
||||
#else
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0x01
|
||||
#define SPI_FLASH_SECTOR_PROTECTION_2 false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE_2 0x40
|
||||
#endif
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x15
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_S25FL216K_H
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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_W25Q16FW_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_W25Q16FW_H
|
||||
|
||||
// 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 0xef
|
||||
#define SPI_FLASH_SECTOR_PROTECTION false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x60
|
||||
#else
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0xef
|
||||
#define SPI_FLASH_SECTOR_PROTECTION_2 false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE_2 0x60
|
||||
#endif
|
||||
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x15
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_W25Q16BV_H
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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_W25Q32BV_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_W25Q32BV_H
|
||||
|
||||
// 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 0xef
|
||||
#define SPI_FLASH_SECTOR_PROTECTION false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
|
||||
#else
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0xef
|
||||
#define SPI_FLASH_SECTOR_PROTECTION_2 false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE_2 0x40
|
||||
#endif
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x16
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_W25Q32BV_H
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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_W25Q80DV_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_W25Q80DV_H
|
||||
|
||||
// The total flash size in bytes.
|
||||
#define SPI_FLASH_TOTAL_SIZE (1 << 20) // 1 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 0xef
|
||||
#define SPI_FLASH_SECTOR_PROTECTION false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
|
||||
#else
|
||||
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0xef
|
||||
#define SPI_FLASH_SECTOR_PROTECTION_2 false
|
||||
#define SPI_FLASH_JEDEC_MEMORY_TYPE_2 0x40
|
||||
#endif
|
||||
#define SPI_FLASH_JEDEC_CAPACITY 0x14
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_W25Q80DV_H
|
@ -37,6 +37,7 @@
|
||||
#include "py/runtime.h"
|
||||
#include "lib/oofatfs/ff.h"
|
||||
#include "peripherals.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "supervisor/shared/rgb_led_status.h"
|
||||
|
||||
//#include "shared_dma.h"
|
||||
@ -48,20 +49,19 @@
|
||||
|
||||
#define NO_SECTOR_LOADED 0xFFFFFFFF
|
||||
|
||||
static bool spi_flash_is_initialised = false;
|
||||
|
||||
struct spi_m_sync_descriptor spi_flash_desc;
|
||||
|
||||
// The currently cached sector in the cache, ram or flash based.
|
||||
static uint32_t current_sector;
|
||||
|
||||
const external_flash_device possible_devices[EXTERNAL_FLASH_DEVICE_COUNT] = {EXTERNAL_FLASH_DEVICES};
|
||||
|
||||
static const external_flash_device* flash_device = NULL;
|
||||
|
||||
// Track which blocks (up to 32) in the current sector currently live in the
|
||||
// cache.
|
||||
static uint32_t dirty_mask;
|
||||
|
||||
// Address of the scratch flash sector.
|
||||
#define SCRATCH_SECTOR (SPI_FLASH_TOTAL_SIZE - SPI_FLASH_ERASE_SIZE)
|
||||
|
||||
// Wait until both the write enable and write in progress bits have cleared.
|
||||
static bool wait_for_flash_ready(void) {
|
||||
uint8_t read_status_response[1] = {0x00};
|
||||
@ -80,7 +80,7 @@ static bool write_enable(void) {
|
||||
|
||||
// Read data_length's worth of bytes starting at address into data.
|
||||
static bool read_flash(uint32_t address, uint8_t* data, uint32_t data_length) {
|
||||
if (!spi_flash_is_initialised) {
|
||||
if (flash_device == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (!wait_for_flash_ready()) {
|
||||
@ -93,7 +93,7 @@ static bool read_flash(uint32_t address, uint8_t* data, uint32_t data_length) {
|
||||
// that the sector that address resides in has already been erased. So make sure
|
||||
// to run erase_sector.
|
||||
static bool write_flash(uint32_t address, const uint8_t* data, uint32_t data_length) {
|
||||
if (!spi_flash_is_initialised) {
|
||||
if (flash_device == NULL) {
|
||||
return false;
|
||||
}
|
||||
// Don't bother writing if the data is all 1s. Thats equivalent to the flash
|
||||
@ -168,12 +168,13 @@ static bool erase_sector(uint32_t sector_address) {
|
||||
// Sector is really 24 bits.
|
||||
static bool copy_block(uint32_t src_address, uint32_t dest_address) {
|
||||
// Copy page by page to minimize RAM buffer.
|
||||
uint8_t buffer[SPI_FLASH_PAGE_SIZE];
|
||||
for (uint32_t i = 0; i < FILESYSTEM_BLOCK_SIZE / SPI_FLASH_PAGE_SIZE; i++) {
|
||||
if (!read_flash(src_address + i * SPI_FLASH_PAGE_SIZE, buffer, SPI_FLASH_PAGE_SIZE)) {
|
||||
uint16_t page_size = SPI_FLASH_PAGE_SIZE;
|
||||
uint8_t buffer[page_size];
|
||||
for (uint32_t i = 0; i < FILESYSTEM_BLOCK_SIZE / page_size; i++) {
|
||||
if (!read_flash(src_address + i * page_size, buffer, page_size)) {
|
||||
return false;
|
||||
}
|
||||
if (!write_flash(dest_address + i * SPI_FLASH_PAGE_SIZE, buffer, SPI_FLASH_PAGE_SIZE)) {
|
||||
if (!write_flash(dest_address + i * page_size, buffer, page_size)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -181,12 +182,41 @@ static bool copy_block(uint32_t src_address, uint32_t dest_address) {
|
||||
}
|
||||
|
||||
void external_flash_init(void) {
|
||||
if (spi_flash_is_initialised) {
|
||||
if (flash_device != NULL) {
|
||||
return;
|
||||
}
|
||||
uint8_t num_possible_devices = sizeof(*possible_devices) / sizeof(external_flash_device);
|
||||
|
||||
// Delay to give the SPI Flash time to get going.
|
||||
// TODO(tannewt): Only do this when we know power was applied vs a reset.
|
||||
uint16_t max_start_up_delay_us = 0;
|
||||
for (uint8_t i = 0; i < num_possible_devices; i++) {
|
||||
if (possible_devices[i].start_up_time_us > max_start_up_delay_us) {
|
||||
max_start_up_delay_us = possible_devices[i].start_up_time_us;
|
||||
}
|
||||
}
|
||||
common_hal_mcu_delay_us(max_start_up_delay_us);
|
||||
|
||||
spi_flash_init();
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < num_possible_devices; i++) {
|
||||
const external_flash_device* possible_device = &possible_devices[i];
|
||||
uint8_t jedec_id_response[3] = {0x00, 0x00, 0x00};
|
||||
spi_flash_read_command(CMD_READ_JEDEC_ID, jedec_id_response, 3);
|
||||
if (jedec_id_response[0] == possible_device->manufacturer_id &&
|
||||
jedec_id_response[1] == possible_device->memory_type &&
|
||||
jedec_id_response[2] == possible_device->capacity) {
|
||||
flash_device = possible_device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flash_device == NULL) {
|
||||
asm("bkpt");
|
||||
return;
|
||||
}
|
||||
|
||||
// Activity LED for flash writes.
|
||||
#ifdef MICROPY_HW_LED_MSC
|
||||
gpio_set_pin_function(SPI_FLASH_CS_PIN, GPIO_PIN_FUNCTION_OFF);
|
||||
@ -195,33 +225,7 @@ void external_flash_init(void) {
|
||||
gpio_set_pin_level(MICROPY_HW_LED_MSC, false);
|
||||
#endif
|
||||
|
||||
uint8_t jedec_id_response[3] = {0x00, 0x00, 0x00};
|
||||
spi_flash_read_command(CMD_READ_JEDEC_ID, jedec_id_response, 3);
|
||||
|
||||
uint8_t manufacturer = jedec_id_response[0];
|
||||
if ((jedec_id_response[0] == SPI_FLASH_JEDEC_MANUFACTURER
|
||||
#ifdef SPI_FLASH_JEDEC_MANUFACTURER_2
|
||||
|| jedec_id_response[0] == SPI_FLASH_JEDEC_MANUFACTURER_2
|
||||
#endif
|
||||
) &&
|
||||
(jedec_id_response[1] == SPI_FLASH_JEDEC_MEMORY_TYPE
|
||||
#ifdef SPI_FLASH_JEDEC_MANUFACTURER_2
|
||||
|| jedec_id_response[1] == SPI_FLASH_JEDEC_MEMORY_TYPE_2
|
||||
#endif
|
||||
) &&
|
||||
jedec_id_response[2] == SPI_FLASH_JEDEC_CAPACITY) {
|
||||
spi_flash_is_initialised = true;
|
||||
} else {
|
||||
// Unknown flash chip!
|
||||
spi_flash_is_initialised = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((manufacturer == SPI_FLASH_JEDEC_MANUFACTURER && SPI_FLASH_SECTOR_PROTECTION)
|
||||
#ifdef SPI_FLASH_JEDEC_MANUFACTURER_2
|
||||
|| (manufacturer == SPI_FLASH_JEDEC_MANUFACTURER_2 && SPI_FLASH_SECTOR_PROTECTION_2)
|
||||
#endif
|
||||
) {
|
||||
if (flash_device->has_sector_protection) {
|
||||
write_enable();
|
||||
|
||||
// Turn off sector protection
|
||||
@ -237,8 +241,6 @@ void external_flash_init(void) {
|
||||
current_sector = NO_SECTOR_LOADED;
|
||||
dirty_mask = 0;
|
||||
MP_STATE_VM(flash_ram_cache) = NULL;
|
||||
|
||||
spi_flash_is_initialised = true;
|
||||
}
|
||||
|
||||
// The size of each individual block.
|
||||
@ -250,7 +252,7 @@ uint32_t external_flash_get_block_size(void) {
|
||||
uint32_t external_flash_get_block_count(void) {
|
||||
// We subtract one erase sector size because we may use it as a staging area
|
||||
// for writes.
|
||||
return SPI_FLASH_PART1_START_BLOCK + (SPI_FLASH_TOTAL_SIZE - SPI_FLASH_ERASE_SIZE) / FILESYSTEM_BLOCK_SIZE;
|
||||
return SPI_FLASH_PART1_START_BLOCK + (flash_device->total_size - SPI_FLASH_ERASE_SIZE) / FILESYSTEM_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
// Flush the cache that was written to the scratch portion of flash. Only used
|
||||
@ -259,11 +261,12 @@ static bool flush_scratch_flash(void) {
|
||||
// First, copy out any blocks that we haven't touched from the sector we've
|
||||
// cached.
|
||||
bool copy_to_scratch_ok = true;
|
||||
uint32_t scratch_sector = flash_device->total_size - SPI_FLASH_ERASE_SIZE;
|
||||
for (uint8_t i = 0; i < SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE; i++) {
|
||||
if ((dirty_mask & (1 << i)) == 0) {
|
||||
copy_to_scratch_ok = copy_to_scratch_ok &&
|
||||
copy_block(current_sector + i * FILESYSTEM_BLOCK_SIZE,
|
||||
SCRATCH_SECTOR + i * FILESYSTEM_BLOCK_SIZE);
|
||||
scratch_sector + i * FILESYSTEM_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
if (!copy_to_scratch_ok) {
|
||||
@ -275,7 +278,7 @@ static bool flush_scratch_flash(void) {
|
||||
erase_sector(current_sector);
|
||||
// Finally, copy the new version into it.
|
||||
for (uint8_t i = 0; i < SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE; i++) {
|
||||
copy_block(SCRATCH_SECTOR + i * FILESYSTEM_BLOCK_SIZE,
|
||||
copy_block(scratch_sector + i * FILESYSTEM_BLOCK_SIZE,
|
||||
current_sector + i * FILESYSTEM_BLOCK_SIZE);
|
||||
}
|
||||
return true;
|
||||
@ -499,7 +502,7 @@ bool external_flash_read_block(uint8_t *dest, uint32_t block) {
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
uint32_t scratch_address = SCRATCH_SECTOR + block_index * FILESYSTEM_BLOCK_SIZE;
|
||||
uint32_t scratch_address = flash_device->total_size - SPI_FLASH_ERASE_SIZE + block_index * FILESYSTEM_BLOCK_SIZE;
|
||||
return read_flash(scratch_address, dest, FILESYSTEM_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
@ -536,7 +539,7 @@ bool external_flash_write_block(const uint8_t *data, uint32_t block) {
|
||||
spi_flash_flush_keep_cache(true);
|
||||
}
|
||||
if (MP_STATE_VM(flash_ram_cache) == NULL && !allocate_ram_cache()) {
|
||||
erase_sector(SCRATCH_SECTOR);
|
||||
erase_sector(flash_device->total_size - SPI_FLASH_ERASE_SIZE);
|
||||
wait_for_flash_ready();
|
||||
}
|
||||
current_sector = this_sector;
|
||||
@ -553,7 +556,7 @@ bool external_flash_write_block(const uint8_t *data, uint32_t block) {
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
uint32_t scratch_address = SCRATCH_SECTOR + block_index * FILESYSTEM_BLOCK_SIZE;
|
||||
uint32_t scratch_address = flash_device->total_size - SPI_FLASH_ERASE_SIZE + block_index * FILESYSTEM_BLOCK_SIZE;
|
||||
return write_flash(scratch_address, data, FILESYSTEM_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,10 @@
|
||||
// Erase sector size.
|
||||
#define SPI_FLASH_SECTOR_SIZE (0x1000 - 100)
|
||||
|
||||
// These are common across all NOR Flash.
|
||||
#define SPI_FLASH_ERASE_SIZE (1 << 12)
|
||||
#define SPI_FLASH_PAGE_SIZE (256)
|
||||
|
||||
#define SPI_FLASH_SYSTICK_MASK (0x1ff) // 512ms
|
||||
#define SPI_FLASH_IDLE_TICK(tick) (((tick) & SPI_FLASH_SYSTICK_MASK) == 2)
|
||||
|
||||
|
@ -167,7 +167,7 @@ void spi_flash_init(void) {
|
||||
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->BAUD.bit.BAUD = 1;
|
||||
QSPI->CTRLB.reg = QSPI_CTRLB_MODE_MEMORY |
|
||||
QSPI_CTRLB_DATALEN_8BITS |
|
||||
QSPI_CTRLB_CSMODE_LASTXFER;
|
||||
@ -191,6 +191,4 @@ void spi_flash_init(void) {
|
||||
spi_flash_command(CMD_ENABLE_WRITE);
|
||||
spi_flash_write_command(0x01, full_status, 3);
|
||||
}
|
||||
|
||||
asm("nop");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user