esp32/boards: Add Pycom LoPy and LoPy4 board definitions with SX127x LoRa driver - #19026
esp32/boards: Add Pycom LoPy and LoPy4 board definitions with SX127x LoRa driver#19026ddtdanilo wants to merge 5 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19026 +/- ##
=======================================
Coverage 98.46% 98.46%
=======================================
Files 176 176
Lines 22784 22784
=======================================
Hits 22435 22435
Misses 349 349 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code size report: |
|
It is clearly a pity that Pycom disappeared and there is not software support any more for the Pycom boards. Therefore boards defintions for Pycom boards may be helpful. For this PR, the file structure should be changed matching the structure of MicroPython.
Some detailed comments:
Edit: I made a trial build for a LoPy4 board. It builds with ESP-IDF V5.5.1, the firmware works at the board. WiFi connects. I did not try LoRa. |
Add a unified SX1272/SX1276 LoRa driver and WS2812 NeoPixel RGB LED helper as shared frozen modules for Pycom boards. The driver handles register-level differences between both chip variants including bandwidth encoding, coding rate bits, CRC location, and RSSI offsets. Signed-off-by: Danilo D <[email protected]>
Add board definition for the Pycom LoPy (L01 module) with ESP32, 4MB flash, SX1272 LoRa transceiver, and WS2812 NeoPixel RGB LED. Pin names in pins.csv include P0-P23 user pin aliases and LORA_* named pins for the SX1272 radio, eliminating the need for a separate board_config module. Includes OTA variant support. Signed-off-by: Danilo D <[email protected]>
Add board definition for the Pycom LoPy4 (L04 module) with ESP32, 8MB flash, 4MB PSRAM, SX1276 LoRa transceiver, and WS2812 NeoPixel. Includes custom 8MB partition table, SPIRAM configuration, OTA variant with dual app partitions, and LORA_* named pins. The SX1276 has no hardware reset pin so the driver uses soft reset. Signed-off-by: Danilo D <[email protected]>
Add LoRaWAN 1.0.x MAC layer with OTAA/ABP Class A support and AES-128-CMAC/CTR crypto built on ucryptolib. Add OTA firmware update helper using esp32.Partition API. Add hardware validation script for GPIO, WiFi, BLE, NeoPixel, PSRAM, and LoRa chip testing. Signed-off-by: Danilo D <[email protected]>
Add hardware tests for SX127x driver (config, TX power, parameter validation), RGB LED, and LoRaWAN crypto (RFC 4493 CMAC vectors, CTR round-trip, MIC, key derivation). Tests use named pins from pins.csv and skip gracefully on non-Pycom boards. Signed-off-by: Danilo D <[email protected]>
0e2f582 to
9abf3d2
Compare
Add board photos for the Pycom LoPy and LoPy4 development boards as referenced by the board definitions in micropython/micropython#19026. Signed-off-by: Danilo D <[email protected]>
Add a LoRa radio driver that handles both SX1272 and SX1276 transceivers. The existing lora-sx127x package only supports SX1276 (version register 0x12); this driver also handles SX1272 (version 0x22) with its different register layouts for bandwidth, coding rate, CRC, and RSSI calculation. Used by Pycom LoPy (SX1272) and LoPy4 (SX1276) boards as defined in micropython/micropython#19026. Signed-off-by: Danilo D <[email protected]>
Add LoRaWAN Class A device operation with OTAA and ABP activation. Includes AES-128-CMAC/CTR crypto primitives built on ucryptolib for MIC calculation, payload encryption, and session key derivation per the LoRaWAN 1.0.x specification. Used by Pycom LoPy/LoPy4 boards as defined in micropython/micropython#19026. Signed-off-by: Danilo D <[email protected]>
|
Hi @robert-hh, thank you very much for the review and for taking the time to do a trial build — really appreciated! Great to hear it builds and WiFi works on actual hardware. I've addressed all your feedback: LoRa pins in pins.csv — Added Board images — Submitted to micropython-media: micropython/micropython-media#116 Driver to micropython-lib — Submitted as a separate PR: micropython/micropython-lib#1102. It includes two packages:
Once those two PRs are merged, I'll update this PR to use ruff CI — Fixed the missing Also restructured the commits to be cleaner (5 focused commits). Let me know if there's anything else I should adjust! |
|
Quick status update on the Per @projectgus's request on micropython/micropython-lib#1102, the LoRa stack is now split into two independently reviewable PRs:
Both are mergeable with all CI checks passing (build, ruff, codespell). Once they land on |
|
Hi @robert-hh — quick friendly check-in. The |
There was a problem hiding this comment.
Thanks for contributing this @ddtdanilo, and thanks @robert-hh for the initial review pass.
I have some comments below, but my main concern is about the supporting micropython-lib PRs - they may take a while.
How would you feel about merging minimal board support for now, without the frozen LoRa drivers, and then after we get the drivers in micropython-lib we can easily open a PR to freeze them onto these boards?
In the meantime if you wanted to host the Pycom-specific Python drivers somewhere else then people can still use mpremote mip install to install them onto their boards.
There was a problem hiding this comment.
The images can be pulled out now they're submitted in micropython-media
| // LoRa radio (SX1272) pin configuration | ||
| #define MICROPY_HW_LORA_MOSI (27) | ||
| #define MICROPY_HW_LORA_MISO (19) | ||
| #define MICROPY_HW_LORA_SCLK (5) | ||
| #define MICROPY_HW_LORA_CS (17) | ||
| #define MICROPY_HW_LORA_DIO0 (23) | ||
| #define MICROPY_HW_LORA_RESET (18) | ||
| #define MICROPY_HW_LORA_CHIP (1272) | ||
|
|
||
| // RGB LED (WS2812 NeoPixel) | ||
| #define MICROPY_HW_NEOPIXEL_PIN (0) |
There was a problem hiding this comment.
Are these used anywhere? (Same question for the other board.)
If not then suggest removing.
| @@ -0,0 +1,8 @@ | |||
| set(SDKCONFIG_DEFAULTS | |||
| ${SDKCONFIG_DEFAULTS} | |||
| boards/PYCOM_LOPY/sdkconfig.ota | |||
There was a problem hiding this comment.
| boards/PYCOM_LOPY/sdkconfig.ota | |
| boards/ESP32_GENERIC/sdkconfig.ota |
(These files have the same contents, so can remove the duplicate from this PR and reference the original directly.)
There was a problem hiding this comment.
Suggest moving this to the micropython-lib LoRaWAN PR (unfortunately micropython-lib tests are a bit more ad hoc, but we do have them!)
There was a problem hiding this comment.
Similar to the lorawan crypto tests, this can go in a tests directory for the micropython-lib driver
There was a problem hiding this comment.
This is probably too board-specific to go in the esp32 port tests. Not sure if we have a place for a test like this (board-specific and requires manual verification of the LED colours) in MicroPython, but maybe in the board directory? @dpgeorge what do you think?
| boards/sdkconfig.ble | ||
| boards/PYCOM_LOPY/sdkconfig.board | ||
| ) | ||
|
|
There was a problem hiding this comment.
We've just merged #18873 so this section can be simplified (after rebase) to something like:
include(boards/mpconfigboard_esp32s3_common.cmake)
list(APPEND SDKCONFIG_DEFAULTS
boards/PYCOM_LOPY/sdkconfig.board)
Summary
Add board definitions, LoRa driver, LoRaWAN MAC, OTA support, and hardware validation for Pycom LoPy and LoPy4 — bringing these archived boards back to life on modern MicroPython.
Boards
Changes addressing review feedback
LORA_MOSI,LORA_MISO,LORA_SCLK,LORA_CS,LORA_DIO0,LORA_RESET,NEOPIXEL— eliminatesboard_config.pypycom_common/as frozen modules; ready to move to micropython-lib in a follow-up PR (note: upstreamlora-sx127xonly supports SX1276, our driver also handles SX1272)from micropython import const, removed unusedSPIimportFeatures
pycom_common/sx127x.py): Unified SX1272/SX1276 register-level driverpycom_common/lorawan.py): Class A with OTAA/ABP, AES-128 cryptoBOARD_VARIANT=OTAfor both boards with dual app partitionspycom_common/pycom_rgb.py): WS2812 NeoPixelpycom_common/ota.py): Firmware update via esp32.Partition APIpycom_common/test_hardware.py): GPIO, WiFi, BLE, LoRa, PSRAM testsStructure
Testing
Build verification (all configurations compile):
make BOARD=PYCOM_LOPY— 1.7MB appmake BOARD=PYCOM_LOPY4— 1.5MB app, 24% freemake BOARD=PYCOM_LOPY BOARD_VARIANT=OTAmake BOARD=PYCOM_LOPY4 BOARD_VARIANT=OTATest files in
tests/ports/esp32/:pycom_sx127x.py: Driver init, config, TX power, validation (uses named pins)pycom_rgb.py: LED color, off, heartbeatpycom_lorawan_crypto.py: AES-128-CMAC (RFC 4493 vectors), CTR, MIC, keysAll Python files pass
ruff check,ruff format,codespell,tools/verifygitlog.py.Follow-up items