diff --git a/features/storage/TESTS/blockdevice/general_block_device/main.cpp b/features/storage/TESTS/blockdevice/general_block_device/main.cpp index cfe324780b7..2cfd3f2cb71 100644 --- a/features/storage/TESTS/blockdevice/general_block_device/main.cpp +++ b/features/storage/TESTS/blockdevice/general_block_device/main.cpp @@ -44,6 +44,10 @@ #include "SDBlockDevice.h" #endif +#if COMPONENT_SDIO +#include "SDIOBlockDevice.h" +#endif + #if COMPONENT_FLASHIAP #include "FlashIAPBlockDevice.h" #endif @@ -84,11 +88,12 @@ enum bd_type { qspif, dataflash, sd, + sdio, flashiap, default_bd }; -uint8_t bd_arr[5] = {0}; +uint8_t bd_arr[6] = {0}; static uint8_t test_iteration = 0; @@ -156,6 +161,13 @@ static BlockDevice *get_bd_instance(uint8_t bd_type) MBED_CONF_SD_SPI_CS ); return &default_bd; +#endif + break; + } + case sdio: { +#if COMPONENT_SDIO + static SDIOBlockDevice default_bd(MBED_CONF_SDIO_CD); + return &default_bd; #endif break; } @@ -707,6 +719,8 @@ void test_get_type_functionality() TEST_ASSERT_EQUAL(0, strcmp(bd_type, "DATAFLASH")); #elif COMPONENT_SD TEST_ASSERT_EQUAL(0, strcmp(bd_type, "SD")); +#elif COMPONENT_SDIO + TEST_ASSERT_EQUAL(0, strcmp(bd_type, "SDIO")); #elif COMPONET_FLASHIAP TEST_ASSERT_EQUAL(0, strcmp(bd_type, "FLASHIAP")); #endif @@ -758,14 +772,17 @@ int get_bd_count() #if COMPONENT_SD bd_arr[count++] = sd; //3 #endif +#if COMPONENT_SDIO + bd_arr[count++] = sdio; //4 +#endif #if COMPONENT_FLASHIAP - bd_arr[count++] = flashiap; //4 + bd_arr[count++] = flashiap; //5 #endif return count; } -static const char *prefix[] = {"SPIF ", "QSPIF ", "DATAFLASH ", "SD ", "FLASHIAP ", "DEFAULT "}; +static const char *prefix[] = {"SPIF ", "QSPIF ", "DATAFLASH ", "SD ", "SDIO", "FLASHIAP ", "DEFAULT "}; int main() { diff --git a/features/storage/TESTS/filesystem/general_filesystem/main.cpp b/features/storage/TESTS/filesystem/general_filesystem/main.cpp index 732d0ca94ea..c1cba2a3842 100644 --- a/features/storage/TESTS/filesystem/general_filesystem/main.cpp +++ b/features/storage/TESTS/filesystem/general_filesystem/main.cpp @@ -26,6 +26,9 @@ #elif COMPONENT_SD #include "SDBlockDevice.h" #include "FATFileSystem.h" +#elif COMPONENT_SDIO +#include "SDBIOlockDevice.h" +#include "FATFileSystem.h" #else #error [NOT_SUPPORTED] storage test not supported on this platform #endif diff --git a/features/storage/TESTS/kvstore/direct_access_devicekey_test/main.cpp b/features/storage/TESTS/kvstore/direct_access_devicekey_test/main.cpp index 3c31f6859f7..f190745a1d9 100644 --- a/features/storage/TESTS/kvstore/direct_access_devicekey_test/main.cpp +++ b/features/storage/TESTS/kvstore/direct_access_devicekey_test/main.cpp @@ -287,7 +287,7 @@ void test_direct_access_to_device_inject_root() #if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH internal_start_address = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS; internal_rbp_size = MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE; -#elif COMPONENT_SD +#elif COMPONENT_SD || COMPONENT_SDIO internal_start_address = MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS; internal_rbp_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE; #elif COMPONENT_FLASHIAP diff --git a/features/storage/kvstore/conf/kv_config.cpp b/features/storage/kvstore/conf/kv_config.cpp index 7105a108ed1..ea7c2bc22f6 100644 --- a/features/storage/kvstore/conf/kv_config.cpp +++ b/features/storage/kvstore/conf/kv_config.cpp @@ -51,6 +51,10 @@ #include "SDBlockDevice.h" #endif +#if COMPONENT_SDIO +#include "SDIOBlockDevice.h" +#endif + /** * @brief This function initializes internal memory secure storage * This includes a TDBStore instance with a FlashIAPBlockdevice @@ -250,7 +254,7 @@ FileSystem *_get_filesystem_default(const char *mount) { #if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH return _get_filesystem_LITTLE(mount); -#elif COMPONENT_SD +#elif COMPONENT_SD || COMPONENT_SDIO return _get_filesystem_FAT(mount); #else BlockDevice *bd = get_other_blockdevice(); @@ -618,6 +622,59 @@ BlockDevice *_get_blockdevice_SD(bd_addr_t start_address, bd_size_t size) #endif } +BlockDevice *_get_blockdevice_SDIO(bd_addr_t start_address, bd_size_t size) +{ +#if COMPONENT_SDIO + + bd_addr_t aligned_end_address; + bd_addr_t aligned_start_address; + + static SDIOBlockDevice bd(MBED_CONF_SDIO_CD); + + if (bd.init() != MBED_SUCCESS) { + tr_error("KV Config: SDIOBlockDevice init fail"); + return NULL; + } + + if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL_NO_RBP") == 0 || + strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) { + //In TDBStore profile, we have a constraint of 4GByte + if (start_address == 0 && size == 0 && bd.size() < (uint32_t)(-1)) { + return &bd; + } + + //If the size of external storage is bigger than 4G we need to slice it. + size = size != 0 ? size : align_down(bd.size(), bd.get_erase_size(bd.size() - 1)); + + if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) { + tr_error("KV Config: Fail to get addresses for SlicingBlockDevice."); + return NULL; + } + + if (aligned_end_address - aligned_start_address != (uint32_t)(aligned_end_address - aligned_start_address)) { + aligned_end_address = aligned_start_address + (uint32_t)(-1);//Support up to 4G only + } + } else { + //For all other KVStore profiles beside TDBStore we take the entire external memory space. + if (start_address == 0 && size == 0) { + return &bd; + } + + if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) { + tr_error("KV Config: Fail to get addresses for SlicingBlockDevice."); + return NULL; + } + } + + aligned_end_address = align_down(aligned_end_address, bd.get_erase_size(aligned_end_address)); + static SlicingBlockDevice sbd(&bd, aligned_start_address, aligned_end_address); + return &sbd; + +#else + return NULL; +#endif +} + BlockDevice *_get_blockdevice_default(bd_addr_t start_address, bd_size_t size) { #if COMPONENT_QSPIF @@ -628,6 +685,8 @@ BlockDevice *_get_blockdevice_default(bd_addr_t start_address, bd_size_t size) return _get_blockdevice_DATAFLASH(start_address, size); #elif COMPONENT_SD return _get_blockdevice_SD(start_address, size); +#elif COMPONENT_SDIO + return _get_blockdevice_SDIO(start_address, size); #else tr_error("KV Config: No default component define in target.json for this target."); return NULL; @@ -1119,7 +1178,7 @@ int _storage_config_default() { #if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH return _storage_config_TDB_EXTERNAL(); -#elif COMPONENT_SD +#elif COMPONENT_SD || COMPONENT_SDIO return _storage_config_FILESYSTEM(); #elif COMPONENT_FLASHIAP return _storage_config_TDB_INTERNAL(); diff --git a/features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp b/features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp index 68085164a1d..a74ce328ff5 100644 --- a/features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp +++ b/features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp @@ -127,7 +127,7 @@ int get_expected_internal_TDBStore_position(uint32_t *out_tdb_start_offset, uin #if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH *out_tdb_start_offset = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS; tdb_size = MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE; -#elif COMPONENT_SD +#elif COMPONENT_SD || COMPONENT_SDIO tdb_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE; #else return MBED_ERROR_UNSUPPORTED; diff --git a/features/storage/system_storage/SystemStorage.cpp b/features/storage/system_storage/SystemStorage.cpp index 8003a3c481a..062b95b8365 100644 --- a/features/storage/system_storage/SystemStorage.cpp +++ b/features/storage/system_storage/SystemStorage.cpp @@ -41,6 +41,10 @@ #include "SDBlockDevice.h" #endif +#if COMPONENT_SDIO +#include "SDIOBlockDevice.h" +#endif + #if COMPONENT_FLASHIAP #include "FlashIAPBlockDevice.h" #endif @@ -145,6 +149,12 @@ MBED_WEAK BlockDevice *BlockDevice::get_default_instance() return &default_bd; +#elif COMPONENT_SDIO + + static SDIOBlockDevice default_bd(MBED_CONF_SDIO_CD); + + return &default_bd; + #elif COMPONENT_FLASHIAP #if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF) @@ -193,7 +203,7 @@ MBED_WEAK FileSystem *FileSystem::get_default_instance() return &flash; -#elif COMPONENT_SD +#elif COMPONENT_SD || COMPONENT_SDIO static FATFileSystem sdcard("sd", BlockDevice::get_default_instance()); sdcard.set_as_default(); diff --git a/targets/targets.json b/targets/targets.json index 1a6b9a1f89a..e51cc645ae6 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -2085,7 +2085,7 @@ "MBED_MPU_CUSTOM", "NXP_LPADC" ], - "components_add": ["FLASHIAP"], + "components_add": ["FLASHIAP", "SDIO"], "extra_labels_add": [ "M33_NS", "PSA", @@ -2107,7 +2107,8 @@ "SPI", "SPISLAVE", "FLASH", - "STDIO_MESSAGES" + "STDIO_MESSAGES", + "SDIO" ], "post_binary_hook": {"function": "LPC55S69Code.binary_hook"}, "secure_image_filename": "tfm.bin", @@ -3907,7 +3908,7 @@ "bootloader_supported": true }, "DISCO_F469NI": { - "components_add": ["QSPIF"], + "components_add": ["QSPIF", "SDIO"], "inherits": ["FAMILY_STM32"], "supported_form_factors": ["ARDUINO"], "core": "Cortex-M4F", @@ -3934,7 +3935,9 @@ "FLASH", "QSPI", "MPU", - "USBDEVICE" + "USBDEVICE", + "SDIO", + "SDIO_ASYNC" ], "release_versions": ["2", "5"], "device_name": "STM32F469NI", @@ -4079,7 +4082,7 @@ "STM32F746NG", "STM_EMAC" ], - "components_add": ["QSPIF", "FLASHIAP"], + "components_add": ["QSPIF", "FLASHIAP", "SDIO"], "supported_form_factors": ["ARDUINO"], "config": { "clock_source": { @@ -4113,7 +4116,9 @@ "FLASH", "QSPI", "USBDEVICE", - "MPU" + "MPU", + "SDIO", + "SDIO_ASYNC" ], "release_versions": ["2", "5"], "device_name": "STM32F746NG",