7. August 2023

How to extract Rust function signatures from .rs file using sed – one-liner

To extract function signatures from .rs file you can use following one-liner with sed:

sed -n -e '/pub fn/,/)/p' file.rs

Sample output:

  pub fn chip(&self) -> Chip {
    pub fn device_info(&mut self) -> Result<DeviceInfo, Error> {
        let chip = self.chip();
    pub fn load_elf_to_ram(
        &mut self,
        elf_data: &[u8],
        mut progress: Option<&mut dyn ProgressCallbacks>,
    ) -> Result<(), Error> {

17. April 2023

Matter: chip-tool pairing ble-wifi failing with Abort trap: 6 on macOS

chip-tool can be used for commissioning ESP32 with Matter.

macOS users may face the following error with iTerm:

chip-tool interactive start

pairing ble-wifi 0x7283 SSID PASS PIN 3840
..[FP] Validating NOC chain
..[FP] NOC chain validation successful
..[FP] Added new fabric at index: 0x1
...
Abort trap: 6

It’s necessary to grant access to Bluetooth to apps launched from iTerm.

Click System SettingsPrivacy & Security. Select Bluetooth. Click +, Select Applications, and find iTerm.

Close and open iTerm. The problem with “trap 6” should be gone.

Just do not forget to install Bluetooth Central Matter Client Developer mode profile. Otherwise the provisioning will fail with UUID problem.

3. May 2022

Podman Debian apt-get update fails with “InRelease is not valid yet”

Podman 4.0.3 users on macOS might face the following strange error when building an image:

apt-get update
...
E: Release file for http://security.debian.org/debian-security/dists/bullseye-security/InRelease is not valid yet (invalid for another 3h 1min 9s). Updates for this repository will not be applied.
E: Release file for http://deb.debian.org/debian/dists/bullseye-updates/InRelease is not valid yet (invalid for another 7h 24min 41s). Updates for this repository will not be applied.

The problem is caused by the not synced clock in Podman VM. This might happen due to the hibernation of the notebook.

The quick fix of the problem is to restart Podman’s VM:

podman machine stop
podman machine start

1. April 2022

How to develop for ESP32-C3 with Rust on macOS with Lima using Dev Container in VS Code

Lima is a solution for macOS for managing Linux VM on macOS which plays well with Dev Containers. It has several advantages over Docker Desktop for macOS or Podman.

Let’s see how it can be used for the development of software for embedded hardware like ESP32-C3 using source code from Ferrous Systems training:

git clone https://github.com/ferrous-systems/espressif-trainings.git

Install Lima and Docker-CLI:

brew install lima docker

Create Linux VM with Dockerd (following instructions from Kevin O’Brien – Utilizing Docker CLI without Docker Desktop):

curl https://raw.githubusercontent.com/lima-vm/lima/master/examples/docker.yaml -O
limactl start ./docker.yaml
limactl shell docker
sudo systemctl enable ssh.service

There is one important tweak in the Lima configuration. It’s necessary to enable write operation otherwise, the workspace mounted from VS Code is read-only. Open file ~/.lima/docker/lima.yaml and add writable flag to desired folder:

mounts:
- location: "~"
  writable: true

Restart Lima to apply changes.

limactl stop docker
limactl start docker

Create context for Docker-CLI to connect to dockerd running in the VM:

docker context create lima --docker "host=unix://${HOME}/.lima/docker/sock/docker.sock"
docker context use lima

Open VS Code with the installed Remote Container plugin and click Re-Open in Container:

cd espressif-trainings
code .

Open terminal in VS Code and build the example:

cd intro/hardware-check
cp cfg.toml.example cfg.toml
cargo build

Flashing of the resulting file could be done by espflash and mounting the device to Lima or using a tool like Adafruit WebSerial ESPTool. The file for flashing is located in the directory target/release.

31. March 2022

How to develop for ESP32-C3 with Rust on macOS with Podman using Dev Container in VS Code

Development in Dev Containers using VS Code greatly simplifies bootstrapping of the development environment. The developer does not need to install toolchains locally and spends a lot of time composing the development environment.

The default installation of VS Code is configured to work with Docker. It requires some small additional steps to switch to Podman.

Let’s begin with development using examples from Ferrous Systems training:

git clone https://github.com/ferrous-systems/espressif-trainings.git

Install Podman and check version:

brew install podman
podman --version

The version should be at least 4.0. If you have a previous version, consider an upgrade.

Following step might not be obvious to Docker users. Docker creates VM for managing containers in the background without asking the user. In the case of Podman, this is more versatile and you can define what kind of machine do you want to create. Here are a few options recommended for development, when you omit them you’ll get smaller defaults.

podman machine init --disk-size 20 --cpus 8 -m 4096 -v ${HOME}/espressif-trainings:${HOME}/espressif-trainings
podman machine start

Please, notice also -v option which mounts the development directory to Podman VM, without this mount you’ll get:

Error: statfs espressif-trainings: no such file or directory

Now the Podman VM should be ready and we can spin up containers. Go to the project directory and open Visual Studio Code:

cd ${HOME}/espressif-trainings
code .

It’s necessary to install one additional dependency for Podman: podman-compose

pip3 install podman-compose

It’s necessary to tell VS Code to use podman instead of docker commands. Go into Settings and search for keyword docker. Replace docker by podman and docker-compose by podman-compose.

VS Code is ready and click Reopen in Container.

Pulling the base image might take a while.

Open terminal and build the first ESP32-C3 example:

cd intro/hardware-check
cp cfg.toml.example cfg.toml
cargo build

Note: If VS Code is complaining about existing vscode volume, it’s possible to remove it by command

podman volume rm vscode

Note 2: If the remove is blocked by the existing terminated container, it’s possible to clean the reference by command

podman container prune

Flashing of the resulting file could be done by espflash and mounting device to Podman or using the tool like Adafruit WebSerial ESPTool. The file for flashing is located in the directory target/release.