Skip to content

Commit 3e8bbee

Browse files
danieldegrassedleach02
authored andcommitted
sd: Add common SD initialization code
All SD cards require SD CMD0 (reset) and CMD8 (send IF cond) at boot. Add this portion of the initialization flow to SD subsystem, as well as query command to check if card is SDIO. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent d90a16f commit 3e8bbee

File tree

8 files changed

+527
-0
lines changed

8 files changed

+527
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ scripts/gen_image_info.py @tejlmand
770770
/subsys/shell/backends/shell_mqtt.c @ycsin
771771
/subsys/stats/ @nvlsianpu
772772
/subsys/storage/ @nvlsianpu
773+
/subsys/sd/ @danieldegrasse
773774
/subsys/task_wdt/ @martinjaeger
774775
/subsys/testsuite/ @nashif
775776
/subsys/testsuite/ztest/*/ztress* @nordic-krch

subsys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ add_subdirectory(canbus)
3030
add_subdirectory_ifdef(CONFIG_TIMING_FUNCTIONS timing)
3131
add_subdirectory_ifdef(CONFIG_DEMAND_PAGING demand_paging)
3232
add_subdirectory(modbus)
33+
add_subdirectory(sd)

subsys/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ source "subsys/stats/Kconfig"
4848

4949
source "subsys/usb/device/Kconfig"
5050

51+
source "subsys/sd/Kconfig"
52+
5153
source "subsys/dfu/Kconfig"
5254

5355
source "subsys/random/Kconfig"

subsys/sd/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
if (CONFIG_SD_STACK)
4+
zephyr_interface_library_named(SD)
5+
6+
zephyr_library()
7+
zephyr_library_sources (sd.c)
8+
endif()

subsys/sd/Kconfig

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) 2022 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# SD stack configuration options
5+
6+
menuconfig SD_STACK
7+
bool "SD Card Support"
8+
select SDHC
9+
help
10+
Enable SD card support
11+
12+
if SD_STACK
13+
14+
module = SD
15+
module-str = SD stack
16+
source "subsys/logging/Kconfig.template.log_config"
17+
18+
config SD_INIT_TIMEOUT
19+
int "Timeout while initializing SD card"
20+
default 1500
21+
help
22+
Maximum time to wait, in milliseconds, for the SD card to initialize.
23+
24+
config SD_RETRY_COUNT
25+
int "Number of times to retry initialization commands"
26+
default 10
27+
help
28+
Number of times to retry initialization commands in case of failure
29+
30+
config SD_OCR_RETRY_COUNT
31+
int "Number of times to retry SD OCR read"
32+
default 1000
33+
help
34+
Number of times to retry SD OCR read command. OCR reads typically
35+
require more retries than general SD commands
36+
37+
config SD_CMD_TIMEOUT
38+
int "Timeout for SD commands (in ms)"
39+
default 200
40+
help
41+
Default timeout in milliseconds for SD commands
42+
43+
config SD_DATA_TIMEOUT
44+
int "Timeout for SD data transfer (in ms)"
45+
default 10000
46+
help
47+
Default timeout in milliseconds for SD data transfer commands
48+
49+
config SD_BUFFER_SIZE
50+
int
51+
default 512
52+
help
53+
Size in bytes of internal buffer SD card uses for unaligned reads and
54+
internal data reads during initialization
55+
56+
config SD_DATA_RETRIES
57+
int "Number of times to retry sending data to card"
58+
default 3
59+
help
60+
Number of times to retry sending data to SD card in case of failure
61+
62+
63+
config SD_UHS_PROTOCOL
64+
bool "Ultra high speed SD card protocol support"
65+
default y if SDHC_SUPPORTS_UHS
66+
help
67+
Enable support for ultra high speed SD cards. This can be disabled to
68+
reduce code size, at the cost of data transfer speeds.
69+
70+
endif # SD_STACK

0 commit comments

Comments
 (0)