8000 esp32/esp32c2: Adapt to target chip ESP32C2. · micropython/micropython@af01368 · GitHub
[go: up one dir, main page]

Skip to content

Commit af01368

Browse files
committed
esp32/esp32c2: Adapt to target chip ESP32C2.
esp32/esp32c2: Fix heap size is too small to enable Bluetooth. Signed-off-by: TianShuangKe <qinyun575@gmail.com>
1 parent e323da7 commit af01368

18 files changed

+126
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"deploy": [
3+
"../deploy_c2.md"
4+
],
5+
"docs": "",
6+
"features": [
7+
"BLE",
8+
"External Flash",
9+
"WiFi"
10+
],
11+
"images": [
12+
"esp32c2_devkitmini.jpg"
13+
],
14+
"mcu": "esp32c2",
15+
"product": "ESP32-C2",
16+
"thumbnail": "",
17+
"url": "https://www.espressif.com/en/products/modules",
18+
"vendor": "Espressif"
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The following files are firmware images that should work on most
2+
ESP32-C2-based boards with 4MiB of flash, including WROOM and MINI modules,
3+
that use the revision 1 silicon (or newer).
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(IDF_TARGET esp32c2)
2+
3+
set(SDKCONFIG_DEFAULTS
4+
boards/sdkconfig.base
5+
${SDKCONFIG_IDF_VERSION_SPECIFIC}
6+
boards/sdkconfig.ble
7+
boards/sdkconfig.c2
8+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This configuration is for a generic ESP32C2 board with 4MiB (or more) of flash.
2+
3+
#define MICROPY_HW_BOARD_NAME "ESP32C2 module"
4+
#define MICROPY_HW_MCU_NAME "ESP32C2"
5+
6+
#define MICROPY_HW_ENABLE_SDCARD (0)
7+
#define MICROPY_PY_MACHINE_I2S (0)
8 6D40 +
9+
// Network config
10+
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "esp32c2"
11+
12+
// Enable UART REPL for modules that have an external USB-UART and don't use native USB.
13+
#define MICROPY_HW_ENABLE_UART_REPL (1)

ports/esp32/boards/deploy_c2.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Program your board using the esptool.py program, found [here](https://github.com/espressif/esptool).
2+
3+
If you are putting MicroPython on your board for the first time then you should
4+
first erase the entire flash using:
5+
6+
```bash
7+
esptool.py --chip esp32c2 --port /dev/ttyUSB0 erase_flash
8+
```
9+
10+
From then on program the firmware starting at address 0x0:
11+
12+
```bash
13+
esptool.py --chip esp32c2 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x0 esp32c2-20240627-v1.23.bin
14+
```

ports/esp32/boards/sdkconfig.c2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Main XTAL Config
3+
#
4+
CONFIG_XTAL_FREQ_26=y
5+
# CONFIG_XTAL_FREQ_40 is not set
6+
CONFIG_XTAL_FREQ=26
7+
CONFIG_BT_NIMBLE_TASK_STACK_SIZE=4096

ports/esp32/esp32_rmt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@
4747
// This current MicroPython implementation lacks some major features, notably receive pulses
4848
// and carrier output.
4949

50+
#if SOC_RMT_SUPPORTED
5051
// Last available RMT channel that can transmit.
5152
#define RMT_LAST_TX_CHANNEL (SOC_RMT_TX_CANDIDATES_PER_GROUP - 1)
52-
53+
#else
54+
#define RMT_LAST_TX_CHANNEL (-1)
55+
#endif
5356
// Forward declaration
5457
extern const mp_obj_type_t esp32_rmt_type;
5558

ports/esp32/machine_adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static const machine_adc_obj_t madc_obj[] = {
8787
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_7, GPIO_NUM_27},
8888
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_8, GPIO_NUM_25},
8989
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_9, GPIO_NUM_26},
90-
#elif CONFIG_IDF_TARGET_ESP32C3
90+
#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32C2
9191
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_0},
9292
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_1},
9393
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_2, GPIO_NUM_2},

ports/esp32/machine_bitstream.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ static void IRAM_ATTR machine_bitstream_high_low_bitbang(mp_hal_pin_obj_t pin, u
9090
mp_hal_quiet_timing_exit(irq_state);
9191
}
9292

93+
#if SOC_RMT_SUPPORTED
9394
/******************************************************************************/
9495
// RMT implementation
9596

@@ -172,16 +173,20 @@ static void machine_bitstream_high_low_rmt(mp_hal_pin_obj_t pin, uint32_t *timin
172173
// Cancel RMT output to GPIO pin.
173174
esp_rom_gpio_connect_out_signal(pin, SIG_GPIO_OUT_IDX, false, false);
174175
}
175-
176+
#endif
176177
/******************************************************************************/
177178
// Interface to machine.bitstream
178179

179180
void machine_bitstream_high_low(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len) {
181+
#if SOC_RMT_SUPPORTED
180182
if (esp32_rmt_bitstream_channel_id < 0) {
181183
machine_bitstream_high_low_bitbang(pin, timing_ns, buf, len);
182184
} else {
183185
machine_bitstream_high_low_rmt(pin, timing_ns, buf, len, esp32_rmt_bitstream_channel_id);
184186
}
187+
#else
188+
machine_bitstream_high_low_bitbang(pin, timing_ns, buf, len);
189+
#endif
185190
}
186191

187192
#endif // MICROPY_PY_MACHINE_BITSTREAM

ports/esp32/machine_i2c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
#endif
5151

5252
#if SOC_I2C_SUPPORT_XTAL
53+
#if CONFIG_IDF_TARGET_ESP32C2
54+
#define I2C_SCLK_FREQ APB_CLK_FREQ
55+
#else
5356
#define I2C_SCLK_FREQ XTAL_CLK_FREQ
57+
#endif
5458
#elif SOC_I2C_SUPPORT_APB
5559
#define I2C_SCLK_FREQ APB_CLK_FREQ
5660
#else

ports/esp32/machine_pin.c

Lines changed: 1 addition & 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_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6)
155+
#if !(CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32C2)
156156
rtc_gpio_deinit(index);
157157
#endif
158158
}

ports/esp32/machine_pin.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@
124124
#define MICROPY_HW_ENABLE_GPIO23 (1)
125125
// GPIO 24-30 are used for spi/sip flash.
126126

127+
#elif CONFIG_IDF_TARGET_ESP32C2
128+
#define MICROPY_HW_ENABLE_GPIO0 (1)
129+
#define MICROPY_HW_ENABLE_GPIO1 (1)
130+
#define MICROPY_HW_ENABLE_GPIO2 (1)
131+
#define MICROPY_HW_ENABLE_GPIO3 (1)
132+
#define MICROPY_HW_ENABLE_GPIO4 (1)
133+
#define MICROPY_HW_ENABLE_GPIO5 (1)
134+
#define MICROPY_HW_ENABLE_GPIO6 (1)
135+
#define MICROPY_HW_ENABLE_GPIO7 (1)
136+
#define MICROPY_HW_ENABLE_GPIO8 (1)
137+
#define MICROPY_HW_ENABLE_GPIO9 (1)
138+
#define MICROPY_HW_ENABLE_GPIO10 (1)
139+
#define MICROPY_HW_ENABLE_GPIO18 (1)
140+
141+
#define MICROPY_HW_ENABLE_GPIO19 (1) // UART0_RXD
142+
#define MICROPY_HW_ENABLE_GPIO20 (1) // UART0_TXD
143+
127144
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
128145

129146
#define MICROPY_HW_ENABLE_GPIO0 (1)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Set location of base MicroPython directory.
2+
if(NOT MICROPY_DIR)
3+
get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../.. ABSOLUTE)
4+
endif()
5+
6+
# Set location of the ESP32 port directory.
7+
if(NOT MICROPY_PORT_DIR)
8+
get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE)
9+
endif()
10+
11+
list(APPEND MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/runtime/gchelper_generic.c)
12+
13+
include(${MICROPY_PORT_DIR}/esp32_common.cmake)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
espressif/mdns: "~1.1.0"
4+
idf:
5+
version: ">=5.2.0"

ports/esp32/main_esp32c2/linker.lf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty linker fragment (no workaround required for C2, see main_esp32/linker.lf).

ports/esp32/modesp32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ static const mp_rom_map_elem_t esp32_module_globals_table[] = {
231231

232232
{ MP_ROM_QSTR(MP_QSTR_NVS), MP_ROM_PTR(&esp32_nvs_type) },
233233
{ MP_ROM_QSTR(MP_QSTR_Partition), MP_ROM_PTR(&esp32_partition_type) },
234+
#if SOC_RMT_SUPPORTED
234235
{ MP_ROM_QSTR(MP_QSTR_RMT), MP_ROM_PTR(&esp32_rmt_type) },
236+
#endif
235237
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
236238
{ MP_ROM_QSTR(MP_QSTR_ULP), MP_ROM_PTR(&esp32_ulp_type) },
237239
#endif

ports/esp32/modmachine.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ static mp_obj_t mp_machine_get_freq(void) {
9999

100100
static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
101101
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
102+
#if CONFIG_IDF_TARGET_ESP32C2
103+
if (freq != 80 && freq != 120) {
104+
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 80MHz or 120MHz"));
105+
}
106+
#else
102107
if (freq != 20 && freq != 40 && freq != 80 && freq != 160
103108
#if !(CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6)
104109
&& freq != 240
@@ -110,6 +115,7 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
110115
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz"));
111116
#endif
112117
}
118+
#endif
113119
esp_pm_config_t pm = {
114120
.max_freq_mhz = freq,
115121
.min_freq_mhz = freq,

ports/esp32/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#define MICROPY_GC_INITIAL_HEAP_SIZE (56 * 1024)
3535
#elif CONFIG_IDF_TARGET_ESP32S2 && !CONFIG_SPIRAM
3636
#define MICROPY_GC_INITIAL_HEAP_SIZE (36 * 1024)
37+
#elif CONFIG_IDF_TARGET_ESP32C2
38+
#define MICROPY_GC_INITIAL_HEAP_SIZE (40 * 1024)
3739
#else
3840
#define MICROPY_GC_INITIAL_HEAP_SIZE (64 * 1024)
3941
#endif

0 commit comments

Comments
 (0)
0