|
23 | 23 |
|
24 | 24 | #include "platform.h" |
25 | 25 |
|
26 | | -#if defined(USE_FLASH_W25N01G) || defined(USE_FLASH_W25N02K) |
| 26 | +#if defined(USE_FLASH_W25N01G) || defined(USE_FLASH_W25N02K)|| defined(USE_FLASH_MX35LF2G) |
27 | 27 |
|
28 | 28 | #include "drivers/bus.h" |
29 | 29 | #include "drivers/io.h" |
|
37 | 37 |
|
38 | 38 | #define W25N01GV_BLOCKS_PER_DIE 1024 |
39 | 39 | #define W25N02KV_BLOCKS_PER_DIE 2048 |
40 | | - |
| 40 | +#define MX35LF2G_BLOCKS_PER_DIE 2048 |
41 | 41 |
|
42 | 42 |
|
43 | 43 | // BB replacement area |
44 | 44 | #define W25N_BB_MARKER_BLOCKS 1 |
45 | | -#define W25N_BB_REPLACEMENT_BLOCKS 20 |
| 45 | +#define W25N_BB_REPLACEMENT_BLOCKS (geometry.bbReplacementBlocks) |
46 | 46 | #define W25N_BB_MANAGEMENT_BLOCKS (W25N_BB_REPLACEMENT_BLOCKS + W25N_BB_MARKER_BLOCKS) |
47 | 47 |
|
48 | 48 | // blocks are zero-based index |
|
53 | 53 | // Instructions |
54 | 54 | #define W25N_INSTRUCTION_RDID 0x9F |
55 | 55 | #define W25N_INSTRUCTION_DEVICE_RESET 0xFF |
56 | | -#define W25N_INSTRUCTION_READ_STATUS_REG 0x05 |
| 56 | +#define W25N_INSTRUCTION_READ_STATUS_REG g_readStatusReg |
57 | 57 | #define W25N_INSTRUCTION_READ_STATUS_ALTERNATE_REG 0x0F |
58 | | -#define W25N_INSTRUCTION_WRITE_STATUS_REG 0x01 |
| 58 | +#define W25N_INSTRUCTION_WRITE_STATUS_REG g_writeStatusReg |
59 | 59 | #define W25N_INSTRUCTION_WRITE_STATUS_ALTERNATE_REG 0x1F |
60 | 60 | #define W25N_INSTRUCTION_WRITE_ENABLE 0x06 |
61 | 61 | #define W25N_INSTRUCTION_DIE_SELECT 0xC2 |
|
99 | 99 | #define W25N_STATUS_ERASE_FAIL (1 << 2) |
100 | 100 | #define W25N_STATUS_FLAG_WRITE_ENABLED (1 << 1) |
101 | 101 | #define W25N_STATUS_FLAG_BUSY (1 << 0) |
102 | | -#define W25N_BBLUT_TABLE_ENTRY_COUNT 20 |
| 102 | +#define W25N_BBLUT_TABLE_ENTRY_COUNT geometry.bblutTableEntryCount |
103 | 103 | #define W25N_BBLUT_TABLE_ENTRY_SIZE 4 // in bytes |
104 | 104 |
|
105 | 105 | // Bits in LBA for BB LUT |
|
110 | 110 | // Some useful defs and macros |
111 | 111 | #define W25N_LINEAR_TO_COLUMN(laddr) ((laddr) % W25N_PAGE_SIZE) |
112 | 112 | #define W25N_LINEAR_TO_PAGE(laddr) ((laddr) / W25N_PAGE_SIZE) |
113 | | -#define W25N_LINEAR_TO_BLOCK(laddr) (W25N_LINEAR_TO_PAGE(laddr) / W25N_PAGES_PER_BLOCK) |
114 | | -#define W25N_BLOCK_TO_PAGE(block) ((block) * W25N_PAGES_PER_BLOCK) |
| 113 | +#define W25N_LINEAR_TO_BLOCK(laddr) (W25N_LINEAR_TO_PAGE(laddr) / geometry.pagesPerSector) |
| 114 | +#define W25N_BLOCK_TO_PAGE(block) ((block) * geometry.pagesPerSector) |
115 | 115 | #define W25N_BLOCK_TO_LINEAR(block) (W25N_BLOCK_TO_PAGE(block) * W25N_PAGE_SIZE) |
116 | 116 |
|
117 | 117 | // IMPORTANT: Timeout values are currently required to be set to the highest value required by any of the supported flash chips by this driver |
|
126 | 126 | #define W28N_STATUS_PAGE_ADDRESS_SIZE 16 |
127 | 127 | #define W28N_STATUS_COLUMN_ADDRESS_SIZE 16 |
128 | 128 |
|
| 129 | +static uint8_t g_readStatusReg; |
| 130 | +static uint8_t g_writeStatusReg; |
| 131 | + |
129 | 132 | // JEDEC ID |
130 | 133 | #define JEDEC_ID_WINBOND_W25N01GV 0xEFAA21 |
131 | 134 | #define JEDEC_ID_WINBOND_W25N02KV 0xEFAA22 |
| 135 | +#define JEDEC_ID_MACRONIX_MX35LF2G 0xC22603 |
132 | 136 |
|
133 | 137 | static busDevice_t *busDev = NULL; |
134 | 138 | static flashGeometry_t geometry; |
@@ -242,19 +246,43 @@ bool w25n_detect(uint32_t chipID) |
242 | 246 | geometry.sectors = W25N01GV_BLOCKS_PER_DIE; // Blocks |
243 | 247 | geometry.pagesPerSector = W25N_PAGES_PER_BLOCK; // Pages/Blocks |
244 | 248 | geometry.pageSize = W25N_PAGE_SIZE; |
| 249 | + g_readStatusReg = 0x05; |
| 250 | + g_writeStatusReg = 0x01; |
| 251 | + geometry.bbReplacementBlocks = 20; |
| 252 | + geometry.bufReadModeSet = 0x02; |
| 253 | + geometry.bblutTableEntryCount = 20; |
245 | 254 | break; |
246 | 255 | case JEDEC_ID_WINBOND_W25N02KV: |
247 | 256 | geometry.sectors = W25N02KV_BLOCKS_PER_DIE; // Blocks |
248 | 257 | geometry.pagesPerSector = W25N_PAGES_PER_BLOCK; // Pages/Blocks |
249 | 258 | geometry.pageSize = W25N_PAGE_SIZE; |
| 259 | + g_readStatusReg = 0x05; |
| 260 | + g_writeStatusReg = 0x01; |
| 261 | + geometry.bbReplacementBlocks = 20; |
| 262 | + geometry.bufReadModeSet = 0x02; |
| 263 | + geometry.bblutTableEntryCount = 20; |
| 264 | + break; |
| 265 | + case JEDEC_ID_MACRONIX_MX35LF2G: |
| 266 | + geometry.sectors = MX35LF2G_BLOCKS_PER_DIE; // Blocks |
| 267 | + geometry.pagesPerSector = W25N_PAGES_PER_BLOCK; // Pages/Blocks |
| 268 | + geometry.pageSize = W25N_PAGE_SIZE; |
| 269 | + g_readStatusReg = 0x0F; |
| 270 | + g_writeStatusReg = 0x1F; |
| 271 | + geometry.bbReplacementBlocks = 40; |
| 272 | + geometry.bufReadModeSet = 0; |
| 273 | + geometry.bblutTableEntryCount = 40; |
250 | 274 | break; |
251 | | - |
252 | 275 | default: |
253 | 276 | // Unsupported chip |
254 | 277 | geometry.sectors = 0; |
255 | 278 | geometry.pagesPerSector = 0; |
256 | 279 | geometry.sectorSize = 0; |
257 | 280 | geometry.totalSize = 0; |
| 281 | + g_readStatusReg = 0; |
| 282 | + g_writeStatusReg = 0; |
| 283 | + geometry.bbReplacementBlocks = 0; |
| 284 | + geometry.bufReadModeSet = 0; |
| 285 | + geometry.bblutTableEntryCount = 0; |
258 | 286 | return false; |
259 | 287 | } |
260 | 288 |
|
|
0 commit comments