Skip to content

Commit aed0d05

Browse files
author
Marten Lootsma
committed
Added support for SPIF of size bigger than 16Mbyte
- checks if size is bigger than 16Mbyte - changes to 4 byte address mode of neccessary
1 parent 489bd10 commit aed0d05

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 12 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,13 @@ 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)) // Size is bigger than 16MB and thus address does not fit in 3 byte, switch to 4 byte address mode
218+
{
219+
tr_debug("Size is bigger than 16MB and thus address does not fit in 3 byte, switch to 4 byte address mode");
220+
_spi_send_general_command(SPIF_4BEN, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
221+
_address_size = SPIF_ADDR_SIZE_4_BYTES;
222+
}
223+
214224
exit_point:
215225
_mutex->unlock();
216226

@@ -540,7 +550,7 @@ spif_bd_error SPIFBlockDevice::_spi_send_program_command(int prog_inst, const vo
540550

541551
spif_bd_error SPIFBlockDevice::_spi_send_erase_command(int erase_inst, bd_addr_t addr, bd_size_t size)
542552
{
543-
addr = (((int)addr) & 0x00FFF000);
553+
addr = (((int)addr) & 0xFFFFF000);
544554
_spi_send_general_command(erase_inst, addr, NULL, 0, NULL, 0);
545555
return SPIF_BD_ERROR_OK;
546556
}

0 commit comments

Comments
 (0)