roll: third_party/pigweed pw_digital_io_mcuxpresso: Use hardware level interrupts instead of edge

This commit updates the internal implementation of
McuxpressoDigitalInOutInterrupt to use hardware level-sensitive
interrupts to implement all edge-sensitive interrupts. Previously, only
"kBothEdges" interrupts were implemented with level-sensitive
interrupts.

The reason for this change is to work around a hardware bug around
deep sleep and GPIO edge interrupts on the RT500 MCU.

If, for example, a falling-edge interrupt is set, and the chip enters
deep-sleep while the line is low, the chip will wake up immediately (the
wakeup signal from the GPIO block always acts as level-sensitive in
deep sleep). However, the edge detector in the block won't register an
edge (as none occurred), so no interrupt will be pended in the NVIC. The
chip will exit deep sleep, but there's nothing to do and no interrupts
pending, so the chip enters deep sleep again. All of this happens
without the CPU ever actually exiting WFI and executing instructions. If
the line is still low when the chip enters deep sleep again, it'll
repeat this over and over again.

This "edge-sensitive emulation" works, at the cost of 2x the interrupts
(handled internally in this class), because the system will wake up for
the opposing edge (for internal polarity swapping and bookkeeping), in
addition to the one it actually cares about.

Original-Bug: b/370770558
Tested: Tried both falling and rising interrupts, confirmed they fired
Tested: when expected.
Tested: Also enabled deep sleep and set up an falling-edge interrupt
Tested: attached to a button. Watched the PMIC_SEL0 pin in a logic
Tested: analyzer. Confirmed that before this change, pressing the
Tested: button causes rapid oscillations on PMIC_SEL0 (~5 us period).
Tested: After this change, each time the button is pressed or released
Tested: the system briefly wakes from deep sleep to service the
Tested: interrupt, but then goes back to sleep.
Original-Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/261612
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Original-Revision: b2441ff1e55ad1fbd055099a1ff210f7f7e7c589

Rolled-Repo: https://pigweed.googlesource.com/pigweed/pigweed
Rolled-Commits: 3d1d7aec46d512..b2441ff1e55ad1
Roll-Count: 1
Roller-URL: https://cr-buildbucket.appspot.com/build/8724844446055083985
GitWatcher: ignore
CQ-Do-Not-Cancel-Tryjobs: true
Change-Id: I0e12cb0c5574f199b54fb6ec4c6755536faf3b4a
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/kudzu/+/262679
Commit-Queue: Pigweed Roller <pigweed-roller@pigweed-service-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Bot-Commit: Pigweed Roller <pigweed-roller@pigweed-service-accounts.iam.gserviceaccount.com>
1 file changed
tree: 01bf751b044b0a28c520988ad5c5a6eb8de3c75c
  1. applications/
  2. build_overrides/
  3. lib/
  4. pcb/
  5. targets/
  6. third_party/
  7. tools/
  8. .bazelignore
  9. .bazelrc
  10. .bazelversion
  11. .gitignore
  12. .gitmodules
  13. .gn
  14. activate.bat
  15. banner.txt
  16. bootstrap.bat
  17. bootstrap.fish
  18. bootstrap.sh
  19. BUILD.gn
  20. BUILDCONFIG.gn
  21. OWNERS
  22. pigweed.json
  23. README.md
  24. WORKSPACE
README.md

Kudzu

Getting Started

Make sure you've set up Pigweed's prerequisites.

If you're on Windows, you can automate the initial setup by downloading the first-time setup script from cmd.exe:

curl https://pigweed.googlesource.com/pigweed/sample_project/+/main/tools/setup_windows_prerequisites.bat?format=TEXT > setup_pigweed_prerequisites.b64 && certutil -decode -f setup_pigweed_prerequisites.b64 setup_pigweed_prerequisites.bat && del setup_pigweed_prerequisites.b64

Then you can run the script with the following command in cmd.exe:

setup_pigweed_prerequisites.bat

Note: You may see a few UAC prompts as the script installs Git, Python, and enables developer mode.

Once that is done, you can clone this project with the following command:

git clone https://pigweed.googlesource.com/pigweed/kudzu

Environment setup

Pigweed uses a local development environment for most of its tools. This means tools are not installed to your machine, and are instead stored in a directory inside your project (Note: git ignores this directory). The tools are temporarily added to the PATH of the current shell session.

To make sure the latest tooling has been fetched and set up, run the bootstrap command for your operating system:

Windows

bootstrap.bat

Linux & Mac

source ./bootstrap.sh

After tooling updates, you might need to run bootstrap again to ensure the latest tools.

After the initial bootstrap, you can use use the activate scripts to configure the current shell for development without doing a full update.

Windows

activate.bat

Linux & Mac

source ./activate.sh

Device tools setup

Install the pico SDK and tool to flash the device.

pw package install pico_sdk
pw package install picotool

These packages will be built and added to the path automatically. There is no need to add these to the gn arguments.

Linux Setup

GLFW Dependency:

Install the GLFW OpenGL library

sudo apt install libglfw3-dev libglfw3

Udev Rules:

Put the following into /usr/lib/udev/rules.d/49-picoprobe.rules

# Pico app mode
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000a", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000a", MODE:="0666", SYMLINK+="rp2040"

# RP2 Boot
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE:="0666", SYMLINK+="rp2040"

# Picoprobe
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0004", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0004", MODE:="0666", SYMLINK+="picoprobe"

This will also symlink /dev/picoprobe and /dev/rp2040 to the respective vendor and product ids.

Apply the above rules with:

sudo udevadm control --reload-rules
sudo udevadm trigger

Compile:

pw build

Run:

Host

Run the host app and connect to it via pw console:

./out/gn/host_device_simulator.speed_optimized/obj/applications/badge/bin/badge & \
  pw console --socket-addr default ; \
  killall badge

Kudzu

export ELF=./out/gn/rp2040.size_optimized/obj/applications/badge/bin/badge.elf

picotool reboot -f -u && \
  sleep 3 && \
  picotool load -x $ELF

Connect with pw console:

pw console --verbose \
  --baudrate 115200 \
  --token-databases ./out/gn/rp2040.size_optimized/obj/applications/badge/bin/badge.elf \
  --device /dev/rp2040

From Python Repl window you can issue RPCs interactively:

>>> device.rpcs.kudzu.rpc.Kudzu.PackageTemp()
(Status.OK, kudzu.rpc.PackageTempResponse(temp=27.60657501220703))