tests: add test for SDIO subsystem

Add test to verify SDIO subsystem. Note that due to the nature of SDIO
cards, this test only reads from common registers and does not verify
extended reads or writes.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2022-08-15 16:20:37 -05:00 committed by Anas Nashif
commit 6a31ed50b8
5 changed files with 158 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(sdmmc_subsys_test)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View file

@ -0,0 +1,18 @@
SDIO Subsystem Test
##################
This test is designed to verify the SD subsystem stack implementation for SDIO
devices. Note that this test will only perform basic reads from the SDIO card
after initialization, as most registers present on the card will be vendor
specific. It requires an SDIO card be connected to the board to pass.
The test has the following phases:
* Init test: verify the SD host controller can detect card presence, and
test the initialization flow of the SDIO subsystem to verify that the stack
can correctly initialize an SDIO card.
* Read test: verify that a read from the SDIO common card register area returns
valid data.
* Configuration test: verify that the SD stack reports a valid configuration
for this card after initialization.

View file

@ -0,0 +1,5 @@
CONFIG_TEST=y
CONFIG_ZTEST=y
CONFIG_SDHC=y
CONFIG_SDIO_STACK=y
CONFIG_LOG=y

View file

@ -0,0 +1,114 @@
/*
* Copyright 2022 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/sd/sdio.h>
#include <zephyr/device.h>
#include <zephyr/drivers/disk.h>
#include <zephyr/ztest.h>
static const struct device *sdhc_dev = DEVICE_DT_GET(DT_ALIAS(sdhc0));
static struct sd_card card;
/*
* Verify that SD stack can initialize an SDIO card.
* This test must run first, to ensure the card is initialized.
*/
ZTEST(sd_stack, test_0_init)
{
int ret;
zassert_true(device_is_ready(sdhc_dev), "SDHC device is not ready");
ret = sd_is_card_present(sdhc_dev);
zassert_equal(ret, 1, "SD card not present in slot");
ret = sd_init(sdhc_dev, &card);
zassert_equal(ret, 0, "Card initialization failed");
}
/*
* Verify that a register read works. Given the custom nature of SDIO devices,
* we just read from the card common I/O area.
*/
ZTEST(sd_stack, test_read)
{
int ret;
uint8_t reg = 0xFF;
/* Read from card common I/O area. */
ret = sdio_read_byte(&card.func0, SDIO_CCCR_CCCR, &reg);
zassert_equal(ret, 0, "SD card read failed");
/* Check to make sure CCCR read actually returned valid data */
zassert_not_equal(reg, 0xFF, "CCCR read returned invalid data");
}
/* Simply dump the card configuration. */
ZTEST(sd_stack, test_card_config)
{
switch (card.card_voltage) {
case SD_VOL_1_2_V:
TC_PRINT("Card voltage: 1.2V\n");
break;
case SD_VOL_1_8_V:
TC_PRINT("Card voltage: 1.8V\n");
break;
case SD_VOL_3_0_V:
TC_PRINT("Card voltage: 3.0V\n");
break;
case SD_VOL_3_3_V:
TC_PRINT("Card voltage: 3.3V\n");
break;
default:
zassert_unreachable("Card voltage is not known value");
}
zassert_equal(card.status, CARD_INITIALIZED, "Card status is not OK");
switch (card.card_speed) {
case SD_TIMING_SDR12:
TC_PRINT("Card timing: SDR12\n");
break;
case SD_TIMING_SDR25:
TC_PRINT("Card timing: SDR25\n");
break;
case SD_TIMING_SDR50:
TC_PRINT("Card timing: SDR50\n");
break;
case SD_TIMING_SDR104:
TC_PRINT("Card timing: SDR104\n");
break;
case SD_TIMING_DDR50:
TC_PRINT("Card timing: DDR50\n");
break;
default:
zassert_unreachable("Card timing is not known value");
}
switch (card.type) {
case CARD_SDIO:
TC_PRINT("Card type: SDIO\n");
break;
case CARD_SDMMC:
TC_PRINT("Card type: SDMMC\n");
break;
case CARD_COMBO:
TC_PRINT("Card type: combo card\n");
break;
default:
zassert_unreachable("Card type is not known value");
}
if (card.sd_version >= SD_SPEC_VER3_0) {
TC_PRINT("Card spec: 3.0\n");
} else if (card.sd_version >= SD_SPEC_VER2_0) {
TC_PRINT("Card spec: 2.0\n");
} else if (card.sd_version >= SD_SPEC_VER1_1) {
TC_PRINT("Card spec: 1.1\n");
} else if (card.sd_version >= SD_SPEC_VER1_0) {
TC_PRINT("Card spec: 1.0\n");
} else {
zassert_unreachable("Card spec is unknown value");
}
}
ZTEST_SUITE(sd_stack, NULL, NULL, NULL, NULL, NULL);

View file

@ -0,0 +1,13 @@
common:
depends_on: sdhc
tags: drivers sdhc
tests:
sd.sdio:
harness: ztest
harness_config:
fixture: fixture_sdhc
filter: dt_alias_exists("sdhc0")
tags: sdhc
min_ram: 32
integration_platforms:
- mimxrt1064_evk