Skip to content

Alternative fix for "espulp module broken in CircuitPython 9"#9282

Closed
Sola85 wants to merge 11 commits into
adafruit:mainfrom
Sola85:improve_espulp2
Closed

Alternative fix for "espulp module broken in CircuitPython 9"#9282
Sola85 wants to merge 11 commits into
adafruit:mainfrom
Sola85:improve_espulp2

Conversation

@Sola85
Copy link
Copy Markdown

@Sola85 Sola85 commented May 29, 2024

This is an alternative to PR #9277. In that PR, this issue in the esp-idf was circumvented by disabling one of the ULPs for every type of esp32.
Here, instead we copy one file (namely ports/espressif/bindings/espulp/ulp_riscv.c) from the esp-idf into the circuitpython repo, in order to make the necessary functions for the riscv ulp available at compile time (as suggested by @tannewt here).
This allows both the FSM and RISCV ulps to be included simultaneously in circuitpython for ESP32S2/S3 despite the above issue in esp-idf.

We also have to define CONFIG_ULP_COPROC_TYPE_RISCV manually based on which CONFIG_IDF_TARGET_ESP32XX is set.

Since I'm not sure whether copying a file from esp-idf into the circuitpython repo is acceptable for the maintainers, I have created a separate PR for this commit.

Here is a small proof of concept, showing that the RISCV ULP works again, after this PR

import espulp
import memorymap
import time
# simple counting example, increments a variable once per ulp wakeup
binary = b"\x6f\x00\xe0\x01\x13\x00\x00\x00\x13\x00\x00\x00\x13\x00\x00\x00\x82\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x11\x00\x00\x13\x01\x21\xfe\x19\x28\x19\x20\x1d\x20\x01\xa0\x83\x27\x40\x07\x01\x45\x85\x07\x23\x2a\xf0\x06\x82\x80\xa1\x67\x93\x87\x47\x10\x98\x43\xb7\x06\xc0\xfd\xfd\x16\x75\x8f\x98\xc3\x82\x80\xa1\x67\x93\x87\x47\x10\x98\x43\xb7\x46\xc0\xff\xfd\x16\x75\x8f\xb7\xc6\x0f\x00\x55\x8f\x98\xc3\x98\x43\xb7\x06\x40\x02\x55\x8f\x98\xc3\x01\xa0"

variable = memorymap.AddressRange(start=0x50000074, length=4)

ulp = espulp.ULP(espulp.Architecture.RISCV)
ulp.halt()
ulp.set_wakeup_period(0, 100000)
ulp.run(binary)

print()
while True:
    time.sleep(1)
    print("Value from RISC-V ULP:", int.from_bytes(variable[:], "little"))

@bill88t
Copy link
Copy Markdown

bill88t commented May 29, 2024

Circuitpython has it's own fork of idf.
https://github.com/adafruit/esp-idf

@Sola85
Copy link
Copy Markdown
Author

Sola85 commented May 30, 2024

Ah, good to know. Then I will propose a change enabling the use both ulps simultaneously in that repo instead!

@Sola85 Sola85 closed this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants