Skip to content

Commit 28ab300

Browse files
Merge pull request #11505 from RunnyCow/master
Flash supports MX35LF2G model
2 parents 79ebed8 + 2ed1096 commit 28ab300

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

src/main/drivers/flash.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ typedef struct flashGeometry_s {
4040
uint32_t totalSize; // This is just sectorSize * sectors
4141
uint16_t pagesPerSector;
4242
flashType_e flashType;
43+
int32_t bbReplacementBlocks;
44+
uint8_t bufReadModeSet;
45+
uint8_t bblutTableEntryCount;
4346
} flashGeometry_t;
4447

4548
typedef struct

src/main/drivers/flash_w25n.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "platform.h"
2525

26-
#if defined(USE_FLASH_W25N01G) || defined(USE_FLASH_W25N02K)
26+
#if defined(USE_FLASH_W25N01G) || defined(USE_FLASH_W25N02K)|| defined(USE_FLASH_MX35LF2G)
2727

2828
#include "drivers/bus.h"
2929
#include "drivers/io.h"
@@ -37,12 +37,12 @@
3737

3838
#define W25N01GV_BLOCKS_PER_DIE 1024
3939
#define W25N02KV_BLOCKS_PER_DIE 2048
40-
40+
#define MX35LF2G_BLOCKS_PER_DIE 2048
4141

4242

4343
// BB replacement area
4444
#define W25N_BB_MARKER_BLOCKS 1
45-
#define W25N_BB_REPLACEMENT_BLOCKS 20
45+
#define W25N_BB_REPLACEMENT_BLOCKS (geometry.bbReplacementBlocks)
4646
#define W25N_BB_MANAGEMENT_BLOCKS (W25N_BB_REPLACEMENT_BLOCKS + W25N_BB_MARKER_BLOCKS)
4747

4848
// blocks are zero-based index
@@ -53,9 +53,9 @@
5353
// Instructions
5454
#define W25N_INSTRUCTION_RDID 0x9F
5555
#define W25N_INSTRUCTION_DEVICE_RESET 0xFF
56-
#define W25N_INSTRUCTION_READ_STATUS_REG 0x05
56+
#define W25N_INSTRUCTION_READ_STATUS_REG g_readStatusReg
5757
#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
5959
#define W25N_INSTRUCTION_WRITE_STATUS_ALTERNATE_REG 0x1F
6060
#define W25N_INSTRUCTION_WRITE_ENABLE 0x06
6161
#define W25N_INSTRUCTION_DIE_SELECT 0xC2
@@ -99,7 +99,7 @@
9999
#define W25N_STATUS_ERASE_FAIL (1 << 2)
100100
#define W25N_STATUS_FLAG_WRITE_ENABLED (1 << 1)
101101
#define W25N_STATUS_FLAG_BUSY (1 << 0)
102-
#define W25N_BBLUT_TABLE_ENTRY_COUNT 20
102+
#define W25N_BBLUT_TABLE_ENTRY_COUNT geometry.bblutTableEntryCount
103103
#define W25N_BBLUT_TABLE_ENTRY_SIZE 4 // in bytes
104104

105105
// Bits in LBA for BB LUT
@@ -110,8 +110,8 @@
110110
// Some useful defs and macros
111111
#define W25N_LINEAR_TO_COLUMN(laddr) ((laddr) % W25N_PAGE_SIZE)
112112
#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)
115115
#define W25N_BLOCK_TO_LINEAR(block) (W25N_BLOCK_TO_PAGE(block) * W25N_PAGE_SIZE)
116116

117117
// 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,9 +126,13 @@
126126
#define W28N_STATUS_PAGE_ADDRESS_SIZE 16
127127
#define W28N_STATUS_COLUMN_ADDRESS_SIZE 16
128128

129+
static uint8_t g_readStatusReg;
130+
static uint8_t g_writeStatusReg;
131+
129132
// JEDEC ID
130133
#define JEDEC_ID_WINBOND_W25N01GV 0xEFAA21
131134
#define JEDEC_ID_WINBOND_W25N02KV 0xEFAA22
135+
#define JEDEC_ID_MACRONIX_MX35LF2G 0xC22603
132136

133137
static busDevice_t *busDev = NULL;
134138
static flashGeometry_t geometry;
@@ -242,19 +246,43 @@ bool w25n_detect(uint32_t chipID)
242246
geometry.sectors = W25N01GV_BLOCKS_PER_DIE; // Blocks
243247
geometry.pagesPerSector = W25N_PAGES_PER_BLOCK; // Pages/Blocks
244248
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;
245254
break;
246255
case JEDEC_ID_WINBOND_W25N02KV:
247256
geometry.sectors = W25N02KV_BLOCKS_PER_DIE; // Blocks
248257
geometry.pagesPerSector = W25N_PAGES_PER_BLOCK; // Pages/Blocks
249258
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;
250274
break;
251-
252275
default:
253276
// Unsupported chip
254277
geometry.sectors = 0;
255278
geometry.pagesPerSector = 0;
256279
geometry.sectorSize = 0;
257280
geometry.totalSize = 0;
281+
g_readStatusReg = 0;
282+
g_writeStatusReg = 0;
283+
geometry.bbReplacementBlocks = 0;
284+
geometry.bufReadModeSet = 0;
285+
geometry.bblutTableEntryCount = 0;
258286
return false;
259287
}
260288

0 commit comments

Comments
 (0)