Skip to content

Commit 18f6476

Browse files
fix(spi): Fix bus clock for ESP32-P4 + remove S2 leftover (#11547)
* fix(spi): Fix bus clock for ESP32-P4 * fix(ci): Ignore unused-variable warning * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 12e881b commit 18f6476

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

cores/esp32/esp32-hal-spi.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#elif CONFIG_IDF_TARGET_ESP32P4
6161
#include "esp32p4/rom/ets_sys.h"
6262
#include "esp32p4/rom/gpio.h"
63+
#include "hal/spi_ll.h"
6364
#else
6465
#error Target CONFIG_IDF_TARGET is not supported
6566
#endif
@@ -639,9 +640,6 @@ spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t
639640
} else if (spi_num == HSPI) {
640641
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN);
641642
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST);
642-
} else {
643-
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN);
644-
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST);
645643
}
646644
#elif CONFIG_IDF_TARGET_ESP32S3
647645
if (spi_num == FSPI) {
@@ -662,6 +660,31 @@ spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t
662660
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN);
663661
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST);
664662
}
663+
#elif CONFIG_IDF_TARGET_ESP32P4
664+
#pragma GCC diagnostic push
665+
#pragma GCC diagnostic ignored "-Wunused-variable"
666+
if (spi_num == FSPI) {
667+
PERIPH_RCC_ACQUIRE_ATOMIC(PERIPH_GPSPI2_MODULE, ref_count) {
668+
if (ref_count == 0) {
669+
PERIPH_RCC_ATOMIC() {
670+
spi_ll_enable_bus_clock(SPI2_HOST, true);
671+
spi_ll_reset_register(SPI2_HOST);
672+
spi_ll_enable_clock(SPI2_HOST, true);
673+
}
674+
}
675+
}
676+
} else if (spi_num == HSPI) {
677+
PERIPH_RCC_ACQUIRE_ATOMIC(PERIPH_GPSPI3_MODULE, ref_count) {
678+
if (ref_count == 0) {
679+
PERIPH_RCC_ATOMIC() {
680+
spi_ll_enable_bus_clock(SPI3_HOST, true);
681+
spi_ll_reset_register(SPI3_HOST);
682+
spi_ll_enable_clock(SPI3_HOST, true);
683+
}
684+
}
685+
}
686+
}
687+
#pragma GCC diagnostic pop
665688
#elif defined(__PERIPH_CTRL_ALLOW_LEGACY_API)
666689
periph_ll_reset(PERIPH_SPI2_MODULE);
667690
periph_ll_enable_clk_clear_rst(PERIPH_SPI2_MODULE);

0 commit comments

Comments
 (0)