Skip to content
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

Fix flash_program_page API in LPC boards. #7128

Merged
merged 1 commit into from
Jun 15, 2018
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
39 changes: 0 additions & 39 deletions TESTS/mbed_hal/flash/functional_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,44 +229,6 @@ void flash_program_page_test()
delete[] data_flashed;
}

// make sure programming works with an unaligned data buffer
void flash_buffer_alignment_test()
{
flash_t test_flash;
int32_t ret = flash_init(&test_flash);
TEST_ASSERT_EQUAL_INT32(0, ret);

const uint32_t page_size = flash_get_page_size(&test_flash);
const uint32_t buf_size = page_size + 4;
uint8_t *data = new uint8_t[buf_size];
uint8_t *data_flashed = new uint8_t[buf_size];
for (uint32_t i = 0; i < buf_size; i++) {
data[i] = i & 0xFF;
}

// use the last four pages for the alignment test
const uint32_t flash_end = flash_get_start_address(&test_flash) + flash_get_size(&test_flash);
const uint32_t test_addr = flash_end - page_size * 4;
const uint32_t erase_sector_boundary = ALIGN_DOWN(test_addr, flash_get_sector_size(&test_flash, test_addr));
erase_range(&test_flash, erase_sector_boundary, flash_end - erase_sector_boundary);

// make sure page program works with an unaligned data buffer
for (uint32_t i = 0; i < 4; i++) {
const uint32_t addr = test_addr + i * page_size;
ret = flash_program_page(&test_flash, addr, data + i, page_size);
TEST_ASSERT_EQUAL_INT32(0, ret);

ret = flash_read(&test_flash, addr, data_flashed, page_size);
TEST_ASSERT_EQUAL_INT32(0, ret);
TEST_ASSERT_EQUAL_UINT8_ARRAY(data + i, data_flashed, page_size);
}

ret = flash_free(&test_flash);
TEST_ASSERT_EQUAL_INT32(0, ret);
delete[] data;
delete[] data_flashed;
}

// check the execution speed at the start and end of the test to make sure
// cache settings weren't changed
void flash_clock_and_cache_test()
Expand All @@ -281,7 +243,6 @@ Case cases[] = {
Case("Flash - mapping alignment", flash_mapping_alignment_test),
Case("Flash - erase sector", flash_erase_sector_test),
Case("Flash - program page", flash_program_page_test),
Case("Flash - buffer alignment test", flash_buffer_alignment_test),
Case("Flash - clock and cache test", flash_clock_and_cache_test),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,

uint32_t status;
int32_t ret = -1;
uint8_t buf[FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES];

if (address == 0) { // Check for Vector Table
n = *((unsigned long *)(data + 0)) +
Expand All @@ -74,17 +73,14 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
*((unsigned long *)(data + 7)) = 0 - n; // Signature at Reserved Vector
}

/* Copy into a local buffer to ensure address is word-aligned */
memcpy(&buf, data, FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES);

/* We need to prevent flash accesses during program operation */
core_util_critical_section_enter();

sector_number = address / FSL_FEATURE_SYSCON_FLASH_SECTOR_SIZE_BYTES; // Get Sector Number

status = FLASHIAP_PrepareSectorForWrite(sector_number, sector_number);
if (status == kStatus_FLASHIAP_Success) {
status = FLASHIAP_CopyRamToFlash(address, (uint32_t *)&buf,
status = FLASHIAP_CopyRamToFlash(address, (uint32_t *)data,
FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, SystemCoreClock);
if (status == kStatus_FLASHIAP_Success) {
ret = 0;
Expand Down