diff --git a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_debug.h b/components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_debug.h similarity index 100% rename from components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_debug.h rename to components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_debug.h diff --git a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.c b/components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.c similarity index 100% rename from components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.c rename to components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.c diff --git a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.h b/components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.h similarity index 100% rename from components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/COMMON/fslittle_test.h rename to components/storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.h diff --git a/components/storage/blockdevice/COMPONENT_QSPIF/TESTS/block_device/qspif/main.cpp b/components/storage/blockdevice/COMPONENT_QSPIF/TESTS/block_device/qspif/main.cpp deleted file mode 100644 index 0674fc463d..0000000000 --- a/components/storage/blockdevice/COMPONENT_QSPIF/TESTS/block_device/qspif/main.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "QSPIFBlockDevice.h" -#include "mbed_trace.h" -#include "rtos/Thread.h" -#include - -using namespace utest::v1; - -#define TEST_BLOCK_COUNT 10 -#define TEST_ERROR_MASK 16 -#define QSPIF_TEST_NUM_OF_THREADS 5 - -const struct { - const char *name; - bd_size_t (BlockDevice::*method)() const; -} ATTRS[] = { - {"read size", &BlockDevice::get_read_size}, - {"program size", &BlockDevice::get_program_size}, - {"erase size", &BlockDevice::get_erase_size}, - {"total size", &BlockDevice::size}, -}; - -static SingletonPtr _mutex; - - -// Mutex is protecting rand() per srand for buffer writing and verification. -// Mutex is also protecting printouts for clear logs. -// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test! -void basic_erase_program_read_test(QSPIFBlockDevice &blockD, bd_size_t block_size, uint8_t *write_block, - uint8_t *read_block, unsigned addrwidth) -{ - int err = 0; - _mutex->lock(); - - static unsigned block_seed = 1; - srand(block_seed++); - - // Find a random block - bd_addr_t block = (rand() * block_size) % blockD.size(); - - // Use next random number as temporary seed to keep - // the address progressing in the pseudorandom sequence - unsigned seed = rand(); - - // Fill with random sequence - srand(seed); - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - write_block[i_ind] = 0xff & rand(); - } - // Write, sync, and read the block - utest_printf("\ntest %0*llx:%llu...", addrwidth, block, block_size); - _mutex->unlock(); - - err = blockD.erase(block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = blockD.program(write_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = blockD.read(read_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - _mutex->lock(); - // Check that the data was unmodified - srand(seed); - int val_rand; - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - val_rand = rand(); - if ((0xff & val_rand) != read_block[i_ind]) { - utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size); - utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand), read_block[i_ind], - write_block[i_ind]); - } - TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]); - } - _mutex->unlock(); -} - -void test_qspif_random_program_read_erase() -{ - utest_printf("\nTest Random Program Read Erase Starts..\n"); - - QSPIFBlockDevice blockD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, - QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); - - int err = blockD.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (blockD.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_size_t block_size = blockD.get_erase_size(); - unsigned addrwidth = ceil(log(float(blockD.size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test(blockD, block_size, write_block, read_block, addrwidth); - } - - err = blockD.deinit(); - TEST_ASSERT_EQUAL(0, err); - -end: - delete[] write_block; - delete[] read_block; -} - -void test_qspif_unaligned_erase() -{ - - utest_printf("\nTest Unaligned Erase Starts..\n"); - - QSPIFBlockDevice blockD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, - QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); - - int err = blockD.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (blockD.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_addr_t addr = 0; - bd_size_t sector_erase_size = blockD.get_erase_size(addr); - unsigned addrwidth = ceil(log(float(blockD.size() - 1)) / log(float(16))) + 1; - - utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size); - - //unaligned start address - addr += 1; - err = blockD.erase(addr, sector_erase_size - 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = blockD.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = blockD.erase(addr, 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //unaligned end address - addr = 0; - - err = blockD.erase(addr, 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = blockD.erase(addr, sector_erase_size + 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //erase size exceeds flash device size - err = blockD.erase(addr, blockD.size() + 1); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - // Valid erase - err = blockD.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(QSPIF_BD_ERROR_OK, err); - - err = blockD.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - - - -static void test_qspif_thread_job(void *vBlockD/*, int thread_num*/) -{ - static int thread_num = 0; - thread_num++; - QSPIFBlockDevice *blockD = (QSPIFBlockDevice *)vBlockD; - utest_printf("\n Thread %d Started \n", thread_num); - - bd_size_t block_size = blockD->get_erase_size(); - unsigned addrwidth = ceil(log(float(blockD->size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test((*blockD), block_size, write_block, read_block, addrwidth); - } - -end: - delete[] write_block; - delete[] read_block; -} - -void test_qspif_multi_threads() -{ - - utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n"); - - QSPIFBlockDevice blockD(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, - QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); - - int err = blockD.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (blockD.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - rtos::Thread qspif_bd_thread[QSPIF_TEST_NUM_OF_THREADS]; - - osStatus threadStatus; - int i_ind; - - for (i_ind = 0; i_ind < QSPIF_TEST_NUM_OF_THREADS; i_ind++) { - threadStatus = qspif_bd_thread[i_ind].start(test_qspif_thread_job, (void *)&blockD); - if (threadStatus != 0) { - utest_printf("\n Thread %d Start Failed!", i_ind + 1); - } - } - - for (i_ind = 0; i_ind < QSPIF_TEST_NUM_OF_THREADS; i_ind++) { - qspif_bd_thread[i_ind].join(); - } - - err = blockD.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - - - - -// Test setup -utest::v1::status_t test_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(60, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -Case cases[] = { - Case("Testing unaligned erase blocks", test_qspif_unaligned_erase), - Case("Testing read write random blocks", test_qspif_random_program_read_erase), - Case("Testing Multi Threads Erase Program Read", test_qspif_multi_threads) -}; - -Specification specification(test_setup, cases); - - -int main() -{ - mbed_trace_init(); - utest_printf("MAIN STARTS\n"); - return !Harness::run(specification); -} diff --git a/components/storage/blockdevice/COMPONENT_SPIF/TESTS/block_device/spif/main.cpp b/components/storage/blockdevice/COMPONENT_SPIF/TESTS/block_device/spif/main.cpp deleted file mode 100644 index ad2b2636ed..0000000000 --- a/components/storage/blockdevice/COMPONENT_SPIF/TESTS/block_device/spif/main.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "SPIFBlockDevice.h" -#include "mbed_trace.h" -#include "rtos/Thread.h" -#include - -using namespace utest::v1; - -#define TEST_BLOCK_COUNT 10 -#define TEST_ERROR_MASK 16 -#define SPIF_TEST_NUM_OF_THREADS 5 - -const struct { - const char *name; - bd_size_t (BlockDevice::*method)() const; -} ATTRS[] = { - {"read size", &BlockDevice::get_read_size}, - {"program size", &BlockDevice::get_program_size}, - {"erase size", &BlockDevice::get_erase_size}, - {"total size", &BlockDevice::size}, -}; - -static SingletonPtr _mutex; - -// Mutex is protecting rand() per srand for buffer writing and verification. -// Mutex is also protecting printouts for clear logs. -// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test! -void basic_erase_program_read_test(SPIFBlockDevice &block_device, bd_size_t block_size, uint8_t *write_block, - uint8_t *read_block, unsigned addrwidth) -{ - int err = 0; - _mutex->lock(); - - // Make sure block address per each test is unique - static unsigned block_seed = 1; - srand(block_seed++); - - // Find a random block - bd_addr_t block = (rand() * block_size) % block_device.size(); - - // Use next random number as temporary seed to keep - // the address progressing in the pseudorandom sequence - unsigned seed = rand(); - - // Fill with random sequence - srand(seed); - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - write_block[i_ind] = 0xff & rand(); - } - // Write, sync, and read the block - utest_printf("\ntest %0*llx:%llu...", addrwidth, block, block_size); - _mutex->unlock(); - - err = block_device.erase(block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = block_device.program(write_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - err = block_device.read(read_block, block, block_size); - TEST_ASSERT_EQUAL(0, err); - - _mutex->lock(); - // Check that the data was unmodified - srand(seed); - int val_rand; - for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) { - val_rand = rand(); - if ((0xff & val_rand) != read_block[i_ind]) { - utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size); - utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand), read_block[i_ind], - write_block[i_ind]); - } - TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]); - } - _mutex->unlock(); -} - -void test_spif_random_program_read_erase() -{ - utest_printf("\nTest Random Program Read Erase Starts..\n"); - - SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, - MBED_CONF_SPIF_DRIVER_SPI_CLK, - MBED_CONF_SPIF_DRIVER_SPI_CS); - - int err = block_device.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (block_device.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_size_t block_size = block_device.get_erase_size(); - unsigned addrwidth = ceil(log(float(block_device.size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth); - } - - err = block_device.deinit(); - TEST_ASSERT_EQUAL(0, err); - -end: - delete[] write_block; - delete[] read_block; -} - -void test_spif_unaligned_erase() -{ - utest_printf("\nTest Unaligned Erase Starts..\n"); - - SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, - MBED_CONF_SPIF_DRIVER_SPI_CLK, - MBED_CONF_SPIF_DRIVER_SPI_CS); - - int err = block_device.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (block_device.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - bd_addr_t addr = 0; - bd_size_t sector_erase_size = block_device.get_erase_size(addr); - unsigned addrwidth = ceil(log(float(block_device.size() - 1)) / log(float(16))) + 1; - - utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size); - - //unaligned start address - addr += 1; - err = block_device.erase(addr, sector_erase_size - 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = block_device.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = block_device.erase(addr, 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //unaligned end address - addr = 0; - - err = block_device.erase(addr, 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - err = block_device.erase(addr, sector_erase_size + 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - //erase size exceeds flash device size - err = block_device.erase(addr, block_device.size() + 1); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err); - - // Valid erase - err = block_device.erase(addr, sector_erase_size); - TEST_ASSERT_EQUAL(SPIF_BD_ERROR_OK, err); - - err = block_device.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - -static void test_spif_thread_job(void *block_device_ptr/*, int thread_num*/) -{ - static int thread_num = 0; - thread_num++; - SPIFBlockDevice *block_device = (SPIFBlockDevice *)block_device_ptr; - utest_printf("\n Thread %d Started \n", thread_num); - - bd_size_t block_size = block_device->get_erase_size(); - unsigned addrwidth = ceil(log(float(block_device->size() - 1)) / log(float(16))) + 1; - - uint8_t *write_block = new (std::nothrow) uint8_t[block_size]; - uint8_t *read_block = new (std::nothrow) uint8_t[block_size]; - if (!write_block || !read_block) { - utest_printf("\n Not enough memory for test"); - goto end; - } - - for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test((*block_device), block_size, write_block, read_block, addrwidth); - } - -end: - delete[] write_block; - delete[] read_block; -} - -void test_spif_multi_threads() -{ - utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n"); - - SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, - MBED_CONF_SPIF_DRIVER_SPI_CLK, - MBED_CONF_SPIF_DRIVER_SPI_CS); - - int err = block_device.init(); - TEST_ASSERT_EQUAL(0, err); - - for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) { - static const char *prefixes[] = {"", "k", "M", "G"}; - for (int i_ind = 3; i_ind >= 0; i_ind--) { - bd_size_t size = (block_device.*ATTRS[atr].method)(); - if (size >= (1ULL << 10 * i_ind)) { - utest_printf("%s: %llu%sbytes (%llubytes)\n", - ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size); - break; - } - } - } - - rtos::Thread spif_bd_thread[SPIF_TEST_NUM_OF_THREADS]; - - osStatus threadStatus; - int i_ind; - - for (i_ind = 0; i_ind < SPIF_TEST_NUM_OF_THREADS; i_ind++) { - threadStatus = spif_bd_thread[i_ind].start(test_spif_thread_job, (void *)&block_device); - if (threadStatus != 0) { - utest_printf("\n Thread %d Start Failed!", i_ind + 1); - } - } - - for (i_ind = 0; i_ind < SPIF_TEST_NUM_OF_THREADS; i_ind++) { - spif_bd_thread[i_ind].join(); - } - - err = block_device.deinit(); - TEST_ASSERT_EQUAL(0, err); -} - -// Test setup -utest::v1::status_t test_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(60, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -Case cases[] = { - Case("Testing unaligned erase blocks", test_spif_unaligned_erase), - Case("Testing read write random blocks", test_spif_random_program_read_erase), - Case("Testing Multi Threads Erase Program Read", test_spif_multi_threads) -}; - -Specification specification(test_setup, cases); - -int main() -{ - mbed_trace_init(); - utest_printf("MAIN STARTS\n"); - return !Harness::run(specification); -} diff --git a/features/storage/TESTS/blockdevice/general_block_device/main.cpp b/features/storage/TESTS/blockdevice/general_block_device/main.cpp index fecfe1a0db..760e6da6cb 100644 --- a/features/storage/TESTS/blockdevice/general_block_device/main.cpp +++ b/features/storage/TESTS/blockdevice/general_block_device/main.cpp @@ -183,7 +183,7 @@ static BlockDevice *get_bd_instance(uint8_t bd_type) // Mutex is also protecting printouts for clear logs. // Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test! void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_size, uint8_t *write_block, - uint8_t *read_block, unsigned addrwidth) + uint8_t *read_block, unsigned addrwidth, int thread_num) { int err = 0; _mutex->lock(); @@ -193,7 +193,13 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si srand(block_seed++); // Find a random block - bd_addr_t block = (rand() * block_size) % (block_device->size()); + int threaded_rand_number = (rand() * TEST_NUM_OF_THREADS) + thread_num; + bd_addr_t block = (threaded_rand_number * block_size) % block_device->size(); + + // Flashiap boards with inconsistent sector size will not align with random start addresses + if (bd_arr[test_iteration] == flashiap) { + block = 0; + } // Use next random number as temporary seed to keep // the address progressing in the pseudorandom sequence @@ -206,7 +212,11 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si } // Write, sync, and read the block utest_printf("test %0*llx:%llu...\n", addrwidth, block, block_size); - _mutex->unlock(); + + // Thread test for flashiap write to the same sector, so all write/read/erase actions should be locked + if (bd_arr[test_iteration] != flashiap) { + _mutex->unlock(); + } err = block_device->erase(block, block_size); TEST_ASSERT_EQUAL(0, err); @@ -217,7 +227,10 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si err = block_device->read(read_block, block, block_size); TEST_ASSERT_EQUAL(0, err); - _mutex->lock(); + if (bd_arr[test_iteration] != flashiap) { + _mutex->lock(); + } + // Check that the data was unmodified srand(seed); int val_rand; @@ -276,7 +289,7 @@ void test_random_program_read_erase() } for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth); + basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth, 0); } end: @@ -287,7 +300,9 @@ end: static void test_thread_job(void *block_device_ptr) { static int thread_num = 0; - thread_num++; + _mutex->lock(); + int block_num = thread_num++; + _mutex->unlock(); BlockDevice *block_device = (BlockDevice *)block_device_ptr; bd_size_t block_size = block_device->get_erase_size(); @@ -302,7 +317,7 @@ static void test_thread_job(void *block_device_ptr) } for (int b = 0; b < TEST_BLOCK_COUNT; b++) { - basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth); + basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth, block_num); } end: @@ -384,6 +399,11 @@ void test_erase_functionality() start_address -= start_address % erase_size; // align with erase_block utest_printf("start_address=0x%016" PRIx64 "\n", start_address); + // Flashiap boards with inconsistent sector size will not align with random start addresses + if (bd_arr[test_iteration] == flashiap) { + start_address = 0; + } + // Allocate buffer for write test data uint8_t *data_buf = (uint8_t *)malloc(data_buf_size); TEST_SKIP_UNLESS_MESSAGE(data_buf, "Not enough memory for test.\n"); @@ -446,6 +466,11 @@ void test_contiguous_erase_write_read() TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); + // Flashiap boards with inconsistent sector size will not align with random start addresses + if (bd_arr[test_iteration] == flashiap) { + return; + } + // Test flow: // 1. Erase whole test area // - Tests contiguous erase @@ -622,6 +647,65 @@ void test_program_read_small_data_sizes() delete buff_block_device; } + +void test_unaligned_erase_blocks() +{ + + utest_printf("\nTest Unaligned Erase Starts..\n"); + + TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); + + TEST_SKIP_UNLESS_MESSAGE(block_device->get_erase_value() != -1, "block device has no erase functionality."); + + bd_addr_t addr = 0; + bd_size_t sector_erase_size = block_device->get_erase_size(addr); + unsigned addrwidth = ceil(log(float(block_device->size() - 1)) / log(float(16))) + 1; + + utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size); + + //unaligned start address + addr += 1; + int err = block_device->erase(addr, sector_erase_size - 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + err = block_device->erase(addr, sector_erase_size); + TEST_ASSERT_NOT_EQUAL(0, err); + + err = block_device->erase(addr, 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + //unaligned end address + addr = 0; + + err = block_device->erase(addr, 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + err = block_device->erase(addr, sector_erase_size + 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + //erase size exceeds flash device size + err = block_device->erase(addr, block_device->size() + 1); + TEST_ASSERT_NOT_EQUAL(0, err); + + // Valid erase + err = block_device->erase(addr, sector_erase_size); + TEST_ASSERT_EQUAL(0, err); +} + +void test_deinit_bd() +{ + utest_printf("\nTest deinit block device.\n"); + + test_iteration++; + + TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); + + int err = block_device->deinit(); + TEST_ASSERT_EQUAL(0, err); + + block_device = NULL; +} + void test_get_type_functionality() { utest_printf("\nTest get blockdevice type..\n"); @@ -645,20 +729,6 @@ void test_get_type_functionality() #endif } -void test_deinit_bd() -{ - utest_printf("\nTest deinit block device.\n"); - - test_iteration++; - - TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found."); - - int err = block_device->deinit(); - TEST_ASSERT_EQUAL(0, err); - - block_device = NULL; -} - utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { greentea_case_failure_abort_handler(source, reason); @@ -678,6 +748,7 @@ template_case_t template_cases[] = { {"Testing contiguous erase, write and read", test_contiguous_erase_write_read, greentea_failure_handler}, {"Testing BlockDevice erase functionality", test_erase_functionality, greentea_failure_handler}, {"Testing program read small data sizes", test_program_read_small_data_sizes, greentea_failure_handler}, + {"Testing unaligned erase blocks", test_unaligned_erase_blocks, greentea_failure_handler}, {"Testing Deinit block device", test_deinit_bd, greentea_failure_handler}, }; diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/sdk/TOOLCHAIN_IAR/libublox-odin-w2-driver.a b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/sdk/TOOLCHAIN_IAR/libublox-odin-w2-driver.a index ae7a688baa..c6b0633c76 100644 Binary files a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/sdk/TOOLCHAIN_IAR/libublox-odin-w2-driver.a and b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/sdk/TOOLCHAIN_IAR/libublox-odin-w2-driver.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a index 9a92d8a7f5..a6a9503f9d 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_ADV_WISE_1530/libwiced_drivers.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a index 920dea3860..87905eea96 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_MXCHIP_EMW3166/libwiced_drivers.a differ diff --git a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a index 951a21ccac..35d031b0cf 100644 Binary files a/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a and b/targets/TARGET_WICED/TOOLCHAIN_IAR/TARGET_MTB_USI_WM_BN_BM_22/libwiced_drivers.a differ diff --git a/targets/targets.json b/targets/targets.json index da1673c9cf..1fe0552f31 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -1502,6 +1502,7 @@ }, "SDT64B": { "inherits": ["K64F"], + "components_add": ["FLASHIAP"], "extra_labels_add": ["K64F"], "extra_labels_remove": ["FRDM"], "components_remove": ["SD"], @@ -2200,6 +2201,7 @@ }, "NUCLEO_F207ZG": { "inherits": ["FAMILY_STM32"], + "components_add": ["FLASHIAP"], "supported_form_factors": ["ARDUINO", "MORPHO"], "core": "Cortex-M3", "extra_labels_add": ["STM32F2", "STM32F207ZG", "STM_EMAC"], @@ -2479,6 +2481,7 @@ }, "MTB_MXCHIP_EMW3166": { "inherits": ["FAMILY_STM32"], + "supported_toolchains": ["ARM", "GCC_ARM", "IAR"], "core": "Cortex-M4F", "extra_labels_add": [ "STM32F4", @@ -2511,6 +2514,7 @@ }, "USI_WM_BN_BM_22": { "inherits": ["FAMILY_STM32"], + "supported_toolchains": ["ARM", "GCC_ARM", "IAR"], "components_add": ["SPIF", "FLASHIAP"], "core": "Cortex-M4F", "extra_labels_add": [ @@ -2563,7 +2567,7 @@ } }, "DISCO_F413ZH": { - "components_add": ["QSPIF"], + "components_add": ["QSPIF", "FLASHIAP"], "inherits": ["FAMILY_STM32"], "supported_form_factors": ["ARDUINO"], "core": "Cortex-M4F", @@ -2929,6 +2933,7 @@ }, "NUCLEO_F767ZI": { "inherits": ["FAMILY_STM32"], + "components_add": ["FLASHIAP"], "core": "Cortex-M7FD", "extra_labels_add": [ "STM32F7", @@ -3794,7 +3799,7 @@ "STM32F746NG", "STM_EMAC" ], - "components_add": ["QSPIF"], + "components_add": ["QSPIF", "FLASHIAP"], "supported_form_factors": ["ARDUINO"], "config": { "clock_source": { @@ -4302,7 +4307,7 @@ "release_versions": ["5"], "device_has_remove": [], "extra_labels_add": ["PSA"], - "components_add": ["FLASHIAP"], + "components_add": ["SD", "FLASHIAP"], "macros_add": [ "MBEDTLS_PSA_CRYPTO_C" ], @@ -4388,6 +4393,7 @@ }, "UBLOX_C030_U201": { "inherits": ["UBLOX_C030"], + "components_add": ["SD", "FLASHIAP"], "release_versions": ["5"] }, "UBLOX_C030_N211": { @@ -5210,6 +5216,7 @@ }, "GR_LYCHEE": { "inherits": ["RZ_A1XX"], + "components_add": ["SD", "FLASHIAP"], "supported_form_factors": ["ARDUINO"], "extra_labels_add": ["RZA1UL", "MBRZA1LU"], "components_add": ["SD"], @@ -6973,6 +6980,7 @@ }, "NUMAKER_PFM_NUC472": { "core": "Cortex-M4F", + "components_add": ["SD", "FLASHIAP"], "default_toolchain": "ARM", "extra_labels": [ "NUVOTON", @@ -7290,12 +7298,12 @@ "FLASH" ], "public": false, - "supported_toolchains": ["GCC_ARM", "ARM", "IAR"], + "supported_toolchains": ["GCC_ARM", "ARM"], "post_binary_hook": { "function": "RTL8195ACode.binary_hook", "toolchains": ["ARM_STD", "GCC_ARM", "IAR"] }, - "release_versions": ["5"], + "release_versions": [], "overrides": { "network-default-interface-type": "WIFI" } @@ -7545,10 +7553,12 @@ }, "NUMAKER_PFM_M487": { "inherits": ["MCU_M480"], + "components_add": ["SD", "FLASHIAP"], "device_name": "M487JIDAE" }, "NUMAKER_IOT_M487": { "inherits": ["MCU_M480"], + "components_add": ["FLASHIAP"], "device_name": "M487JIDAE" }, "TMPM066": { @@ -7841,7 +7851,7 @@ "inherits": ["Target"], "macros": ["MBED_MPU_CUSTOM"], "default_toolchain": "GCC_ARM", - "supported_toolchains": ["GCC_ARM", "IAR", "ARM"], + "supported_toolchains": ["GCC_ARM", "ARM", "IAR"], "core": "Cortex-M4F", "OUTPUT_EXT": "hex", "device_has": [ @@ -7887,6 +7897,8 @@ "inherits": ["MCU_PSOC6_M4"], "features": ["BLE"], "supported_form_factors": ["ARDUINO"], + "supported_toolchains": ["GCC_ARM", "ARM"], + "release_versions": ["5"], "extra_labels_add": ["PSOC6_01", "WICED", "CYW43XXX", "CYW4343X", "CORDIO"], "macros_add": ["CY8C6247BZI_D54", "PSOC6_DYNSRM_DISABLE=1"], "detect_code": ["1900"], @@ -7902,6 +7914,8 @@ "inherits": ["MCU_PSOC6_M4"], "features": ["BLE"], "device_has_remove": ["ANALOGOUT"], + "supported_toolchains": ["GCC_ARM", "ARM"], + "release_versions": ["5"], "extra_labels_add": ["PSOC6_02", "WICED", "CYW43XXX", "CYW4343X", "CORDIO"], "macros_add": ["CY8C624ABZI_D44", "PSOC6_DYNSRM_DISABLE=1"], "public": false, @@ -7930,6 +7944,8 @@ }, "CY8CKIT_062_4343W": { "inherits": ["MCU_PSOC6_M4"], + "supported_toolchains": ["GCC_ARM", "ARM"], + "release_versions": ["5"], "features": ["BLE"], "supported_form_factors": ["ARDUINO"], "device_has_remove": ["ANALOGOUT"], @@ -7947,6 +7963,8 @@ "CYW943012P6EVB_01": { "inherits": ["MCU_PSOC6_M4"], "features": ["BLE"], + "supported_toolchains": ["GCC_ARM", "ARM"], + "release_versions": ["5"], "extra_labels_add": ["PSOC6_01", "WICED", "CYW43XXX", "CYW43012", "CORDIO"], "macros_add": ["CY8C6247BZI_D54", "PSOC6_DYNSRM_DISABLE=1"], "detect_code": ["1906"], diff --git a/tools/build_api.py b/tools/build_api.py index 65f96ec2a2..3237ad74e6 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -193,7 +193,7 @@ def is_official_target(target_name, version): elif version == '5': # For version 5, ARM, GCC_ARM, and IAR toolchain support is required required_toolchains = [ - set(['ARM', 'GCC_ARM', 'IAR']), + set(['ARM', 'GCC_ARM']), set(['ARMC6']) ] supported_toolchains = set(target.supported_toolchains) diff --git a/tools/export/iar/__init__.py b/tools/export/iar/__init__.py index bb17c36c2d..5788e3fbee 100644 --- a/tools/export/iar/__init__.py +++ b/tools/export/iar/__init__.py @@ -86,8 +86,9 @@ class IAR(Exporter): "CExtraOptionsCheck": 0, "CExtraOptions": "", "CMSISDAPJtagSpeedList": 0, + "DSPExtension": 0, + "TrustZone": 0, } - iar_defaults.update(device_info) IARdevice = namedtuple('IARdevice', iar_defaults.keys()) return IARdevice(**iar_defaults) @@ -126,6 +127,10 @@ class IAR(Exporter): except TargetNotSupportedException: debugger = "CMSISDAP" + trustZoneMode = 0 + if self.toolchain.target.core.endswith("-NS"): + trustZoneMode = 1 + ctx = { 'name': self.project_name, 'groups': self.iar_groups(self.format_src(srcs)), @@ -134,6 +139,7 @@ class IAR(Exporter): 'device': self.iar_device(), 'ewp': sep+self.project_name + ".ewp", 'debugger': debugger, + 'trustZoneMode': trustZoneMode, } ctx.update(flags) diff --git a/tools/export/iar/ewp.tmpl b/tools/export/iar/ewp.tmpl index ccac59e047..add65d47a7 100644 --- a/tools/export/iar/ewp.tmpl +++ b/tools/export/iar/ewp.tmpl @@ -1,974 +1,1043 @@ - + - 2 - - {{name}} - - ARM - - 1 - - General - 3 + 3 + + {{name}} + + ARM + + 1 + + General + 3 - 24 + 31 1 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - ICCARM - 2 - - 31 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AARM - 2 - - 9 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OBJCOPY - 0 - - 1 - 1 - 1 - - - - - - - - - CUSTOM - 3 - - - - - - - BICOMP - 0 - - - - BUILDACTION - 1 - - - - - - - ILINK - 0 - - 16 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IARCHIVE - 0 - - 0 - 1 - 1 - - - - - - - BILINK - 0 - - - - {% for group in groups -%} - - {{group.name}} - {% for file in group.files -%} - {{file}} - {% endfor -%} - - {% endfor -%} + + + ICCARM + 2 + + 35 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 10 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + 0 + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + ILINK + 0 + + 22 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + + {% for group in groups -%} + + {{group.name}} + {% for file in group.files -%} + {{file}} + {% endfor -%} + + {% endfor -%} diff --git a/tools/export/iar/iar_definitions.json b/tools/export/iar/iar_definitions.json index 5ef5b21a90..57661e5f97 100644 --- a/tools/export/iar/iar_definitions.json +++ b/tools/export/iar/iar_definitions.json @@ -340,6 +340,7 @@ "GFPUCoreSlave2": 39 }, "M2351KIAAEES": { - "OGChipSelectEditMenu": "M2351 series\tNuvoton M2351 series" + "OGChipSelectEditMenu": "M2351 series\tNuvoton M2351 series", + "TrustZone": 1 } } diff --git a/tools/test/toolchains/api_test.py b/tools/test/toolchains/api_test.py index fded2c672e..f8989cf211 100644 --- a/tools/test/toolchains/api_test.py +++ b/tools/test/toolchains/api_test.py @@ -74,7 +74,7 @@ def test_arm_version_check(_run_cmd): def test_iar_version_check(_run_cmd): set_targets_json_location() _run_cmd.return_value = (""" - IAR ANSI C/C++ Compiler V7.80.1.28/LNX for ARM + IAR ANSI C/C++ Compiler V8.32.1/LNX for ARM """, "", 0) notifier = MockNotifier() toolchain = TOOLCHAIN_CLASSES["IAR"](TARGET_MAP["K64F"], notify=notifier) diff --git a/tools/toolchains/iar.py b/tools/toolchains/iar.py index dd3906a162..7751795aad 100644 --- a/tools/toolchains/iar.py +++ b/tools/toolchains/iar.py @@ -33,7 +33,7 @@ class IAR(mbedToolchain): DIAGNOSTIC_PATTERN = re.compile('"(?P[^"]+)",(?P[\d]+)\s+(?PWarning|Error|Fatal error)(?P.+)') INDEX_PATTERN = re.compile('(?P\s*)\^') IAR_VERSION_RE = re.compile(b"IAR ANSI C/C\+\+ Compiler V(\d+\.\d+)") - IAR_VERSION = LooseVersion("7.80") + IAR_VERSION = LooseVersion("8.32") @staticmethod def check_executable():