Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Rajendra Waghmare
Posts: 8
Joined: Mon Feb 18, 2019 12:30 pm

Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by Rajendra Waghmare » Thu Jan 09, 2020 5:35 am

Hello there,

I have downloaded micropython v1.12 and compiled with esp-idf V4 #310beae373446ceb9a4ad9b36b5428d7fdf2705f with BLE support. I need BLE and ethernet both for my ESP32 application.
As I can see in the Makefile either BLE or ETH is compiled conditionally. Please see the code below.

Code: Select all

ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
$(eval $(call gen_espidf_lib_rule,esp_common,$(ESPIDF_ESP_COMMON_O)))
$(eval $(call gen_espidf_lib_rule,esp_event,$(ESPIDF_ESP_EVENT_O)))
$(eval $(call gen_espidf_lib_rule,esp_wifi,$(ESPIDF_ESP_WIFI_O)))
ifeq ($(CONFIG_BT_NIMBLE_ENABLED),y)
$(eval $(call gen_espidf_lib_rule,bt_nimble,$(ESPIDF_BT_NIMBLE_O)))
endif
$(eval $(call gen_espidf_lib_rule,esp_eth,$(ESPIDF_ESP_ETH_O)))
$(eval $(call gen_espidf_lib_rule,xtensa,$(ESPIDF_XTENSA_O)))
else
$(eval $(call gen_espidf_lib_rule,ethernet,$(ESPIDF_ETHERNET_O)))
endif
From this it looks like BLE and ETH does not work simultaneously. Is this correct? If yes any reason for that. Is there any future build planned to have both enabled?
BLE and ETH?

Thanks,
-Rajendra

User avatar
jimmo
Posts: 1845
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Thu Jan 09, 2020 1:04 pm

Please see https://github.com/micropython/micropython/pull/5107 and https://github.com/micropython/micropython/issues/5265

The simple answer though is that the MicroPython ethernet driver was written against the 3.3 IDF, and the API changed significantly in 4.x. I guess we're waiting for someone who has both an ESP32 board with an ethernet interface and the time and interest to update the driver to use the new IDF API.

The other alternative is that NimBLE is now supported in the latest minor release of the 3.3 IDF, which became available just before MicroPython 1.12 was released. We didn't want to change IDF versions just before a release though.
Either way, if you cherrypick this commit -- https://github.com/jimmo/micropython/co ... b006a59878 -- then you can build against the 3.3 IDF (you'll have to update your IDF checkout to the new commit hash) and have BLE and LAN together.

(I plan to send that as a PR as soon as I have some time to do some more thorough testing, but all the testing I've done so far showed no issues).

Rajendra Waghmare
Posts: 8
Joined: Mon Feb 18, 2019 12:30 pm

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by Rajendra Waghmare » Fri Jan 10, 2020 9:03 am

Thank you Jimmo for reply.
As suggested, I could compile micropython#36f953a2fcc806e72badbea935de8db006a59878 with latest IDF#6ccb4cf5b7d1fdddb8c2492f9cbc926abaf230df. With this the LAN is enabled. However I do not see BLE module is enabled - ubluetooth or bluetooth is not listed in micropython modules. Am I missing something here, or there is some other way to configure and use nimBLE?

User avatar
jimmo
Posts: 1845
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Fri Jan 10, 2020 10:53 am

Did you cherrypick the commit I referenced? It doesn't sound like it, as you would need to move to IDF commit 143d26aa49df524e10fb8e41a71d12e731b9b71d to make it build.

User avatar
jimmo
Posts: 1845
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Fri Jan 10, 2020 10:56 am

To explain in more detail,

IDF 3.3 (6ccb4cf5b7d1fdddb8c2492f9cbc926abaf230df) does not support NimBLE.
IDF 3.3.1 (143d26aa49df524e10fb8e41a71d12e731b9b71d) does support NimBLE.
IDF 4.0-beta1 supports NimBLE, but the API for LAN and PPP is incompatible with MicroPython.

The current MicroPython master branch uses either 3.3 or 4.0-beta1. If you cherrypick my commit, then it will support 3.3.1 instead of 3.3 (which means that you'll get ubluetooth, as well as LAN and PPP).

Rajendra Waghmare
Posts: 8
Joined: Mon Feb 18, 2019 12:30 pm

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by Rajendra Waghmare » Mon Jan 13, 2020 7:30 am

I tried to build with this # but ran into build errors.

Code: Select all

CC /home/user/esp/esp-idf-3.3-9jan2020/esp-idf//components/soc/esp32/rtc_wdt.c
CC /home/user/esp/esp-idf-3.3-9jan2020/esp-idf//components/soc/esp32/sdio_slave_periph.c
CC /home/user/esp/esp-idf-3.3-9jan2020/esp-idf//components/soc/esp32/sdmmc_periph.c
CC /home/user/esp/esp-idf-3.3-9jan2020/esp-idf//components/soc/esp32/soc_memory_layout.c
CC /home/user/esp/esp-idf-3.3-9jan2020/esp-idf//components/soc/esp32/spi_periph.c
CC /home/user/esp/esp-idf-3.3-9jan2020/esp-idf//components/soc/src/memory_layout_utils.c
AR build-GENERIC/bootloader/libsoc.a
CC /home/user/esp/esp-idf-3.3-9jan2020/esp-idf//components/bootloader/subproject/main/bootloader_start.c
AR build-GENERIC/bootloader/libmain.a
LINK build-GENERIC/bootloader.elf
build-GENERIC/bootloader/libbootloader_support.a(bootloader_init.o):(.literal.bootloader_init+0xa0): undefined reference to `bootloader_flash_gpio_config'
build-GENERIC/bootloader/libbootloader_support.a(bootloader_init.o):(.literal.bootloader_init+0xa4): undefined reference to `bootloader_flash_dummy_config'
build-GENERIC/bootloader/libbootloader_support.a(bootloader_init.o):(.literal.bootloader_init+0xa8): undefined reference to `bootloader_flash_cs_timing_config'
build-GENERIC/bootloader/libbootloader_support.a(bootloader_init.o): In function `bootloader_init':
bootloader_init.c:(.text.bootloader_init+0x14a): undefined reference to `bootloader_flash_gpio_config'
bootloader_init.c:(.text.bootloader_init+0x152): undefined reference to `bootloader_flash_dummy_config'
bootloader_init.c:(.text.bootloader_init+0x158): undefined reference to `bootloader_flash_cs_timing_config'
collect2: error: ld returned 1 exit status
Makefile:685: recipe for target 'build-GENERIC/bootloader.elf' failed
make: *** [build-GENERIC/bootloader.elf] Error 1
user@raj-pc:~/esp/micropython-master/micropython/ports/esp32$ 
Last edited by Rajendra Waghmare on Mon Jan 13, 2020 8:11 am, edited 1 time in total.

User avatar
jimmo
Posts: 1845
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Mon Jan 13, 2020 7:36 am

I just submitted the PR for this https://github.com/micropython/micropython/pull/5524

Can you try doing a "make clean" and build again?

Either way, when this gets merged, all ESP32 builds will support BLE.

Rajendra Waghmare
Posts: 8
Joined: Mon Feb 18, 2019 12:30 pm

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by Rajendra Waghmare » Thu Jan 16, 2020 3:44 am

Thanks Jimmo! I could compile the code and see that both are enabled. I need to do some testing using both simultaneously.

User avatar
jimmo
Posts: 1845
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Sat Jan 18, 2020 5:35 am

This is now merged, so the nightly builds on https://micropython.org/download will include this. (Although there are reports of SSL issues that need to be investigated)

User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by iotman » Mon Jan 20, 2020 8:39 am

Hi Jimmo, I'm about to start working with BLE after a couple of months distracted by migrating servers.

We had discussed this previously, and it seems like the BLE has now been implemented in the code that I can flash an ESP32 with.

So I'm just wondering if I can write code in micropython, just the same (or similar) to how we can program with WiFi?

Is there any boilerplate sample code somewhere that you might know of?

Regards, AB

Post Reply