Skip to content

Commit 713f40d

Browse files
AZKKXLdpgeorge
authored andcommitted
esp32: Add support for ESP32-C5 SoCs.
Signed-off-by: yuan_mo <[email protected]> Signed-off-by: Damien George <[email protected]>
1 parent 2a3b9b0 commit 713f40d

File tree

6 files changed

+72
-2
lines changed

6 files changed

+72
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
dependencies:
2+
espressif/mdns:
3+
component_hash: 46ee81d32fbf850462d8af1e83303389602f6a6a9eddd2a55104cb4c063858ed
4+
dependencies:
5+
- name: idf
6+
require: private
7+
version: '>=5.0'
8+
source:
9+
registry_url: https://components.espressif.com/
10+
type: service
11+
version: 1.1.0
12+
idf:
13+
source:
14+
type: idf
15+
version: 5.5.1
16+
direct_dependencies:
17+
- espressif/mdns
18+
- idf
19+
manifest_hash: 3b18b5bbac91c9fe5098d3759a37c84ed0828546d8cbc92e26e4c1698e689c8a
20+
target: esp32c5
21+
version: 2.0.0

ports/esp32/machine_adc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ static const machine_adc_obj_t madc_obj[] = {
100100
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_3, GPIO_NUM_3},
101101
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_4, GPIO_NUM_4},
102102
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_0, GPIO_NUM_5},
103+
#elif CONFIG_IDF_TARGET_ESP32C5
104+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_1},
105+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_2},
106+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_2, GPIO_NUM_3},
107+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_3, GPIO_NUM_4},
108+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_4, GPIO_NUM_5},
109+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_5, GPIO_NUM_6},
103110
#elif CONFIG_IDF_TARGET_ESP32C6
104111
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_0},
105112
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_1},

ports/esp32/machine_i2c.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "driver/i2c_master.h"
3636
#else
3737
#include "driver/i2c.h"
38+
#include "esp_clk_tree.h"
3839
#include "hal/i2c_ll.h"
3940
#endif
4041

@@ -224,6 +225,8 @@ int machine_hw_i2c_transfer(mp_obj_base_t *self_in, uint16_t addr, size_t n, mp_
224225
#if SOC_I2C_SUPPORT_XTAL
225226
#if CONFIG_XTAL_FREQ > 0
226227
#define I2C_SCLK_FREQ (CONFIG_XTAL_FREQ * 1000000)
228+
#elif CONFIG_XTAL_FREQ == 0 && CONFIG_IDF_TARGET_ESP32C5
229+
// The crystal is auto-detected, so the I2C sclk frequency will be computed at runtime.
227230
#else
228231
#error "I2C uses XTAL but no configured freq"
229232
#endif // CONFIG_XTAL_FREQ
@@ -257,7 +260,13 @@ static void machine_hw_i2c_init(machine_hw_i2c_obj_t *self, bool first_init) {
257260
.master.clk_speed = self->freq,
258261
};
259262
i2c_param_config(self->port, &conf);
260-
int timeout = i2c_ll_calculate_timeout_us_to_reg_val(I2C_SCLK_FREQ, self->timeout_us);
263+
#if CONFIG_IDF_TARGET_ESP32C5
264+
uint32_t i2c_sclk_freq;
265+
check_esp_err(esp_clk_tree_src_get_freq_hz(I2C_CLK_SRC_DEFAULT, ESP_CLK_TREE_SRC_FREQ_PRECISION_APPROX, &i2c_sclk_freq));
266+
#else
267+
uint32_t i2c_sclk_freq = I2C_SCLK_FREQ;
268+
#endif
269+
int timeout = i2c_ll_calculate_timeout_us_to_reg_val(i2c_sclk_freq, self->timeout_us);
261270
i2c_set_timeout(self->port, (timeout > I2C_LL_MAX_TIMEOUT) ? I2C_LL_MAX_TIMEOUT : timeout);
262271
i2c_driver_install(self->port, I2C_MODE_MASTER, 0, 0, 0);
263272
}

ports/esp32/machine_pin.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
152152
// reset the pin to digital if this is a mode-setting init (grab it back from ADC)
153153
if (args[ARG_mode].u_obj != mp_const_none) {
154154
if (rtc_gpio_is_valid_gpio(index)) {
155-
#if !(CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6)
155+
#if !(CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C6)
156156
rtc_gpio_deinit(index);
157157
#endif
158158
}
@@ -163,6 +163,11 @@ static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
163163
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);
164164
}
165165
#endif
166+
#if CONFIG_IDF_TARGET_ESP32C5 && !MICROPY_HW_ESP_USB_SERIAL_JTAG
167+
if (index == 13 || index == 14) {
168+
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);
169+
}
170+
#endif
166171
#if CONFIG_IDF_TARGET_ESP32C6 && !MICROPY_HW_ESP_USB_SERIAL_JTAG
167172
if (index == 12 || index == 13) {
168173
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);

ports/esp32/machine_pin.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@
111111
#define MICROPY_HW_ENABLE_GPIO20 (1)
112112
#define MICROPY_HW_ENABLE_GPIO21 (1)
113113

114+
#elif CONFIG_IDF_TARGET_ESP32C5
115+
116+
#define MICROPY_HW_ENABLE_GPIO0 (1)
117+
#define MICROPY_HW_ENABLE_GPIO1 (1)
118+
#define MICROPY_HW_ENABLE_GPIO2 (1)
119+
#define MICROPY_HW_ENABLE_GPIO3 (1)
120+
#define MICROPY_HW_ENABLE_GPIO4 (1)
121+
#define MICROPY_HW_ENABLE_GPIO5 (1)
122+
#define MICROPY_HW_ENABLE_GPIO6 (1)
123+
#define MICROPY_HW_ENABLE_GPIO7 (1)
124+
#define MICROPY_HW_ENABLE_GPIO8 (1)
125+
#define MICROPY_HW_ENABLE_GPIO9 (1)
126+
#define MICROPY_HW_ENABLE_GPIO10 (1)
127+
#define MICROPY_HW_ENABLE_GPIO11 (1)
128+
#define MICROPY_HW_ENABLE_GPIO12 (1)
129+
#if !MICROPY_HW_ESP_USB_SERIAL_JTAG
130+
#define MICROPY_HW_ENABLE_GPIO13 (1)
131+
#define MICROPY_HW_ENABLE_GPIO14 (1)
132+
#endif
133+
#define MICROPY_HW_ENABLE_GPIO23 (1)
134+
#define MICROPY_HW_ENABLE_GPIO24 (1)
135+
#define MICROPY_HW_ENABLE_GPIO25 (1)
136+
#define MICROPY_HW_ENABLE_GPIO26 (1)
137+
#define MICROPY_HW_ENABLE_GPIO27 (1)
138+
#define MICROPY_HW_ENABLE_GPIO28 (1)
139+
114140
#elif CONFIG_IDF_TARGET_ESP32C6
115141

116142
#define MICROPY_HW_ENABLE_GPIO0 (1)

ports/esp32/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@
172172
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c2"
173173
#elif CONFIG_IDF_TARGET_ESP32C3
174174
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c3"
175+
#elif CONFIG_IDF_TARGET_ESP32C5
176+
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c5"
175177
#elif CONFIG_IDF_TARGET_ESP32C6
176178
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c6"
177179
#endif

0 commit comments

Comments
 (0)