Structify flash device definitions.

This commit is contained in:
Scott Shawcroft 2018-02-28 19:15:54 -08:00
parent 568c04e6af
commit 2ab923862b
13 changed files with 264 additions and 512 deletions

View File

@ -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,8 @@
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
#include "external_flash/devices/S25FL216K.h"
#include "external_flash/devices/GD25Q16C.h"
#define EXTERNAL_FLASH_DEVICES 25FL216K, \
GD25Q16C
#define CALIBRATE_CRYSTALLESS 1

View File

@ -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 2
#define EXTERNAL_FLASH_DEVICES S25FL116K, GD25Q16C
#include "external_flash/external_flash.h"

View File

@ -0,0 +1,180 @@
/*
* 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 erase_size;
uint16_t page_size;
uint16_t start_up_time_us;
uint8_t manufacturer_id;
uint8_t memory_type;
uint8_t capacity;
uint8_t max_clock_speed_mhz;
bool has_sector_protection;
bool supports_qspi;
bool supports_qspi_writes;
} 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 */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 10000, \
.manufacturer_id = 0x1f, \
.memory_type = 0x45, \
.capacity = 0x01, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = true, \
.supports_qspi = true, \
.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 */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xc8, \
.memory_type = 0x40, \
.capacity = 0x15, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = true, \
.supports_qspi = true, \
.supports_qspi_writes = false, \
}
// 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 */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 300, \
.manufacturer_id = 0x01, \
.memory_type = 0x60, \
.capacity = 0x17, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = true, \
.supports_qspi = true, \
.supports_qspi_writes = false, \
}
// 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 */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 10000, \
.manufacturer_id = 0x01, \
.memory_type = 0x40, \
.capacity = 0x15, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = true, \
.supports_qspi = 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 */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 10000, \
.manufacturer_id = 0x01, \
.memory_type = 0x40, \
.capacity = 0x15, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = false, \
.supports_qspi = true, \
.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 */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
.memory_type = 0x60, \
.capacity = 0x15, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = false, \
.supports_qspi = true, \
.supports_qspi_writes = false, \
}
// 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 << 21), /* 2 MiB */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
.memory_type = 0x60, \
.capacity = 0x16, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = false, \
.supports_qspi = 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 */ \
.erase_size = (1 << 12), /* 4 KiB */ \
.page_size = 256, /*256 bytes */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
.memory_type = 0x60, \
.capacity = 0x14, \
.max_clock_speed_mhz = 104, \
.has_sector_protection = false, \
.supports_qspi = true, \
.supports_qspi_writes = false, \
}
#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;
external_flash_device possible_devices[EXTERNAL_FLASH_DEVICE_COUNT] = {EXTERNAL_FLASH_DEVICES};
static 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
@ -111,13 +111,13 @@ static bool write_flash(uint32_t address, const uint8_t* data, uint32_t data_len
for (uint32_t bytes_written = 0;
bytes_written < data_length;
bytes_written += SPI_FLASH_PAGE_SIZE) {
bytes_written += flash_device->page_size) {
if (!wait_for_flash_ready() || !write_enable()) {
return false;
}
if (!spi_flash_write_data(address + bytes_written, (uint8_t*) data + bytes_written,
SPI_FLASH_PAGE_SIZE)) {
flash_device->page_size)) {
return false;
}
}
@ -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 = flash_device->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++) {
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 - flash_device->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;
for (uint8_t i = 0; i < SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE; i++) {
uint32_t scratch_sector = flash_device->total_size - flash_device->erase_size;
for (uint8_t i = 0; i < flash_device->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) {
@ -274,8 +277,8 @@ static bool flush_scratch_flash(void) {
// Second, erase the current sector.
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,
for (uint8_t i = 0; i < flash_device->erase_size / FILESYSTEM_BLOCK_SIZE; i++) {
copy_block(scratch_sector + i * FILESYSTEM_BLOCK_SIZE,
current_sector + i * FILESYSTEM_BLOCK_SIZE);
}
return true;
@ -285,8 +288,8 @@ static bool flush_scratch_flash(void) {
// ram. Each page is allocated separately so that the GC doesn't need to provide
// one huge block. We can free it as we write if we want to also.
static bool allocate_ram_cache(void) {
uint8_t blocks_per_sector = SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE;
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / SPI_FLASH_PAGE_SIZE;
uint8_t blocks_per_sector = flash_device->erase_size / FILESYSTEM_BLOCK_SIZE;
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / flash_device->page_size;
MP_STATE_VM(flash_ram_cache) = m_malloc_maybe(blocks_per_sector * pages_per_block * sizeof(uint32_t), false);
if (MP_STATE_VM(flash_ram_cache) == NULL) {
return false;
@ -298,7 +301,7 @@ static bool allocate_ram_cache(void) {
bool success = true;
for (i = 0; i < blocks_per_sector; i++) {
for (j = 0; j < pages_per_block; j++) {
uint8_t *page_cache = m_malloc_maybe(SPI_FLASH_PAGE_SIZE, false);
uint8_t *page_cache = m_malloc_maybe(flash_device->page_size, false);
if (page_cache == NULL) {
success = false;
break;
@ -333,14 +336,14 @@ static bool flush_ram_cache(bool keep_cache) {
// we've cached. If we don't do this we'll erase the data during the sector
// erase below.
bool copy_to_ram_ok = true;
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / SPI_FLASH_PAGE_SIZE;
for (uint8_t i = 0; i < SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE; i++) {
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / flash_device->page_size;
for (uint8_t i = 0; i < flash_device->erase_size / FILESYSTEM_BLOCK_SIZE; i++) {
if ((dirty_mask & (1 << i)) == 0) {
for (uint8_t j = 0; j < pages_per_block; j++) {
copy_to_ram_ok = read_flash(
current_sector + (i * pages_per_block + j) * SPI_FLASH_PAGE_SIZE,
current_sector + (i * pages_per_block + j) * flash_device->page_size,
MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j],
SPI_FLASH_PAGE_SIZE);
flash_device->page_size);
if (!copy_to_ram_ok) {
break;
}
@ -357,11 +360,11 @@ static bool flush_ram_cache(bool keep_cache) {
// Second, erase the current sector.
erase_sector(current_sector);
// Lastly, write all the data in ram that we've cached.
for (uint8_t i = 0; i < SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE; i++) {
for (uint8_t i = 0; i < flash_device->erase_size / FILESYSTEM_BLOCK_SIZE; i++) {
for (uint8_t j = 0; j < pages_per_block; j++) {
write_flash(current_sector + (i * pages_per_block + j) * SPI_FLASH_PAGE_SIZE,
write_flash(current_sector + (i * pages_per_block + j) * flash_device->page_size,
MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j],
SPI_FLASH_PAGE_SIZE);
flash_device->page_size);
if (!keep_cache) {
m_free(MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j]);
}
@ -485,21 +488,21 @@ bool external_flash_read_block(uint8_t *dest, uint32_t block) {
}
// Mask out the lower bits that designate the address within the sector.
uint32_t this_sector = address & (~(SPI_FLASH_ERASE_SIZE - 1));
uint8_t block_index = (address / FILESYSTEM_BLOCK_SIZE) % (SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE);
uint32_t this_sector = address & (~(flash_device->erase_size - 1));
uint8_t block_index = (address / FILESYSTEM_BLOCK_SIZE) % (flash_device->erase_size / FILESYSTEM_BLOCK_SIZE);
uint8_t mask = 1 << (block_index);
// We're reading from the currently cached sector.
if (current_sector == this_sector && (mask & dirty_mask) > 0) {
if (MP_STATE_VM(flash_ram_cache) != NULL) {
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / SPI_FLASH_PAGE_SIZE;
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / flash_device->page_size;
for (int i = 0; i < pages_per_block; i++) {
memcpy(dest + i * SPI_FLASH_PAGE_SIZE,
memcpy(dest + i * flash_device->page_size,
MP_STATE_VM(flash_ram_cache)[block_index * pages_per_block + i],
SPI_FLASH_PAGE_SIZE);
flash_device->page_size);
}
return true;
} else {
uint32_t scratch_address = SCRATCH_SECTOR + block_index * FILESYSTEM_BLOCK_SIZE;
uint32_t scratch_address = flash_device->total_size - flash_device->erase_size + block_index * FILESYSTEM_BLOCK_SIZE;
return read_flash(scratch_address, dest, FILESYSTEM_BLOCK_SIZE);
}
}
@ -521,8 +524,8 @@ bool external_flash_write_block(const uint8_t *data, uint32_t block) {
// Wait for any previous writes to finish.
wait_for_flash_ready();
// Mask out the lower bits that designate the address within the sector.
uint32_t this_sector = address & (~(SPI_FLASH_ERASE_SIZE - 1));
uint8_t block_index = (address / FILESYSTEM_BLOCK_SIZE) % (SPI_FLASH_ERASE_SIZE / FILESYSTEM_BLOCK_SIZE);
uint32_t this_sector = address & (~(flash_device->erase_size - 1));
uint8_t block_index = (address / FILESYSTEM_BLOCK_SIZE) % (flash_device->erase_size / FILESYSTEM_BLOCK_SIZE);
uint8_t mask = 1 << (block_index);
// Flush the cache if we're moving onto a sector or we're writing the
// same block again.
@ -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 - flash_device->erase_size);
wait_for_flash_ready();
}
current_sector = this_sector;
@ -545,15 +548,15 @@ bool external_flash_write_block(const uint8_t *data, uint32_t block) {
dirty_mask |= mask;
// Copy the block to the appropriate cache.
if (MP_STATE_VM(flash_ram_cache) != NULL) {
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / SPI_FLASH_PAGE_SIZE;
uint8_t pages_per_block = FILESYSTEM_BLOCK_SIZE / flash_device->page_size;
for (int i = 0; i < pages_per_block; i++) {
memcpy(MP_STATE_VM(flash_ram_cache)[block_index * pages_per_block + i],
data + i * SPI_FLASH_PAGE_SIZE,
SPI_FLASH_PAGE_SIZE);
data + i * flash_device->page_size,
flash_device->page_size);
}
return true;
} else {
uint32_t scratch_address = SCRATCH_SECTOR + block_index * FILESYSTEM_BLOCK_SIZE;
uint32_t scratch_address = flash_device->total_size - flash_device->erase_size + block_index * FILESYSTEM_BLOCK_SIZE;
return write_flash(scratch_address, data, FILESYSTEM_BLOCK_SIZE);
}
}

View File

@ -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");
}