Skip to content

FlashIAP: Get erase value from HAL instead of hardcoding it #11752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TESTS/mbed_drivers/flashiap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void flashiap_cross_sector_program_test()
TEST_ASSERT_EQUAL_INT32(0, ret);

uint32_t page_size = flash_device.get_page_size();
uint8_t erase_value = flash_device.get_erase_value();

// Erase last two sectors
uint32_t address = flash_device.get_flash_start() + flash_device.get_flash_size();
Expand Down Expand Up @@ -170,7 +171,7 @@ void flashiap_cross_sector_program_test()
data[i] = rand() % 256;
}
for (uint32_t i = prog_size; i < aligned_prog_size; i++) {
data[i] = 0xFF;
data[i] = erase_value;
}

ret = flash_device.program(data, address, prog_size);
Expand Down
3 changes: 2 additions & 1 deletion drivers/source/FlashIAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
uint32_t page_size = get_page_size();
uint32_t flash_size = flash_get_size(&_flash);
uint32_t flash_start_addr = flash_get_start_address(&_flash);
uint8_t flash_erase_value = flash_get_erase_value(&_flash);
uint32_t chunk, prog_size;
const uint8_t *buf = (uint8_t *) buffer;
const uint8_t *prog_buf;
Expand All @@ -123,7 +124,7 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
chunk = std::min(chunk, page_size);
memcpy(_page_buf, buf, chunk);
if (chunk < page_size) {
memset(_page_buf + chunk, 0xFF, page_size - chunk);
memset(_page_buf + chunk, flash_erase_value, page_size - chunk);
}
prog_buf = _page_buf;
prog_size = page_size;
Expand Down