From 299c7f24ac9993ee835df8ae1dce3235fbb067ca Mon Sep 17 00:00:00 2001 From: Marcus Chang Date: Wed, 19 Jul 2017 14:32:39 +0100 Subject: [PATCH] mbed-hal: Fixed flash test The test assumed that data written to flash would be memory mapped and directly accessible. On some platform this is not the case and data has to read back through an explicit read command. The test has been changed to use the flash read command instead of direct memory access. --- TESTS/mbed_hal/flash/functional_tests/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/TESTS/mbed_hal/flash/functional_tests/main.cpp b/TESTS/mbed_hal/flash/functional_tests/main.cpp index cabe49ec4e..40ab6341a0 100644 --- a/TESTS/mbed_hal/flash/functional_tests/main.cpp +++ b/TESTS/mbed_hal/flash/functional_tests/main.cpp @@ -148,7 +148,6 @@ void flash_mapping_alignment_test() TEST_ASSERT_EQUAL(0, sector_start % sector_size); // All address in a sector must return the same sector size TEST_ASSERT_EQUAL(sector_size, end_sector_size); - } // Make sure unmapped flash is reported correctly @@ -185,6 +184,7 @@ void flash_program_page_test() uint32_t test_size = flash_get_page_size(&test_flash); uint8_t *data = new uint8_t[test_size]; + uint8_t *data_flashed = new uint8_t[test_size]; for (uint32_t i = 0; i < test_size; i++) { data[i] = 0xCE; } @@ -199,7 +199,9 @@ void flash_program_page_test() ret = flash_program_page(&test_flash, address, data, test_size); TEST_ASSERT_EQUAL_INT32(0, ret); - uint8_t *data_flashed = (uint8_t *)address; + + ret = flash_read(&test_flash, address, data_flashed, test_size); + TEST_ASSERT_EQUAL_INT32(0, ret); TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, test_size); // sector size might not be same as page size @@ -213,11 +215,15 @@ void flash_program_page_test() } ret = flash_program_page(&test_flash, address, data, test_size); TEST_ASSERT_EQUAL_INT32(0, ret); + + ret = flash_read(&test_flash, address, data_flashed, test_size); + TEST_ASSERT_EQUAL_INT32(0, ret); TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, test_size); ret = flash_free(&test_flash); TEST_ASSERT_EQUAL_INT32(0, ret); delete[] data; + delete[] data_flashed; } // make sure programming works with an unaligned data buffer @@ -230,6 +236,7 @@ void flash_buffer_alignment_test() 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; } @@ -245,13 +252,16 @@ void flash_buffer_alignment_test() 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); - uint8_t *data_flashed = (uint8_t *)addr; + + 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