Skip to content

Commit 1d1ba47

Browse files
committed
feat(sdio): add sdio_slave_reset_hw
1 parent 92883fb commit 1d1ba47

File tree

6 files changed

+68
-7
lines changed

6 files changed

+68
-7
lines changed

components/esp_driver_sdio/include/driver/sdio_slave.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -92,10 +92,20 @@ void sdio_slave_stop(void);
9292

9393
/** Clear the data still in the driver, as well as reset the PKT_LEN and TOKEN1 counting.
9494
*
95-
* @return always return ESP_OK.
95+
* @return
96+
* - ESP_ERR_INVALID_STATE if already started.
97+
* - ESP_OK otherwise.
9698
*/
9799
esp_err_t sdio_slave_reset(void);
98100

101+
/** Reset sdio hardware, and clear the data still in the driver, as well as reset the PKT_LEN and TOKEN1 counting.
102+
*
103+
* @return
104+
* - ESP_ERR_INVALID_STATE if already started.
105+
* - ESP_OK otherwise.
106+
*/
107+
esp_err_t sdio_slave_reset_hw(void);
108+
99109
/*---------------------------------------------------------------------------
100110
* Receive
101111
*--------------------------------------------------------------------------*/
@@ -220,7 +230,7 @@ esp_err_t sdio_slave_transmit(uint8_t* addr, size_t len);
220230
/*---------------------------------------------------------------------------
221231
* Host
222232
*--------------------------------------------------------------------------*/
223-
/** Read the spi slave register shared with host.
233+
/** Read the sdio slave register shared with host.
224234
*
225235
* @param pos register address, 0-27 or 32-63.
226236
*
@@ -230,7 +240,7 @@ esp_err_t sdio_slave_transmit(uint8_t* addr, size_t len);
230240
*/
231241
uint8_t sdio_slave_read_reg(int pos);
232242

233-
/** Write the spi slave register shared with host.
243+
/** Write the sdio slave register shared with host.
234244
*
235245
* @param pos register address, 0-11, 14-15, 18-19, 24-27 and 32-63, other address are reserved.
236246
* @param reg the value to write.

components/esp_driver_sdio/src/sdio_slave.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ esp_err_t sdio_slave_reset(void)
456456
return err;
457457
}
458458

459+
esp_err_t sdio_slave_reset_hw(void)
460+
{
461+
sdio_slave_hw_deinit();
462+
sdio_slave_hw_init(&context.config);
463+
return sdio_slave_reset();
464+
}
465+
459466
void sdio_slave_stop(void)
460467
{
461468
sdio_slave_hal_set_ioready(context.hal, false);

components/esp_driver_sdio/test_apps/sdio/sdio_common_tests/host_sdmmc/main/test_sdio_sdhost.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ TEST_CASE("SDIO_SDMMC: test register", "[sdio]")
203203
/*---------------------------------------------------------------
204204
SDMMC_SDIO: test reset
205205
---------------------------------------------------------------*/
206-
TEST_CASE("SDIO_SDMMC: test reset", "[sdio]")
206+
static void test_reset(void)
207207
{
208208
essl_handle_t handle = NULL;
209209
test_sdio_param_t test_param = {
@@ -243,6 +243,16 @@ TEST_CASE("SDIO_SDMMC: test reset", "[sdio]")
243243
s_master_deinit();
244244
}
245245

246+
TEST_CASE("SDIO_SDMMC: test reset", "[sdio]")
247+
{
248+
test_reset();
249+
}
250+
251+
TEST_CASE("SDIO_SDMMC: test reset hw", "[sdio]")
252+
{
253+
test_reset();
254+
}
255+
246256
/*---------------------------------------------------------------
247257
SDMMC_SDIO: test fixed addr
248258
---------------------------------------------------------------*/

components/esp_driver_sdio/test_apps/sdio/sdio_common_tests/sdio/main/test_sdio_slave.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,18 @@ TEST_CASE("SDIO_Slave: test register", "[sdio]")
105105
/*---------------------------------------------------------------
106106
SDMMC_SDIO: test reset
107107
---------------------------------------------------------------*/
108-
TEST_CASE("SDIO_Slave: test reset", "[sdio]")
108+
static void test_reset(bool reset_hw)
109109
{
110110
s_slave_init(SDIO_SLAVE_SEND_PACKET);
111111
TEST_ESP_OK(sdio_slave_start());
112112
ESP_LOGI(TAG, "slave ready");
113113

114114
sdio_slave_stop();
115-
TEST_ESP_OK(sdio_slave_reset());
115+
if (!reset_hw) {
116+
TEST_ESP_OK(sdio_slave_reset());
117+
} else {
118+
TEST_ESP_OK(sdio_slave_reset_hw());
119+
}
116120
TEST_ESP_OK(sdio_slave_start());
117121

118122
//tx
@@ -155,6 +159,16 @@ TEST_CASE("SDIO_Slave: test reset", "[sdio]")
155159
sdio_slave_deinit();
156160
}
157161

162+
TEST_CASE("SDIO_Slave: test reset", "[sdio]")
163+
{
164+
test_reset(false);
165+
}
166+
167+
TEST_CASE("SDIO_Slave: test reset hw", "[sdio]")
168+
{
169+
test_reset(true);
170+
}
171+
158172
/*---------------------------------------------------------------
159173
SDMMC_SDIO: test fixed addr
160174
---------------------------------------------------------------*/

docs/en/api-reference/peripherals/sdio_slave.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ There are several ways to use the ``arg`` in the queue parameter:
276276

277277
For more about this, see :example:`peripherals/sdio`.
278278

279+
Reset SDIO
280+
^^^^^^^^^^^^
281+
282+
Calling ``sdio_slave_reset`` can reset PKT_LEN (Packet length accumulator value) and TOKEN1 (Receiving buffers accumulated number) at the SDIO slave driver software level to resynchronize the transmit and receive counts with the host.
283+
284+
If there is a usage scenario where the ESP chip remains powered on but the HOST is powered off. During the power-off period of the HOST, some unknown signals may be generated on the SDIO signal line, causing the SDIO hardware state machine to be abnormal. The HOST restarts and executes the card identification process, and the ESP will not respond normally. In this case, consider calling ``sdio_slave_reset_hw`` to reset the SDIO hardware.
285+
286+
.. note::
287+
288+
Reset the SDIO hardware. The interrupt enable status and shared register values ​​will be lost. You may need to call ``sdio_slave_set_host_intena`` and ``sdio_slave_write_reg`` to set them.
279289

280290
Application Example
281291
-------------------

docs/zh_CN/api-reference/peripherals/sdio_slave.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ SDIO 从机驱动程序的相关术语如下:
276276

277277
更多详情,请参阅 :example:`peripherals/sdio`。
278278

279+
重置 SDIO
280+
^^^^^^^^^^^^
281+
282+
调用 ``sdio_slave_reset`` 可以重置 SDIO 从机驱动程序软件层面的 PKT_LEN (从机发送包长度累加值) 和 TOKEN1 (接收 buffer 累计数量), 便于与主机重新同步收发计数。
283+
284+
如果存在 ESP 芯片保持上电状态,但 HOST 端会下电的使用场景。HOST 端下电期间, SDIO 信号线上可能会产生一些未知的信号导致 SDIO 硬件状态机异常。HOST 重新启动, 执行卡识别流程, ESP 将不会正常响应。这种情况下,考虑调用 ``sdio_slave_reset_hw``, 重置 SDIO 硬件。
285+
286+
.. note::
287+
288+
重置 SDIO 硬件,中断使能状态和共享寄存器的值会丢失,可能需要调用 ``sdio_slave_set_host_intena``、 ``sdio_slave_write_reg`` 设置。
279289

280290
应用示例
281291
--------

0 commit comments

Comments
 (0)