Skip to content

Commit 90c8a3e

Browse files
tannewtclaude
andcommitted
Fix build for all 9 ESP32 chipsets with IDF v6.0
- Move chip-specific IDF components (esp_hal_rmt, esp_hal_usb, esp_hal_dma, esp_hal_pmu, esp_driver_usb_serial_jtag) from common link list to per-chip CHIP_COMPONENTS since not all chips have these as static libraries - Re-add rom.wdt.ld linker scripts from new esp_hal_wdt component paths - Re-add esp32s2.rom.spiflash_legacy.ld for S2 - Add P4 register include paths (hw_ver3/hw_ver1), LDO include, and eco5 ROM linker scripts - Remove xesppie from P4 -march flag (GCC doesn't support it, clang-only) - Guard RTC_DATA_ATTR for chips without RTC memory (C2, C61) - Remove use_dma2d flag from MIPI DSI config (now separate API in v6.0) - Migrate I2CTarget to new i2c_slave driver API (legacy i2c removed) - Update protomatter submodule for gpio_struct.h include Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3701bc7 commit 90c8a3e

7 files changed

Lines changed: 96 additions & 40 deletions

File tree

lib/protomatter

ports/espressif/Makefile

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ ifeq ($(IDF_TARGET_ARCH),xtensa)
253253
else ifeq ($(IDF_TARGET_ARCH),riscv)
254254

255255
ifeq ($(IDF_TARGET),esp32p4)
256-
CFLAGS += -march=rv32imafc_zicsr_zifencei_xesppie -mabi=ilp32f
256+
CFLAGS += -march=rv32imafc_zicsr_zifencei -mabi=ilp32f
257257
else
258258
CFLAGS += -march=rv32imac_zicsr_zifencei
259259
endif
@@ -294,7 +294,7 @@ LDFLAGS += \
294294

295295
CHIP_COMPONENTS = \
296296
esp_driver_dac \
297-
esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_touch_sens esp_hal_twai
297+
esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_rmt esp_hal_touch_sens esp_hal_twai
298298

299299
else ifeq ($(IDF_TARGET),esp32c2)
300300
LDFLAGS += \
@@ -310,7 +310,8 @@ LDFLAGS += \
310310
CFLAGS += -DSOC_XTAL_FREQ_MHZ=CONFIG_XTAL_FREQ
311311

312312
CHIP_COMPONENTS = \
313-
esp_driver_tsens
313+
esp_driver_tsens \
314+
esp_hal_dma esp_hal_pmu
314315

315316
else ifeq ($(IDF_TARGET),esp32c3)
316317
# esp32c2 has none of: esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_touch_sens esp_hal_twai
@@ -324,7 +325,8 @@ LDFLAGS += \
324325

325326
CHIP_COMPONENTS = \
326327
esp_driver_tsens \
327-
esp_hal_i2s esp_hal_twai
328+
esp_driver_usb_serial_jtag \
329+
esp_hal_dma esp_hal_i2s esp_hal_pmu esp_hal_rmt esp_hal_twai esp_hal_usb
328330

329331
else ifeq ($(IDF_TARGET),esp32c6)
330332
LDFLAGS += \
@@ -341,7 +343,8 @@ LDFLAGS += \
341343

342344
CHIP_COMPONENTS = \
343345
esp_driver_tsens \
344-
esp_hal_i2s esp_hal_pcnt esp_hal_twai
346+
esp_driver_usb_serial_jtag \
347+
esp_hal_dma esp_hal_i2s esp_hal_pcnt esp_hal_pmu esp_hal_rmt esp_hal_twai esp_hal_usb
345348

346349
else ifeq ($(IDF_TARGET),esp32c61)
347350
LDFLAGS += \
@@ -359,20 +362,30 @@ LDFLAGS += \
359362

360363
CHIP_COMPONENTS = \
361364
esp_driver_tsens \
362-
esp_hal_i2s
365+
esp_driver_usb_serial_jtag \
366+
esp_hal_dma esp_hal_i2s esp_hal_pmu esp_hal_usb
363367

364368
else ifeq ($(IDF_TARGET),esp32p4)
369+
CFLAGS += \
370+
-isystem esp-idf/components/soc/esp32p4/register/hw_ver3 \
371+
-isystem esp-idf/components/soc/esp32p4/register/hw_ver1 \
372+
-isystem esp-idf/components/esp_hw_support/ldo/include
373+
365374
LDFLAGS += \
366375
-Tesp32p4.rom.libc.ld \
367376
-Tesp32p4.rom.newlib.ld \
368377
-Tesp32p4.rom.systimer.ld \
378+
-Tesp32p4.rom.eco5.ld \
379+
-Tesp32p4.rom.eco5.libc.ld \
380+
-Tesp32p4.rom.eco5.rvfp.ld \
381+
-Tesp32p4.rom.version.ld \
369382
-Trom.wdt.ld
370383

371384

372385
CHIP_COMPONENTS = \
373386
esp_driver_tsens \
374387
esp_driver_usb_serial_jtag \
375-
esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_touch_sens esp_hal_twai
388+
esp_hal_dma esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_pmu esp_hal_rmt esp_hal_touch_sens esp_hal_twai esp_hal_usb
376389

377390
else ifeq ($(IDF_TARGET),esp32h2)
378391
LDFLAGS += \
@@ -384,18 +397,20 @@ LDFLAGS += \
384397

385398
CHIP_COMPONENTS = \
386399
esp_driver_tsens \
387-
esp_hal_i2s esp_hal_pcnt esp_hal_twai
400+
esp_driver_usb_serial_jtag \
401+
esp_hal_dma esp_hal_i2s esp_hal_pcnt esp_hal_pmu esp_hal_rmt esp_hal_twai esp_hal_usb
388402

389403
else ifeq ($(IDF_TARGET),esp32s2)
390404
LDFLAGS += \
391405
-Tesp32s2.rom.libc-funcs.ld \
392406
-Tesp32s2.rom.newlib-data.ld \
393-
-Tesp32s2.rom.newlib-reent-funcs.ld
407+
-Tesp32s2.rom.newlib-reent-funcs.ld \
408+
-Tesp32s2.rom.spiflash_legacy.ld
394409

395410
CHIP_COMPONENTS = \
396411
esp_driver_dac \
397412
esp_driver_tsens \
398-
esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_touch_sens esp_hal_twai
413+
esp_hal_dma esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_rmt esp_hal_touch_sens esp_hal_twai esp_hal_usb
399414

400415
else ifeq ($(IDF_TARGET),esp32s3)
401416
LDFLAGS += \
@@ -408,7 +423,8 @@ LDFLAGS += \
408423

409424
CHIP_COMPONENTS = \
410425
esp_driver_tsens \
411-
esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_touch_sens esp_hal_twai
426+
esp_driver_usb_serial_jtag \
427+
esp_hal_dma esp_hal_i2s esp_hal_lcd esp_hal_pcnt esp_hal_pmu esp_hal_rmt esp_hal_touch_sens esp_hal_twai esp_hal_usb
412428

413429
endif
414430

@@ -759,7 +775,7 @@ ifeq ($(IDF_TARGET),esp32)
759775
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
760776
endif
761777

762-
ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_dma esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_ledc esp_driver_spi esp_driver_uart esp_driver_usb_serial_jtag efuse esp_adc esp_app_format esp_common esp_event esp_gdbstub esp_hal_ana_conv esp_hal_clock esp_hal_dma esp_hal_gpio esp_hal_gpspi esp_hal_i2c esp_hal_ledc esp_hal_mspi esp_hal_pmu esp_hal_rmt esp_hal_security esp_hal_timg esp_hal_uart esp_hal_usb esp_hal_wdt esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log esp_libc nvs_flash nvs_sec_provider pthread soc spi_flash vfs esp_stdio
778+
ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_dma esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_gdbstub esp_hal_ana_conv esp_hal_clock esp_hal_gpio esp_hal_gpspi esp_hal_i2c esp_hal_ledc esp_hal_mspi esp_hal_security esp_hal_timg esp_hal_uart esp_hal_wdt esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log esp_libc nvs_flash nvs_sec_provider pthread soc spi_flash vfs esp_stdio
763779
ifneq ($(CIRCUITPY_WIFI),0)
764780
ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp_security esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant esp_phy
765781
endif

ports/espressif/common-hal/alarm/SleepMemory.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515

1616
// Data storage for singleton instance of SleepMemory.
1717
// Might be RTC_SLOW_MEM or RTC_FAST_MEM, depending on setting of CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM.
18+
#if defined(CONFIG_SOC_RTC_FAST_MEM_SUPPORTED) || defined(CONFIG_SOC_RTC_SLOW_MEM_SUPPORTED)
1819
static RTC_DATA_ATTR uint8_t _sleep_mem[SLEEP_MEMORY_LENGTH];
20+
#else
21+
// Chips without RTC memory can't persist SleepMemory across deep sleep.
22+
static uint8_t _sleep_mem[SLEEP_MEMORY_LENGTH];
23+
#endif
1924

2025
void alarm_sleep_memory_reset(void) {
2126
// ESP-IDF build system takes care of doing esp_sleep_pd_config() or the equivalent with

ports/espressif/common-hal/busio/I2C.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "py/mphal.h"
1010
#include "py/runtime.h"
1111

12-
#include "components/driver/i2c/include/driver/i2c.h"
1312
#include "driver/gpio.h"
1413

1514
#include "bindings/espidf/__init__.h"

ports/espressif/common-hal/i2ctarget/I2CTarget.c

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
#include "common-hal/i2ctarget/I2CTarget.h"
1313
#include "shared-bindings/microcontroller/Pin.h"
1414

15+
static bool i2c_slave_on_receive(i2c_slave_dev_handle_t i2c_slave, const i2c_slave_rx_done_event_data_t *evt_data, void *arg) {
16+
i2ctarget_i2c_target_obj_t *self = (i2ctarget_i2c_target_obj_t *)arg;
17+
for (uint32_t i = 0; i < evt_data->length; i++) {
18+
uint16_t next_head = (self->recv_head + 1) % I2CTARGET_RECV_BUF_SIZE;
19+
if (next_head == self->recv_tail) {
20+
break; // buffer full
21+
}
22+
self->recv_buf[self->recv_head] = evt_data->buffer[i];
23+
self->recv_head = next_head;
24+
}
25+
return false;
26+
}
27+
1528
void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self,
1629
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
1730
uint8_t *addresses, unsigned int num_addresses, bool smbus) {
@@ -31,32 +44,40 @@ void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self,
3144

3245
self->sda_pin = sda;
3346
self->scl_pin = scl;
34-
self->i2c_num = peripherals_i2c_get_free_num();
3547

36-
if (self->i2c_num == I2C_NUM_MAX) {
37-
mp_raise_ValueError(MP_ERROR_TEXT("All I2C peripherals are in use"));
38-
}
39-
40-
const i2c_config_t i2c_conf = {
41-
.mode = I2C_MODE_SLAVE,
42-
.sda_io_num = self->sda_pin->number,
43-
.scl_io_num = self->scl_pin->number,
44-
.sda_pullup_en = GPIO_PULLUP_ENABLE,
45-
.scl_pullup_en = GPIO_PULLUP_ENABLE,
46-
.slave.addr_10bit_en = 0,
47-
.slave.slave_addr = self->addresses[0],
48+
self->recv_head = 0;
49+
self->recv_tail = 0;
50+
51+
i2c_slave_config_t slave_config = {
52+
.i2c_port = -1, // auto
53+
.sda_io_num = sda->number,
54+
.scl_io_num = scl->number,
55+
.clk_source = I2C_CLK_SRC_DEFAULT,
56+
.send_buf_depth = 256,
57+
.receive_buf_depth = 256,
58+
.slave_addr = addresses[0],
59+
.addr_bit_len = I2C_ADDR_BIT_LEN_7,
60+
.flags = {
61+
.enable_internal_pullup = true,
62+
},
4863
};
4964

50-
// Initialize I2C.
51-
esp_err_t err = peripherals_i2c_init(self->i2c_num, &i2c_conf);
65+
esp_err_t err = i2c_new_slave_device(&slave_config, &self->handle);
5266
if (err != ESP_OK) {
53-
if (err == ESP_FAIL) {
67+
if (err == ESP_ERR_NOT_FOUND) {
68+
mp_raise_ValueError(MP_ERROR_TEXT("All I2C peripherals are in use"));
69+
} else if (err == ESP_FAIL) {
5470
mp_raise_OSError(MP_EIO);
5571
} else {
5672
mp_arg_error_invalid(MP_QSTR_I2CTarget);
5773
}
5874
}
5975

76+
i2c_slave_event_callbacks_t cbs = {
77+
.on_receive = i2c_slave_on_receive,
78+
};
79+
i2c_slave_register_event_callbacks(self->handle, &cbs, self);
80+
6081
claim_pin(sda);
6182
claim_pin(scl);
6283
}
@@ -70,7 +91,8 @@ void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) {
7091
return;
7192
}
7293

73-
peripherals_i2c_deinit(self->i2c_num);
94+
i2c_del_slave_device(self->handle);
95+
self->handle = NULL;
7496

7597
common_hal_reset_pin(self->sda_pin);
7698
common_hal_reset_pin(self->scl_pin);
@@ -83,24 +105,34 @@ int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *sel
83105
*address = self->addresses[0];
84106
*is_read = true;
85107
*is_restart = false;
86-
return 1;
108+
// Check if we have received data
109+
if (self->recv_head != self->recv_tail) {
110+
*is_read = false;
111+
return 1;
112+
}
113+
return 0;
87114
}
88115

89116
int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data) {
90-
i2c_slave_read_buffer(self->i2c_num, data, 128, 0);
117+
if (self->recv_head == self->recv_tail) {
118+
return 0; // no data available
119+
}
120+
*data = self->recv_buf[self->recv_tail];
121+
self->recv_tail = (self->recv_tail + 1) % I2CTARGET_RECV_BUF_SIZE;
91122
return 1;
92123
}
93124

94125
int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data) {
95-
i2c_reset_tx_fifo(self->i2c_num);
96-
i2c_slave_write_buffer(self->i2c_num, &data, 128, 0);
126+
uint32_t write_len;
127+
esp_err_t err = i2c_slave_write(self->handle, &data, 1, &write_len, 100);
128+
if (err != ESP_OK || write_len == 0) {
129+
return 0;
130+
}
97131
return 1;
98132
}
99133

100134
void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) {
101-
102135
}
103136

104137
void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self) {
105-
106138
}

ports/espressif/common-hal/i2ctarget/I2CTarget.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
#pragma once
88

99
#include "py/obj.h"
10-
#include "peripherals/i2c.h"
10+
#include "driver/i2c_slave.h"
1111
#include "common-hal/microcontroller/Pin.h"
1212

13+
#define I2CTARGET_RECV_BUF_SIZE 128
14+
1315
typedef struct {
1416
mp_obj_base_t base;
15-
i2c_port_t i2c_num;
17+
i2c_slave_dev_handle_t handle;
1618
uint8_t *addresses;
1719
uint8_t num_addresses;
1820
const mcu_pin_obj_t *scl_pin;
1921
const mcu_pin_obj_t *sda_pin;
22+
uint8_t recv_buf[I2CTARGET_RECV_BUF_SIZE];
23+
volatile uint16_t recv_head;
24+
volatile uint16_t recv_tail;
2025
} i2ctarget_i2c_target_obj_t;

ports/espressif/common-hal/mipidsi/Display.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ void common_hal_mipidsi_display_construct(mipidsi_display_obj_t *self,
8888
.vsync_front_porch = vsync_front_porch,
8989
},
9090
.flags = {
91-
.use_dma2d = false,
9291
.disable_lp = false,
9392
},
9493
};

0 commit comments

Comments
 (0)