Skip to content

Commit 0a0fed7

Browse files
Felipe Nevesnashif
authored andcommitted
drivers: spi: esp32: add esp32c3 support
to the esp32 spi unified driver Signed-off-by: Felipe Neves <[email protected]>
1 parent c03519f commit 0a0fed7

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

boards/riscv/esp32c3_devkitm/esp32c3_devkitm.dts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
status = "okay";
4242
};
4343

44+
&spi2 {
45+
#address-cells = <1>;
46+
#size-cells = <0>;
47+
status = "okay";
48+
miso-pin = <2>;
49+
mosi-pin = <7>;
50+
sclk-pin = <6>;
51+
csel-pin = <10>;
52+
};
53+
4454
&gpio0 {
4555
status = "okay";
4656
};

drivers/spi/Kconfig.esp32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
menuconfig ESP32_SPIM
77
bool "ESP32 SPI Master driver"
8-
depends on SOC_ESP32 || SOC_ESP32S2
8+
depends on SOC_ESP32 || SOC_ESP32S2 || SOC_ESP32C3
99
default y
1010
help
1111
Enables support for ESP32 SPI Master driver.

drivers/spi/spi_esp32_spim.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ LOG_MODULE_REGISTER(esp32_spi, CONFIG_SPI_LOG_LEVEL);
1515

1616
#include <soc.h>
1717
#include <drivers/spi.h>
18+
#ifndef CONFIG_SOC_ESP32C3
1819
#include <drivers/interrupt_controller/intc_esp32.h>
20+
#else
21+
#include <drivers/interrupt_controller/intc_esp32c3.h>
22+
#endif
1923
#include <drivers/gpio/gpio_esp32.h>
2024
#include <drivers/clock_control.h>
2125
#include "spi_context.h"
@@ -40,6 +44,17 @@ LOG_MODULE_REGISTER(esp32_spi, CONFIG_SPI_LOG_LEVEL);
4044
#define SCLK_IDX_3 SPI3_CLK_OUT_MUX_IDX
4145
#define CSEL_IDX_2 FSPICS0_OUT_IDX
4246
#define CSEL_IDX_3 SPI3_CS0_OUT_IDX
47+
#elif defined(CONFIG_SOC_ESP32C3)
48+
#define MISO_IDX_2 FSPIQ_IN_IDX
49+
#define MOSI_IDX_2 FSPID_OUT_IDX
50+
#define SCLK_IDX_2 FSPICLK_OUT_IDX
51+
#define CSEL_IDX_2 FSPICS0_OUT_IDX
52+
#endif
53+
54+
#ifdef CONFIG_SOC_ESP32C3
55+
#define ISR_HANDLER isr_handler_t
56+
#else
57+
#define ISR_HANDLER intr_handler_t
4358
#endif
4459

4560
static bool spi_esp32_transfer_ongoing(struct spi_esp32_data *data)
@@ -124,7 +139,11 @@ static int spi_esp32_init(const struct device *dev)
124139
}
125140

126141
#ifdef CONFIG_SPI_ESP32_INTERRUPT
127-
data->irq_line = esp_intr_alloc(cfg->irq_source, 0, spi_esp32_isr, (void *)dev, NULL);
142+
data->irq_line = esp_intr_alloc(cfg->irq_source,
143+
0,
144+
(ISR_HANDLER)spi_esp32_isr,
145+
(void *)dev,
146+
NULL);
128147
#endif
129148

130149
spi_context_unlock_unconditionally(&data->ctx);

dts/riscv/espressif/esp32c3.dtsi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@
129129
label = "TRNG_0";
130130
status = "disabled";
131131
};
132+
133+
spi2: spi@60024000 {
134+
compatible = "espressif,esp32-spi";
135+
reg = <0x60024000 DT_SIZE_K(4)>;
136+
interrupts = <SPI2_INTR_SOURCE>;
137+
interrupt-parent = <&intc>;
138+
label = "SPI_2";
139+
clocks = <&rtc ESP32_SPI2_MODULE>;
140+
status = "disabled";
141+
use-iomux;
142+
};
132143
};
133144

134145
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_SPI_LOOPBACK_DRV_NAME="SPI_2"
2+
CONFIG_SPI_ESP32_INTERRUPT=y

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ manifest:
6767
groups:
6868
- hal
6969
- name: hal_espressif
70-
revision: 7c46a3fc5b336199392cba0f66c3c27d5fe9025c
70+
revision: 8284e0c251a6450f9cdeff299988a647648296e3
7171
path: modules/hal/espressif
7272
west-commands: west/west-commands.yml
7373
groups:

0 commit comments

Comments
 (0)