Skip to content

Commit 8f1f102

Browse files
committed
Add in-tree support for out-of-tree SDIO driver (ARMmbed/sdio-driver#4)
1 parent b81aeff commit 8f1f102

File tree

7 files changed

+108
-14
lines changed

7 files changed

+108
-14
lines changed

features/storage/TESTS/blockdevice/general_block_device/main.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
#include "SDBlockDevice.h"
4545
#endif
4646

47+
#if COMPONENT_SDIO
48+
#include "SDIOBlockDevice.h"
49+
#endif
50+
4751
#if COMPONENT_FLASHIAP
4852
#include "FlashIAPBlockDevice.h"
4953
#endif
@@ -84,11 +88,12 @@ enum bd_type {
8488
qspif,
8589
dataflash,
8690
sd,
91+
sdio,
8792
flashiap,
8893
default_bd
8994
};
9095

91-
uint8_t bd_arr[5] = {0};
96+
uint8_t bd_arr[6] = {0};
9297

9398
static uint8_t test_iteration = 0;
9499

@@ -156,6 +161,13 @@ static BlockDevice *get_bd_instance(uint8_t bd_type)
156161
MBED_CONF_SD_SPI_CS
157162
);
158163
return &default_bd;
164+
#endif
165+
break;
166+
}
167+
case sdio: {
168+
#if COMPONENT_SDIO
169+
static SDIOBlockDevice default_bd(MBED_CONF_SDIO_CD);
170+
return &default_bd;
159171
#endif
160172
break;
161173
}
@@ -707,6 +719,8 @@ void test_get_type_functionality()
707719
TEST_ASSERT_EQUAL(0, strcmp(bd_type, "DATAFLASH"));
708720
#elif COMPONENT_SD
709721
TEST_ASSERT_EQUAL(0, strcmp(bd_type, "SD"));
722+
#elif COMPONENT_SDIO
723+
TEST_ASSERT_EQUAL(0, strcmp(bd_type, "SDIO"));
710724
#elif COMPONET_FLASHIAP
711725
TEST_ASSERT_EQUAL(0, strcmp(bd_type, "FLASHIAP"));
712726
#endif
@@ -758,14 +772,17 @@ int get_bd_count()
758772
#if COMPONENT_SD
759773
bd_arr[count++] = sd; //3
760774
#endif
775+
#if COMPONENT_SDIO
776+
bd_arr[count++] = sdio; //4
777+
#endif
761778
#if COMPONENT_FLASHIAP
762-
bd_arr[count++] = flashiap; //4
779+
bd_arr[count++] = flashiap; //5
763780
#endif
764781

765782
return count;
766783
}
767784

768-
static const char *prefix[] = {"SPIF ", "QSPIF ", "DATAFLASH ", "SD ", "FLASHIAP ", "DEFAULT "};
785+
static const char *prefix[] = {"SPIF ", "QSPIF ", "DATAFLASH ", "SD ", "SDIO", "FLASHIAP ", "DEFAULT "};
769786

770787
int main()
771788
{

features/storage/TESTS/filesystem/general_filesystem/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#elif COMPONENT_SD
2727
#include "SDBlockDevice.h"
2828
#include "FATFileSystem.h"
29+
#elif COMPONENT_SDIO
30+
#include "SDBIOlockDevice.h"
31+
#include "FATFileSystem.h"
2932
#else
3033
#error [NOT_SUPPORTED] storage test not supported on this platform
3134
#endif

features/storage/TESTS/kvstore/direct_access_devicekey_test/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void test_direct_access_to_device_inject_root()
287287
#if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH
288288
internal_start_address = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS;
289289
internal_rbp_size = MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE;
290-
#elif COMPONENT_SD
290+
#elif COMPONENT_SD || COMPONENT_SDIO
291291
internal_start_address = MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS;
292292
internal_rbp_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE;
293293
#elif COMPONENT_FLASHIAP

features/storage/kvstore/conf/kv_config.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#include "SDBlockDevice.h"
5252
#endif
5353

54+
#if COMPONENT_SDIO
55+
#include "SDIOBlockDevice.h"
56+
#endif
57+
5458
/**
5559
* @brief This function initializes internal memory secure storage
5660
* This includes a TDBStore instance with a FlashIAPBlockdevice
@@ -250,7 +254,7 @@ FileSystem *_get_filesystem_default(const char *mount)
250254
{
251255
#if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH
252256
return _get_filesystem_LITTLE(mount);
253-
#elif COMPONENT_SD
257+
#elif COMPONENT_SD || COMPONENT_SDIO
254258
return _get_filesystem_FAT(mount);
255259
#else
256260
BlockDevice *bd = get_other_blockdevice();
@@ -618,6 +622,59 @@ BlockDevice *_get_blockdevice_SD(bd_addr_t start_address, bd_size_t size)
618622
#endif
619623
}
620624

625+
BlockDevice *_get_blockdevice_SDIO(bd_addr_t start_address, bd_size_t size)
626+
{
627+
#if COMPONENT_SDIO
628+
629+
bd_addr_t aligned_end_address;
630+
bd_addr_t aligned_start_address;
631+
632+
static SDIOBlockDevice bd(MBED_CONF_SDIO_CD);
633+
634+
if (bd.init() != MBED_SUCCESS) {
635+
tr_error("KV Config: SDIOBlockDevice init fail");
636+
return NULL;
637+
}
638+
639+
if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL_NO_RBP") == 0 ||
640+
strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
641+
//In TDBStore profile, we have a constraint of 4GByte
642+
if (start_address == 0 && size == 0 && bd.size() < (uint32_t)(-1)) {
643+
return &bd;
644+
}
645+
646+
//If the size of external storage is bigger than 4G we need to slice it.
647+
size = size != 0 ? size : align_down(bd.size(), bd.get_erase_size(bd.size() - 1));
648+
649+
if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
650+
tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
651+
return NULL;
652+
}
653+
654+
if (aligned_end_address - aligned_start_address != (uint32_t)(aligned_end_address - aligned_start_address)) {
655+
aligned_end_address = aligned_start_address + (uint32_t)(-1);//Support up to 4G only
656+
}
657+
} else {
658+
//For all other KVStore profiles beside TDBStore we take the entire external memory space.
659+
if (start_address == 0 && size == 0) {
660+
return &bd;
661+
}
662+
663+
if (_get_addresses(&bd, start_address, size, &aligned_start_address, &aligned_end_address) != 0) {
664+
tr_error("KV Config: Fail to get addresses for SlicingBlockDevice.");
665+
return NULL;
666+
}
667+
}
668+
669+
aligned_end_address = align_down(aligned_end_address, bd.get_erase_size(aligned_end_address));
670+
static SlicingBlockDevice sbd(&bd, aligned_start_address, aligned_end_address);
671+
return &sbd;
672+
673+
#else
674+
return NULL;
675+
#endif
676+
}
677+
621678
BlockDevice *_get_blockdevice_default(bd_addr_t start_address, bd_size_t size)
622679
{
623680
#if COMPONENT_QSPIF
@@ -628,6 +685,8 @@ BlockDevice *_get_blockdevice_default(bd_addr_t start_address, bd_size_t size)
628685
return _get_blockdevice_DATAFLASH(start_address, size);
629686
#elif COMPONENT_SD
630687
return _get_blockdevice_SD(start_address, size);
688+
#elif COMPONENT_SDIO
689+
return _get_blockdevice_SDIO(start_address, size);
631690
#else
632691
tr_error("KV Config: No default component define in target.json for this target.");
633692
return NULL;
@@ -1119,7 +1178,7 @@ int _storage_config_default()
11191178
{
11201179
#if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH
11211180
return _storage_config_TDB_EXTERNAL();
1122-
#elif COMPONENT_SD
1181+
#elif COMPONENT_SD || COMPONENT_SDIO
11231182
return _storage_config_FILESYSTEM();
11241183
#elif COMPONENT_FLASHIAP
11251184
return _storage_config_TDB_INTERNAL();

features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int get_expected_internal_TDBStore_position(uint32_t *out_tdb_start_offset, uin
127127
#if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH
128128
*out_tdb_start_offset = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS;
129129
tdb_size = MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE;
130-
#elif COMPONENT_SD
130+
#elif COMPONENT_SD || COMPONENT_SDIO
131131
tdb_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE;
132132
#else
133133
return MBED_ERROR_UNSUPPORTED;

features/storage/system_storage/SystemStorage.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#include "SDBlockDevice.h"
4242
#endif
4343

44+
#if COMPONENT_SDIO
45+
#include "SDIOBlockDevice.h"
46+
#endif
47+
4448
#if COMPONENT_FLASHIAP
4549
#include "FlashIAPBlockDevice.h"
4650
#endif
@@ -145,6 +149,12 @@ MBED_WEAK BlockDevice *BlockDevice::get_default_instance()
145149

146150
return &default_bd;
147151

152+
#elif COMPONENT_SDIO
153+
154+
static SDIOBlockDevice default_bd(MBED_CONF_SDIO_CD);
155+
156+
return &default_bd;
157+
148158
#elif COMPONENT_FLASHIAP
149159

150160
#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()
193203

194204
return &flash;
195205

196-
#elif COMPONENT_SD
206+
#elif COMPONENT_SD || COMPONENT_SDIO
197207

198208
static FATFileSystem sdcard("sd", BlockDevice::get_default_instance());
199209
sdcard.set_as_default();

targets/targets.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@
20852085
"MBED_MPU_CUSTOM",
20862086
"NXP_LPADC"
20872087
],
2088-
"components_add": ["FLASHIAP"],
2088+
"components_add": ["FLASHIAP", "SDIO"],
20892089
"extra_labels_add": [
20902090
"M33_NS",
20912091
"PSA",
@@ -2107,7 +2107,8 @@
21072107
"SPI",
21082108
"SPISLAVE",
21092109
"FLASH",
2110-
"STDIO_MESSAGES"
2110+
"STDIO_MESSAGES",
2111+
"SDIO"
21112112
],
21122113
"post_binary_hook": {"function": "LPC55S69Code.binary_hook"},
21132114
"secure_image_filename": "tfm.bin",
@@ -3907,7 +3908,7 @@
39073908
"bootloader_supported": true
39083909
},
39093910
"DISCO_F469NI": {
3910-
"components_add": ["QSPIF"],
3911+
"components_add": ["QSPIF", "SDIO"],
39113912
"inherits": ["FAMILY_STM32"],
39123913
"supported_form_factors": ["ARDUINO"],
39133914
"core": "Cortex-M4F",
@@ -3934,7 +3935,9 @@
39343935
"FLASH",
39353936
"QSPI",
39363937
"MPU",
3937-
"USBDEVICE"
3938+
"USBDEVICE",
3939+
"SDIO",
3940+
"SDIO_ASYNC"
39383941
],
39393942
"release_versions": ["2", "5"],
39403943
"device_name": "STM32F469NI",
@@ -4079,7 +4082,7 @@
40794082
"STM32F746NG",
40804083
"STM_EMAC"
40814084
],
4082-
"components_add": ["QSPIF", "FLASHIAP"],
4085+
"components_add": ["QSPIF", "FLASHIAP", "SDIO"],
40834086
"supported_form_factors": ["ARDUINO"],
40844087
"config": {
40854088
"clock_source": {
@@ -4113,7 +4116,9 @@
41134116
"FLASH",
41144117
"QSPI",
41154118
"USBDEVICE",
4116-
"MPU"
4119+
"MPU",
4120+
"SDIO",
4121+
"SDIO_ASYNC"
41174122
],
41184123
"release_versions": ["2", "5"],
41194124
"device_name": "STM32F746NG",

0 commit comments

Comments
 (0)