Skip to content

Commit 15b8455

Browse files
authored
Merge pull request adafruit#654 from tannewt/structify_flash_devices
Structify flash devices
2 parents 568c04e + 01aceaa commit 15b8455

21 files changed

Lines changed: 319 additions & 504 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#define SPEAKER_ENABLE_PIN (&pin_PA30)
4040

41-
#include "external_flash/external_flash.h"
41+
#include "external_flash/devices.h"
4242

4343
// If you change this, then make sure to update the linker scripts as well to
4444
// make sure you don't overwrite code.
@@ -47,8 +47,13 @@
4747

4848
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
4949

50-
#include "external_flash/devices/S25FL216K.h"
51-
#include "external_flash/devices/GD25Q16C.h"
50+
#include "external_flash/devices.h"
51+
52+
#define EXTERNAL_FLASH_DEVICE_COUNT 2
53+
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
54+
GD25Q16C
55+
56+
#include "external_flash/external_flash.h"
5257

5358
#define CALIBRATE_CRYSTALLESS 1
5459

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@
4040

4141
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
4242

43-
#include "external_flash/devices/S25FL216K.h"
44-
#include "external_flash/devices/GD25Q16C.h"
43+
#include "external_flash/devices.h"
44+
45+
#define EXTERNAL_FLASH_DEVICE_COUNT 2
46+
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
47+
GD25Q16C
48+
49+
#include "external_flash/external_flash.h"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@
4242

4343
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
4444

45-
#include "external_flash/devices/S25FL064L.h"
45+
#include "external_flash/devices.h"
46+
47+
#define EXTERNAL_FLASH_DEVICE_COUNT 1
48+
#define EXTERNAL_FLASH_DEVICES S25FL064L
49+
50+
#include "external_flash/external_flash.h"

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
#define MICROPY_PORT_B (PORT_PB22 | PORT_PB23 | PORT_PB03 )
3434
#define MICROPY_PORT_C (0)
3535

36-
#include "external_flash/external_flash.h"
37-
3836
// If you change this, then make sure to update the linker scripts as well to
3937
// make sure you don't overwrite code.
4038
// #define CIRCUITPY_INTERNAL_NVM_SIZE 256
4139
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
4240
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
4341

44-
#include "external_flash/devices/GD25Q16C.h"
45-
#include "external_flash/devices/W25Q16FW.h"
42+
#include "external_flash/devices.h"
43+
44+
#define EXTERNAL_FLASH_DEVICE_COUNT 2
45+
#define EXTERNAL_FLASH_DEVICES W25Q16FW, \
46+
GD25Q16C
47+
48+
#include "external_flash/external_flash.h"

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@
3434
#define MICROPY_PORT_B (PORT_PB03 | PORT_PB22 | PORT_PB23)
3535
#define MICROPY_PORT_C (0)
3636

37-
#include "external_flash/external_flash.h"
38-
3937
// If you change this, then make sure to update the linker scripts as well to
4038
// make sure you don't overwrite code.
4139
// #define CIRCUITPY_INTERNAL_NVM_SIZE 256
4240
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
4341

4442
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
4543

46-
#include "external_flash/devices/S25FL216K.h"
47-
#include "external_flash/devices/GD25Q16C.h"
44+
#include "external_flash/devices.h"
45+
46+
#define EXTERNAL_FLASH_DEVICE_COUNT 2
47+
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
48+
GD25Q16C
49+
50+
#include "external_flash/external_flash.h"

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020

2121
#define AUTORESET_DELAY_MS 500
2222

23-
#include "external_flash/external_flash.h"
24-
2523
// If you change this, then make sure to update the linker scripts as well to
2624
// make sure you don't overwrite code
2725
// #define CIRCUITPY_INTERNAL_NVM_SIZE 256
2826
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
2927

3028
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
3129

32-
#include "external_flash/devices/S25FL116K.h"
33-
#include "external_flash/devices/GD25Q16C.h"
30+
#include "external_flash/devices.h"
31+
32+
#define EXTERNAL_FLASH_DEVICE_COUNT 3
33+
#define EXTERNAL_FLASH_DEVICES S25FL116K, S25FL216K, GD25Q16C
34+
35+
#include "external_flash/external_flash.h"

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@
5454

5555
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
5656

57-
#include "external_flash/devices/S25FL216K.h"
58-
#include "external_flash/devices/GD25Q16C.h"
57+
#include "external_flash/devices.h"
58+
59+
#define EXTERNAL_FLASH_DEVICE_COUNT 2
60+
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
61+
GD25Q16C
62+
63+
#include "external_flash/external_flash.h"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@
4848
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
4949
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
5050

51-
#include "external_flash/devices/W25Q32BV.h"
51+
#include "external_flash/devices.h"
52+
53+
#define EXTERNAL_FLASH_DEVICE_COUNT 1
54+
#define EXTERNAL_FLASH_DEVICES W25Q32BV
55+
56+
#include "external_flash/external_flash.h"

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@
4141
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
4242
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
4343

44-
//#include "external_flash/devices/W25Q32BV.h"
45-
#include "external_flash/devices/S25FL216K.h"
44+
#include "external_flash/devices.h"
45+
46+
#define EXTERNAL_FLASH_DEVICE_COUNT 1
47+
#define EXTERNAL_FLASH_DEVICES S25FL216K
48+
49+
#include "external_flash/external_flash.h"
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H
27+
#define MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H
28+
29+
#include <stdbool.h>
30+
#include <stdint.h>
31+
32+
typedef struct {
33+
uint32_t total_size;
34+
uint16_t start_up_time_us;
35+
36+
// Three response bytes to 0x9f JEDEC ID command.
37+
uint8_t manufacturer_id;
38+
uint8_t memory_type;
39+
uint8_t capacity;
40+
41+
// Max clock speed for all operations and the fastest read mode.
42+
uint8_t max_clock_speed_mhz;
43+
bool has_sector_protection : 1;
44+
45+
// Supports the 0x0b fast read command with 8 dummy cycles.
46+
bool supports_fast_read : 1;
47+
48+
// Supports the fast read, quad output command 0x6b with 8 dummy cycles.
49+
bool supports_qspi : 1;
50+
51+
// Requires quad enable set in status bit 9.
52+
bool has_quad_enable : 1;
53+
54+
// Supports the quad input page program command 0x32. This is known as 1-1-4 because it only
55+
// uses all four lines for data.
56+
bool supports_qspi_writes: 1;
57+
} external_flash_device;
58+
59+
// Settings for the Adesto Tech AT25DF081A 1MiB SPI flash. Its on the SAMD21
60+
// Xplained board.
61+
// Datasheet: https://www.adestotech.com/wp-content/uploads/doc8715.pdf
62+
#define AT25DF081A {\
63+
.total_size = (1 << 20), /* 1 MiB */ \
64+
.start_up_time_us = 10000, \
65+
.manufacturer_id = 0x1f, \
66+
.memory_type = 0x45, \
67+
.capacity = 0x01, \
68+
.max_clock_speed_mhz = 85, \
69+
.has_sector_protection = true, \
70+
.supports_fast_read = true, \
71+
.supports_qspi = false, \
72+
.has_quad_enable = false, \
73+
.supports_qspi_writes = false, \
74+
}
75+
76+
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
77+
// Datasheet: http://www.gigadevice.com/wp-content/uploads/2017/12/DS-00086-GD25Q16C-Rev2.6.pdf
78+
#define GD25Q16C {\
79+
.total_size = (1 << 21), /* 2 MiB */ \
80+
.start_up_time_us = 5000, \
81+
.manufacturer_id = 0xc8, \
82+
.memory_type = 0x40, \
83+
.capacity = 0x15, \
84+
.max_clock_speed_mhz = 104, /* if we need 120 then we can turn on high performance mode */ \
85+
.has_sector_protection = false, \
86+
.supports_fast_read = true, \
87+
.supports_qspi = true, \
88+
.has_quad_enable = true, \
89+
.supports_qspi_writes = true, \
90+
}
91+
92+
// Settings for the Cypress (was Spansion) S25FL064L 8MiB SPI flash.
93+
// Datasheet: http://www.cypress.com/file/316661/download
94+
#define S25FL064L {\
95+
.total_size = (1 << 23), /* 8 MiB */ \
96+
.start_up_time_us = 300, \
97+
.manufacturer_id = 0x01, \
98+
.memory_type = 0x60, \
99+
.capacity = 0x17, \
100+
.max_clock_speed_mhz = 108, \
101+
.has_sector_protection = false, \
102+
.supports_fast_read = true, \
103+
.supports_qspi = true, \
104+
.has_quad_enable = true, \
105+
.supports_qspi_writes = true, \
106+
}
107+
108+
// Settings for the Cypress (was Spansion) S25FL116K 2MiB SPI flash.
109+
// Datasheet: http://www.cypress.com/file/196886/download
110+
#define S25FL116K {\
111+
.total_size = (1 << 21), /* 2 MiB */ \
112+
.start_up_time_us = 10000, \
113+
.manufacturer_id = 0x01, \
114+
.memory_type = 0x40, \
115+
.capacity = 0x15, \
116+
.max_clock_speed_mhz = 108, \
117+
.has_sector_protection = false, \
118+
.supports_fast_read = true, \
119+
.supports_qspi = true, \
120+
.has_quad_enable = true, \
121+
.supports_qspi_writes = false, \
122+
}
123+
124+
// Settings for the Cypress (was Spansion) S25FL216K 2MiB SPI flash.
125+
// Datasheet: http://www.cypress.com/file/197346/download
126+
#define S25FL216K {\
127+
.total_size = (1 << 21), /* 2 MiB */ \
128+
.start_up_time_us = 10000, \
129+
.manufacturer_id = 0x01, \
130+
.memory_type = 0x40, \
131+
.capacity = 0x15, \
132+
.max_clock_speed_mhz = 65, \
133+
.has_sector_protection = false, \
134+
.supports_fast_read = true, \
135+
.supports_qspi = false, \
136+
.has_quad_enable = false, \
137+
.supports_qspi_writes = false, \
138+
}
139+
140+
// Settings for the Winbond W25Q16FW 2MiB SPI flash.
141+
// Datasheet: https://www.winbond.com/resource-files/w25q16fw%20revj%2005182017%20sfdp.pdf
142+
#define W25Q16FW {\
143+
.total_size = (1 << 21), /* 2 MiB */ \
144+
.start_up_time_us = 5000, \
145+
.manufacturer_id = 0xef, \
146+
.memory_type = 0x60, \
147+
.capacity = 0x15, \
148+
.max_clock_speed_mhz = 133, \
149+
.has_sector_protection = false, \
150+
.supports_fast_read = true, \
151+
.supports_qspi = true, \
152+
.has_quad_enable = true, \
153+
.supports_qspi_writes = true, \
154+
}
155+
156+
// Settings for the Winbond W25Q16JV 2MiB SPI flash.
157+
// Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf
158+
#define W25Q16JV {\
159+
.total_size = (1 << 21), /* 2 MiB */ \
160+
.start_up_time_us = 5000, \
161+
.manufacturer_id = 0xef, \
162+
.memory_type = 0x40, \
163+
.capacity = 0x15, \
164+
.max_clock_speed_mhz = 133, \
165+
.has_sector_protection = false, \
166+
.supports_fast_read = true, \
167+
.supports_qspi = true, \
168+
.has_quad_enable = true, \
169+
.supports_qspi_writes = true, \
170+
}
171+
172+
// Settings for the Winbond W25Q32BV 2MiB SPI flash.
173+
// Datasheet: https://www.winbond.com/resource-files/w25q32bv_revi_100413_wo_automotive.pdf
174+
#define W25Q32BV {\
175+
.total_size = (1 << 22), /* 4 MiB */ \
176+
.start_up_time_us = 10000, \
177+
.manufacturer_id = 0xef, \
178+
.memory_type = 0x60, \
179+
.capacity = 0x16, \
180+
.max_clock_speed_mhz = 104, \
181+
.has_sector_protection = false, \
182+
.supports_fast_read = true, \
183+
.supports_qspi = true, \
184+
.has_quad_enable = true, \
185+
.supports_qspi_writes = false, \
186+
}
187+
188+
// Settings for the Winbond W25Q80DL 1MiB SPI flash.
189+
// Datasheet: https://www.winbond.com/resource-files/w25q80dv%20dl_revh_10022015.pdf
190+
#define W25Q80DL {\
191+
.total_size = (1 << 20), /* 1 MiB */ \
192+
.start_up_time_us = 5000, \
193+
.manufacturer_id = 0xef, \
194+
.memory_type = 0x60, \
195+
.capacity = 0x14, \
196+
.max_clock_speed_mhz = 104, \
197+
.has_sector_protection = false, \
198+
.supports_fast_read = true, \
199+
.supports_qspi = true, \
200+
.has_quad_enable = true, \
201+
.supports_qspi_writes = false, \
202+
}
203+
204+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H

0 commit comments

Comments
 (0)