There is a lot to learn, so let’s start simple.
-
Connect the board to your computer and access the first project:
cd exercises/hello_world -
Build, flash, and monitor the project with
cargo run. You should see:.. 0x4080082e - handle_interrupts at ??:?? .. Commands: CTRL+R Reset chip CTRL+C Exit .. loop..! ..We will talk about the
at ??:??in the next chapter aboutpanic!.The
loop..!logs come from esp-println. They provide us withdbg!,print!andprintln!.
Build, flash and monitor?
The .cargo/config.toml includes this config:
[target.riscv32imac-unknown-none-elf] # our processor arch.
runner = "espflash flash --monitor" # for `cargo run`.
Our cargo run is replaced by cargo build && espflash flash <elf_path> --monitor.
Note
This builds and flashes the binary. Then monitors for any logs. Without the
--monitorit flashes and exits instead of waiting and printing logs.
Exercise
esp-println supports backends log and defmt which provide info!, warn! other macros. Let’s try adding them:
- Uncomment the lines in
src/main.rsand inCargo.tomlto enablelog. - The
logcrate logging level is controlled withESP_LOGunder the[env]section in.cargo/config.toml.-
Change the
ESP_LOGvariable to turnoffall logs. Re-runcargo run --release, to test how it works. -
Try with other levels, for example, with
trace.
-
The exercises/hello_world/examples/hello_world.rs contains a solution.
You can run it with the following command cargo run --release --example hello_world. You should first fix the lines at the bottom of Cargo.toml.
Suggested Reading
- esp-println
- log this one you can just peek at to have a general idea.