Skip to content

Commit 689c6fa

Browse files
committed
Add ESP BLE GATT server support
Enable BLE where we can. Switch 4MB, non-USB board default partitioning over to a single 2MB firmware bank. Old boards override this setting to keep the same behavior. This also adds alpha support for the ESP32-C2 (aka ESP8684). Fixes #5926 and fixes #7170
1 parent ba22fc8 commit 689c6fa

File tree

105 files changed

+1182
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1182
-209
lines changed

devices/ble_hci/common-hal/_bleio/Service.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_ob
5757
}
5858
}
5959

60+
void common_hal_bleio_service_deinit(bleio_service_obj_t *self) {
61+
}
62+
6063
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection) {
6164
self->handle = 0xFFFF;
6265
self->uuid = NULL;

ports/espressif/Makefile

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424

2525
include ../../py/circuitpy_mkenv.mk
2626

27-
ifeq ($(IDF_TARGET),esp32c3)
27+
ifeq ($(IDF_TARGET),esp32c2)
28+
IDF_TARGET_ARCH = riscv
29+
CROSS_COMPILE = riscv32-esp-elf-
30+
else ifeq ($(IDF_TARGET),esp32c3)
2831
IDF_TARGET_ARCH = riscv
2932
CROSS_COMPILE = riscv32-esp-elf-
3033
else ifeq ($(IDF_TARGET),esp32c6)
@@ -68,7 +71,9 @@ INC += \
6871
-isystem esp-idf/components/bt/host/nimble/esp-hci/include \
6972
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/controller/include \
7073
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/include \
74+
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/ans/include \
7175
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/gap/include \
76+
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/gatt/include \
7277
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/include \
7378
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/util/include \
7479
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/transport/include \
@@ -223,6 +228,12 @@ LDFLAGS += \
223228
-T$(IDF_TARGET).rom.newlib-data.ld \
224229
-T$(IDF_TARGET).rom.newlib-funcs.ld \
225230
-T$(IDF_TARGET).rom.spiflash.ld
231+
else ifeq ($(IDF_TARGET),esp32c2)
232+
LDFLAGS += \
233+
-Tesp32c2.rom.heap.ld \
234+
-Tesp32c2.rom.newlib.ld \
235+
-Tesp32c2.rom.version.ld
236+
CFLAGS += -DSOC_XTAL_FREQ_MHZ=CONFIG_XTAL_FREQ
226237
else ifeq ($(IDF_TARGET),esp32c3)
227238
LDFLAGS += \
228239
-Tesp32c3.rom.newlib.ld \
@@ -264,6 +275,8 @@ endif
264275
# Always add these because we might be doing host.
265276
ifeq ($(IDF_TARGET),esp32)
266277
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32
278+
else ifeq ($(IDF_TARGET),esp32c2)
279+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C2
267280
else ifeq ($(IDF_TARGET),esp32c3)
268281
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C3
269282
else ifeq ($(IDF_TARGET),esp32c6)
@@ -408,10 +421,14 @@ else
408421
UF2_BOOTLOADER ?= $(CIRCUITPY_USB_DEVICE)
409422
ifeq ($(UF2_BOOTLOADER), 1)
410423
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE).defaults
424+
else
425+
ifeq ($(CIRCUITPY_ESP_FLASH_SIZE), 4MB)
426+
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE)-no-ota-no-uf2.defaults
411427
else
412428
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE)-no-uf2.defaults
413429
endif
414430
endif
431+
endif
415432
FLASH_MODE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_MODE).defaults
416433
FLASH_SPEED_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_FREQ).defaults
417434

@@ -469,11 +486,15 @@ update-all-sdkconfigs: $(BUILD)/esp-idf/config/sdkconfig.h
469486
update-board-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h
470487
python tools/update_sdkconfig.py --board=$(BOARD) --debug=$(DEBUG)
471488

472-
BINARY_WIFI_BLOBS = libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libwapi.a
489+
BINARY_WIFI_BLOBS = libcore.a libespnow.a libnet80211.a libpp.a libsmartconfig.a
473490
BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a
474491
ifneq ($(CIRCUITPY_WIFI),0)
475492
BINARY_BLOBS += esp-idf/components/esp_coex/lib/$(IDF_TARGET)/libcoexist.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS))
493+
ifneq ($(IDF_TARGET),esp32c2)
494+
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, libmesh.a libwapi.a)
495+
endif
476496
endif
497+
477498
ifeq ($(IDF_TARGET),esp32)
478499
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
479500
endif
@@ -493,6 +514,9 @@ ifneq ($(CIRCUITPY_BLEIO),0)
493514

494515
ESP_IDF_COMPONENTS_LINK += bt
495516
ifeq ($(BLE_IMPL),esp32)
517+
# BLE will hang the ESP32 and trigger an interrupt watchdog without this undefined symbol at
518+
# link because a weak version of the interrupt that BLE uses will be linked incorrectly.
519+
LDFLAGS += -u ld_include_hli_vectors_bt
496520
BINARY_BLOBS += esp-idf/components/bt/controller/lib_esp32/$(IDF_TARGET)/libbtdm_app.a
497521
endif
498522

@@ -544,6 +568,8 @@ ifeq ($(IDF_TARGET),esp32)
544568
BOOTLOADER_OFFSET = 0x1000
545569
else ifeq ($(IDF_TARGET),esp32h2)
546570
BOOTLOADER_OFFSET = 0x0
571+
else ifeq ($(IDF_TARGET),esp32c2)
572+
BOOTLOADER_OFFSET = 0x0
547573
else ifeq ($(IDF_TARGET),esp32c3)
548574
BOOTLOADER_OFFSET = 0x0
549575
else ifeq ($(IDF_TARGET),esp32c6)

ports/espressif/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Support Status:
1111

1212
ESP32, "beta"
1313
ESP32-H2, "alpha"
14+
ESP32-C2, "alpha"
1415
ESP32-C3, "beta"
1516
ESP32-C6, "alpha"
1617
ESP32-S2, "stable"

ports/espressif/boards/01space_lcd042_esp32c3/mpconfigboard.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
77
CIRCUITPY_ESP_FLASH_FREQ = 80m
88
CIRCUITPY_ESP_FLASH_SIZE = 4MB
99

10+
# Override partition layout to preserve compatibility because the default has changed.
11+
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
12+
CIRCUITPY_DUALBANK = 1
13+
CIRCUITPY_BLEIO = 0
14+
1015
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

ports/espressif/boards/adafruit_feather_huzzah32/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ CIRCUITPY_ESP_FLASH_MODE = qio
77
CIRCUITPY_ESP_FLASH_FREQ = 80m
88
CIRCUITPY_ESP_FLASH_SIZE = 4MB
99

10+
CIRCUITPY_BLEIO = 0
1011
CIRCUITPY_ESPCAMERA = 0

ports/espressif/boards/adafruit_huzzah32_breakout/mpconfigboard.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
77
CIRCUITPY_ESP_FLASH_FREQ = 80m
88
CIRCUITPY_ESP_FLASH_SIZE = 4MB
99

10+
# Override partition layout to preserve compatibility because the default has changed.
11+
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
12+
CIRCUITPY_DUALBANK = 1
13+
CIRCUITPY_BLEIO = 0
14+
1015
CIRCUITPY_ESPCAMERA = 0

ports/espressif/boards/adafruit_qtpy_esp32c3/mpconfigboard.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ CIRCUITPY_ESP_FLASH_MODE = qio
77
CIRCUITPY_ESP_FLASH_FREQ = 80m
88
CIRCUITPY_ESP_FLASH_SIZE = 4MB
99

10+
# Override partition layout to preserve compatibility because the default has changed.
11+
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
12+
CIRCUITPY_DUALBANK = 1
13+
CIRCUITPY_BLEIO = 0
14+
1015
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1
1116

1217
# Not enough pins.

ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
77
CIRCUITPY_ESP_FLASH_FREQ = 80m
88
CIRCUITPY_ESP_FLASH_SIZE = 4MB
99

10+
# Override partition layout to preserve compatibility because the default has changed.
11+
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
12+
CIRCUITPY_DUALBANK = 1
13+
CIRCUITPY_BLEIO = 0
14+
1015
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

ports/espressif/boards/beetle-esp32-c3/mpconfigboard.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ CIRCUITPY_ESP_FLASH_MODE=qio
88
CIRCUITPY_ESP_FLASH_FREQ=80m
99
CIRCUITPY_ESP_FLASH_SIZE=4MB
1010

11+
# Override partition layout to preserve compatibility because the default has changed.
12+
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
13+
CIRCUITPY_DUALBANK = 1
14+
CIRCUITPY_BLEIO = 0
15+
1116
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

0 commit comments

Comments
 (0)