@@ -56,6 +56,7 @@ using namespace mbed;
56
56
#define SPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE 40
57
57
// Address Length
58
58
#define SPIF_ADDR_SIZE_3_BYTES 3
59
+ #define SPIF_ADDR_SIZE_4_BYTES 4
59
60
// Erase Types Params
60
61
#define SPIF_BASIC_PARAM_ERASE_TYPE_1_BYTE 29
61
62
#define SPIF_BASIC_PARAM_ERASE_TYPE_2_BYTE 31
@@ -88,7 +89,9 @@ enum spif_default_instructions {
88
89
SPIF_RSTEN = 0x66 , // Reset Enable
89
90
SPIF_RST = 0x99 , // Reset
90
91
SPIF_RDID = 0x9f , // Read Manufacturer and JDEC Device ID
91
- SPIF_ULBPR = 0x98 , // Clears all write-protection bits in the Block-Protection register
92
+ SPIF_ULBPR = 0x98 , // Clears all write-protection bits in the Block-Protection register,
93
+ SPIF_4BEN = 0xB7 , // Enable 4-byte address mode
94
+ SPIF_4BDIS = 0xE9 , // Disable 4-byte address mode
92
95
};
93
96
94
97
// Mutex is used for some SPI Driver commands that must be done sequentially with no other commands in between
@@ -211,6 +214,12 @@ int SPIFBlockDevice::init()
211
214
_dummy_and_mode_cycles = _write_dummy_and_mode_cycles;
212
215
_is_initialized = true ;
213
216
217
+ if (_device_size_bytes > (1 << 24 )) {
218
+ tr_debug (" Size is bigger than 16MB and thus address does not fit in 3 byte, switch to 4 byte address mode" );
219
+ _spi_send_general_command (SPIF_4BEN, SPI_NO_ADDRESS_COMMAND, NULL , 0 , NULL , 0 );
220
+ _address_size = SPIF_ADDR_SIZE_4_BYTES;
221
+ }
222
+
214
223
exit_point:
215
224
_mutex->unlock ();
216
225
@@ -540,7 +549,7 @@ spif_bd_error SPIFBlockDevice::_spi_send_program_command(int prog_inst, const vo
540
549
541
550
spif_bd_error SPIFBlockDevice::_spi_send_erase_command (int erase_inst, bd_addr_t addr, bd_size_t size)
542
551
{
543
- addr = (((int )addr) & 0x00FFF000 );
552
+ addr = (((int )addr) & 0xFFFFF000 );
544
553
_spi_send_general_command (erase_inst, addr, NULL , 0 , NULL , 0 );
545
554
return SPIF_BD_ERROR_OK;
546
555
}
0 commit comments