Skip to content

Commit 1803561

Browse files
authored
Merge pull request #10779 from martinichka/feature-spif-bigger-16m
Add support for SPIF of size bigger than 16Mbyte
2 parents 410e96b + e0ad715 commit 1803561

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ using namespace mbed;
5656
#define SPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE 40
5757
// Address Length
5858
#define SPIF_ADDR_SIZE_3_BYTES 3
59+
#define SPIF_ADDR_SIZE_4_BYTES 4
5960
// Erase Types Params
6061
#define SPIF_BASIC_PARAM_ERASE_TYPE_1_BYTE 29
6162
#define SPIF_BASIC_PARAM_ERASE_TYPE_2_BYTE 31
@@ -88,7 +89,9 @@ enum spif_default_instructions {
8889
SPIF_RSTEN = 0x66, // Reset Enable
8990
SPIF_RST = 0x99, // Reset
9091
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
9295
};
9396

9497
// 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()
211214
_dummy_and_mode_cycles = _write_dummy_and_mode_cycles;
212215
_is_initialized = true;
213216

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+
214223
exit_point:
215224
_mutex->unlock();
216225

@@ -540,7 +549,7 @@ spif_bd_error SPIFBlockDevice::_spi_send_program_command(int prog_inst, const vo
540549

541550
spif_bd_error SPIFBlockDevice::_spi_send_erase_command(int erase_inst, bd_addr_t addr, bd_size_t size)
542551
{
543-
addr = (((int)addr) & 0x00FFF000);
552+
addr = (((int)addr) & 0xFFFFF000);
544553
_spi_send_general_command(erase_inst, addr, NULL, 0, NULL, 0);
545554
return SPIF_BD_ERROR_OK;
546555
}

0 commit comments

Comments
 (0)