feat(sd): added power control driver and implementation layer with ldo

This commit is contained in:
Armando
2024-01-21 19:29:42 +08:00
parent 5154be52ac
commit ec44556a07
24 changed files with 414 additions and 46 deletions

View File

@@ -1,3 +1,3 @@
idf_component_register(SRCS sdmmc_test_board.c sdmmc_test_board_defs.c
INCLUDE_DIRS include
REQUIRES esp_driver_sdmmc esp_driver_sdspi esp_driver_gpio)
REQUIRES esp_driver_sdmmc esp_driver_sdspi esp_driver_gpio unity)

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

View File

@@ -1,12 +1,15 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdmmc_test_board.h"
#include "sdkconfig.h"
#include "unity.h"
#include "soc/soc_caps.h"
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
#include "sd_pwr_ctrl.h"
const sdmmc_test_board_slot_info_t* sdmmc_test_board_get_slot_info(int slot_index)
{
@@ -32,6 +35,18 @@ void sdmmc_test_board_get_config_sdmmc(int slot_index, sdmmc_host_t *out_host_co
out_host_config->max_freq_khz = slot->max_freq_khz;
}
#if SOC_SDMMC_IO_POWER_EXTERNAL
#define SDMMC_PWR_LDO_CHANNEL 4
sd_pwr_ctrl_ldo_config_t ldo_config = {
.ldo_unit_id = SDMMC_PWR_LDO_CHANNEL,
};
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
TEST_ESP_OK(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle));
out_host_config->pwr_ctrl_handle = pwr_ctrl_handle;
#endif
#if SOC_SDMMC_USE_GPIO_MATRIX
out_slot_config->clk = slot->clk;
out_slot_config->cmd = slot->cmd_mosi;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,6 +15,8 @@
#include "sdmmc_cmd.h"
#include "sdmmc_test_begin_end_sd.h"
#include "hal/gpio_hal.h"
#include "sd_pwr_ctrl.h"
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
void sdmmc_test_sd_skip_if_board_incompatible(int slot, int width, int freq_khz, int ddr)
{
@@ -25,14 +27,22 @@ void sdmmc_test_sd_skip_if_board_incompatible(int slot, int width, int freq_khz,
TEST_IGNORE_MESSAGE("Board doesn't have the required slot");
}
sdmmc_test_board_get_config_sdmmc(slot, &config, &slot_config);
int board_max_freq_khz = sdmmc_test_board_get_slot_info(slot)->max_freq_khz;
if (board_max_freq_khz > 0 && board_max_freq_khz < freq_khz) {
#if SOC_SDMMC_IO_POWER_EXTERNAL
TEST_ESP_OK(sd_pwr_ctrl_del_on_chip_ldo(config.pwr_ctrl_handle));
#endif
TEST_IGNORE_MESSAGE("Board doesn't support required max_freq_khz");
}
if (slot_config.width < width) {
#if SOC_SDMMC_IO_POWER_EXTERNAL
TEST_ESP_OK(sd_pwr_ctrl_del_on_chip_ldo(config.pwr_ctrl_handle));
#endif
TEST_IGNORE_MESSAGE("Board doesn't support required bus width");
}
}
void sdmmc_test_sd_begin(int slot, int width, int freq_khz, int ddr, sdmmc_card_t *out_card)
{
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
@@ -115,4 +125,7 @@ void sdmmc_test_sd_end(sdmmc_card_t *card)
//Need to reset GPIO first, otherrwise cannot discharge VDD of card completely.
sdmmc_test_board_card_power_set(false);
#if SOC_SDMMC_IO_POWER_EXTERNAL
TEST_ESP_OK(sd_pwr_ctrl_del_on_chip_ldo(card->host.pwr_ctrl_handle));
#endif
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,6 +9,8 @@
#include "driver/sdmmc_host.h"
#include "sdmmc_test_cd_wp_common.h"
#include "sdmmc_test_board.h"
#include "sd_pwr_ctrl.h"
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
//TODO: IDF-8734
#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3
@@ -27,6 +29,9 @@ TEST_CASE("CD input works in SD mode", "[sdmmc]")
TEST_ESP_OK(sdmmc_host_deinit());
sdmmc_test_board_card_power_set(false);
#if SOC_SDMMC_IO_POWER_EXTERNAL
TEST_ESP_OK(sd_pwr_ctrl_del_on_chip_ldo(config.pwr_ctrl_handle));
#endif
}
TEST_CASE("WP input works in SD mode", "[sdmmc]")
@@ -44,5 +49,8 @@ TEST_CASE("WP input works in SD mode", "[sdmmc]")
TEST_ESP_OK(sdmmc_host_deinit());
sdmmc_test_board_card_power_set(false);
#if SOC_SDMMC_IO_POWER_EXTERNAL
TEST_ESP_OK(sd_pwr_ctrl_del_on_chip_ldo(config.pwr_ctrl_handle));
#endif
}
#endif