Skip to content

Commit 0560ecc

Browse files
authored
Merge pull request #10478 from chrissnow/Dataflash-Erase_Size
DataFlash: Change erase size to pages to reduce memory usage.
2 parents f859289 + 157debf commit 0560ecc

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ enum opcode {
6161
DATAFLASH_OP_PROGRAM_DIRECT = 0x02, // Program through Buffer 1 without Built-In Erase
6262
DATAFLASH_OP_PROGRAM_DIRECT_WITH_ERASE = 0x82,
6363
DATAFLASH_OP_ERASE_BLOCK = 0x50,
64+
DATAFLASH_OP_ERASE_PAGE = 0x81,
6465
};
6566

6667
/* non-exhaustive command list */
@@ -447,17 +448,17 @@ int DataFlashBlockDevice::erase(bd_addr_t addr, bd_size_t size)
447448
/* disable write protection */
448449
_write_enable(true);
449450

450-
/* erase one block at a time until the full size has been erased */
451+
/* erase one page at a time until the full size has been erased */
451452
uint32_t erased = 0;
452453
while (erased < size) {
453454

454-
/* set block erase opcode */
455-
uint32_t command = DATAFLASH_OP_ERASE_BLOCK;
455+
/* set page erase opcode */
456+
uint32_t command = DATAFLASH_OP_ERASE_PAGE;
456457

457458
/* translate address */
458459
uint32_t address = _translate_address(addr);
459460

460-
/* set block address */
461+
/* set page address */
461462
command = (command << 8) | ((address >> 16) & 0xFF);
462463
command = (command << 8) | ((address >> 8) & 0xFF);
463464
command = (command << 8) | (address & 0xFF);
@@ -474,8 +475,8 @@ int DataFlashBlockDevice::erase(bd_addr_t addr, bd_size_t size)
474475
}
475476

476477
/* update loop variables */
477-
addr += _block_size;
478-
erased += _block_size;
478+
addr += _page_size;
479+
erased += _page_size;
479480
}
480481

481482
/* enable write protection */
@@ -503,17 +504,17 @@ bd_size_t DataFlashBlockDevice::get_program_size() const
503504
bd_size_t DataFlashBlockDevice::get_erase_size() const
504505
{
505506
_mutex.lock();
506-
DEBUG_PRINTF("erase size: %" PRIX16 "\r\n", _block_size);
507-
bd_size_t block_size = _block_size;
507+
DEBUG_PRINTF("erase size: %" PRIX16 "\r\n", _page_size);
508+
bd_size_t block_size = _page_size;
508509
_mutex.unlock();
509510
return block_size;
510511
}
511512

512513
bd_size_t DataFlashBlockDevice::get_erase_size(bd_addr_t addr) const
513514
{
514515
_mutex.lock();
515-
DEBUG_PRINTF("erase size: %" PRIX16 "\r\n", _block_size);
516-
bd_size_t block_size = _block_size;
516+
DEBUG_PRINTF("erase size: %" PRIX16 "\r\n", _page_size);
517+
bd_size_t block_size = _page_size;
517518
_mutex.unlock();
518519
return block_size;
519520
}

0 commit comments

Comments
 (0)