Skip to content

Commit

Permalink
Add in-tree support for out-of-tree SDIO driver (ARMmbed/sdio-driver#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias-arm committed Aug 12, 2019
1 parent b81aeff commit 8f1f102
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 14 deletions.
23 changes: 20 additions & 3 deletions features/storage/TESTS/blockdevice/general_block_device/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include "SDBlockDevice.h"
#endif

#if COMPONENT_SDIO
#include "SDIOBlockDevice.h"
#endif

#if COMPONENT_FLASHIAP
#include "FlashIAPBlockDevice.h"
#endif
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down
3 changes: 3 additions & 0 deletions features/storage/TESTS/filesystem/general_filesystem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 61 additions & 2 deletions features/storage/kvstore/conf/kv_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion features/storage/system_storage/SystemStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include "SDBlockDevice.h"
#endif

#if COMPONENT_SDIO
#include "SDIOBlockDevice.h"
#endif

#if COMPONENT_FLASHIAP
#include "FlashIAPBlockDevice.h"
#endif
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 11 additions & 6 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@
"MBED_MPU_CUSTOM",
"NXP_LPADC"
],
"components_add": ["FLASHIAP"],
"components_add": ["FLASHIAP", "SDIO"],
"extra_labels_add": [
"M33_NS",
"PSA",
Expand All @@ -2107,7 +2107,8 @@
"SPI",
"SPISLAVE",
"FLASH",
"STDIO_MESSAGES"
"STDIO_MESSAGES",
"SDIO"
],
"post_binary_hook": {"function": "LPC55S69Code.binary_hook"},
"secure_image_filename": "tfm.bin",
Expand Down Expand Up @@ -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",
Expand All @@ -3934,7 +3935,9 @@
"FLASH",
"QSPI",
"MPU",
"USBDEVICE"
"USBDEVICE",
"SDIO",
"SDIO_ASYNC"
],
"release_versions": ["2", "5"],
"device_name": "STM32F469NI",
Expand Down Expand Up @@ -4079,7 +4082,7 @@
"STM32F746NG",
"STM_EMAC"
],
"components_add": ["QSPIF", "FLASHIAP"],
"components_add": ["QSPIF", "FLASHIAP", "SDIO"],
"supported_form_factors": ["ARDUINO"],
"config": {
"clock_source": {
Expand Down Expand Up @@ -4113,7 +4116,9 @@
"FLASH",
"QSPI",
"USBDEVICE",
"MPU"
"MPU",
"SDIO",
"SDIO_ASYNC"
],
"release_versions": ["2", "5"],
"device_name": "STM32F746NG",
Expand Down

0 comments on commit 8f1f102

Please sign in to comment.