Skip to content

Commit cc7adfa

Browse files
committed
fix(spi_master): fix spi halt when remove device who using rc_fast
1 parent 409af75 commit cc7adfa

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

components/esp_driver_spi/src/gpspi/spi_master.c

+9
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,15 @@ esp_err_t spi_bus_remove_device(spi_device_handle_t handle)
584584

585585
#if SOC_SPI_SUPPORT_CLK_RC_FAST
586586
if (handle->cfg.clock_source == SPI_CLK_SRC_RC_FAST) {
587+
// If no transactions from other device, acquire the bus to switch module clock to `SPI_CLK_SRC_DEFAULT`
588+
// because `SPI_CLK_SRC_RC_FAST` will be disabled then, which block following transactions
589+
if (handle->host->cur_cs == DEV_NUM_MAX) {
590+
spi_device_acquire_bus(handle, portMAX_DELAY);
591+
SPI_MASTER_PERI_CLOCK_ATOMIC() {
592+
spi_ll_set_clk_source(handle->host->hal.hw, SPI_CLK_SRC_DEFAULT);
593+
}
594+
spi_device_release_bus(handle);
595+
}
587596
periph_rtc_dig_clk8m_disable();
588597
}
589598
#endif

components/soc/esp32c5/include/soc/clk_tree_defs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ typedef enum { // TODO: [ESP32C5] IDF-8695 (inherit from C6)
357357
/**
358358
* @brief Array initializer for all supported clock sources of SPI
359359
*/
360-
#define SOC_SPI_CLKS {SOC_MOD_CLK_PLL_F160M, SOC_MOD_CLK_XTAL, SOC_MOD_CLK_RC_FAST}
360+
#define SOC_SPI_CLKS {SOC_MOD_CLK_PLL_F160M, SOC_MOD_CLK_RC_FAST, SOC_MOD_CLK_XTAL}
361361

362362
/**
363363
* @brief Type of SPI clock source.

components/soc/esp32c6/include/soc/clk_tree_defs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ typedef enum {
357357
/**
358358
* @brief Array initializer for all supported clock sources of SPI
359359
*/
360-
#define SOC_SPI_CLKS {SOC_MOD_CLK_PLL_F80M, SOC_MOD_CLK_XTAL, SOC_MOD_CLK_RC_FAST}
360+
#define SOC_SPI_CLKS {SOC_MOD_CLK_PLL_F80M, SOC_MOD_CLK_RC_FAST, SOC_MOD_CLK_XTAL}
361361

362362
/**
363363
* @brief Type of SPI clock source.

components/soc/esp32c61/include/soc/clk_tree_defs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ typedef enum {
249249
/**
250250
* @brief Array initializer for all supported clock sources of SPI
251251
*/
252-
#define SOC_SPI_CLKS {SOC_MOD_CLK_PLL_F160M, SOC_MOD_CLK_XTAL, SOC_MOD_CLK_RC_FAST}
252+
#define SOC_SPI_CLKS {SOC_MOD_CLK_PLL_F160M, SOC_MOD_CLK_RC_FAST, SOC_MOD_CLK_XTAL}
253253

254254
/**
255255
* @brief Type of SPI clock source.

components/soc/esp32h2/include/soc/clk_tree_defs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ typedef enum {
335335
/**
336336
* @brief Array initializer for all supported clock sources of SPI
337337
*/
338-
#define SOC_SPI_CLKS {SOC_MOD_CLK_XTAL, SOC_MOD_CLK_PLL_F48M, SOC_MOD_CLK_RC_FAST}
338+
#define SOC_SPI_CLKS {SOC_MOD_CLK_XTAL, SOC_MOD_CLK_RC_FAST, SOC_MOD_CLK_PLL_F48M}
339339

340340
/**
341341
* @brief Type of SPI clock source.

0 commit comments

Comments
 (0)