Skip to content

Commit

Permalink
fix: More clean up
Browse files Browse the repository at this point in the history
config.toml:
 * Use build-* rather than bld-*
 * Add a "custom" command example `rrr-blinky`

README.md:
 * Show "all" examples are created if `--bin` is not specified
 * Show the size differential between development and release profiles
 * Describe aliases at the end of Getting Started using build-riscv,
   run-riscv and rrr-blinky
  • Loading branch information
winksaville committed Oct 29, 2024
1 parent c61b023 commit ab44340
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 60 deletions.
10 changes: 5 additions & 5 deletions rp235x-hal-examples/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
[alias]

# Build arm or riscv
bld-arm = "build --target=thumbv8m.main-none-eabihf"
bld-riscv = "build --target=riscv32imac-unknown-none-elf"
build-arm = "build --target=thumbv8m.main-none-eabihf"
build-riscv = "build --target=riscv32imac-unknown-none-elf"

# Run arm or riscv
run-arm = "run --target=thumbv8m.main-none-eabihf"
run-riscv = "run --target=riscv32imac-unknown-none-elf"

# Run release for arm or riscv, add other cumstom aliases as desired.
rra = "run-arm --release"
rrr = "run-riscv --release"
# Add other custom aliases here, `rrr-blinky` which
# runs in release mode a riscv version of blinky.
rrr-blinky = "run-riscv --release --bin=blinky"

[build]
# Set the default target to match the Cortex-M33 in the RP2350
Expand Down
152 changes: 97 additions & 55 deletions rp235x-hal-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ $ cargo build --bin blinky
Finished `dev` profile [unoptimized + debuginfo] target(s) in 14.97s
```

This builds the default target, which is the for the ARM at `./target/thumbv8m.main-none-eabihf/debug/blinky`:
This builds the default target, which is the for the ARM and the elf file
is located at `./target/thumbv8m.main-none-eabihf/debug/blinky`:
```console
$ file ./target/thumbv8m.main-none-eabihf/debug/blinky
./target/thumbv8m.main-none-eabihf/debug/blinky: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
```

If you want to build the RISC-V you can specify the target directly to override the default:
If you want to build the RISC-V you specify the target directly to override the default:
```console
$ cargo build --target=riscv32imac-unknown-none-elf --bin blinky
Compiling nb v1.1.0
Expand All @@ -108,7 +109,7 @@ $ cargo build --target=riscv32imac-unknown-none-elf --bin blinky
Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.23s```
```

And we can see that a RISC-V elf file is now present at `./target/riscv32imac-unknown-none-elf/debug/blinky`:
And we see that the RISC-V elf file is now present at `./target/riscv32imac-unknown-none-elf/debug/blinky`:
```console
$ file ./target/riscv32imac-unknown-none-elf/debug/blinky
./target/riscv32imac-unknown-none-elf/debug/blinky: ELF 32-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
Expand All @@ -117,61 +118,89 @@ $ file ./target/riscv32imac-unknown-none-elf/debug/blinky
You can also specify the ARM target directly by using
`--target thumbv8m.main-none-eabihf` instead of `--target riscv32imac-unknown-none-elf`.

You can also easily build, flash and start the application on the RP235x
by using the `cargo run` with one of the following commands:
To build, flash and start the application on the RP235x
you use `cargo run` with one of the following commands:
```console
$ cargo run --target thumbv8m.main-none-eabihf --bin blinky
$ cargo run --target riscv32imac-unknown-none-elf --bin blinky
```

You can also specify a release build by passing `--release` to the `cargo build`
For a release build pass `--release` to the `cargo build`
or `cargo run` commands. This will build the example with optimizations enabled:
```console
$ cargo run --target thumbv8m.main-none-eabihf --release --bin blinky
$ cargo run --target riscv32imac-unknown-none-elf --release --bin blinky
```

The above work well but the commands are somewhat verbose. To make building and running
commands more succinct an `[alias]` section is added to [.cargo/config.toml](../.cargo/config.toml)
that define:
| Command Alias | Description |
|-----------|-------------|
| bld-arm | build for ARM |
| bld-riscv | build for RISC-V |
| run-arm | run on ARM |
| run-riscv | run on RISC-V |
| rra | run release ARM |
| rrr | run release RISC-V |
For the ARM target all of the examples are built if no `--bin` is specified:
```console
$ cargo clean
Removed 1488 files, 398.6MiB total
$ cargo build --target thumbv8m.main-none-eabihf
Compiling proc-macro2 v1.0.89
Compiling unicode-ident v1.0.13
..
Compiling rp235x-hal v0.2.0
Compiling pio-proc v0.2.2
Finished `dev` profile [unoptimized + debuginfo] target(s) in 16.08s
$ find target/thumbv8m.main-none-eabihf/debug/ -maxdepth 1 -type f -executable | sort
target/thumbv8m.main-none-eabihf/debug/adc
target/thumbv8m.main-none-eabihf/debug/adc_fifo_dma
..
target/thumbv8m.main-none-eabihf/debug/blinky
..
target/thumbv8m.main-none-eabihf/debug/vector_table
target/thumbv8m.main-none-eabihf/debug/watchdog
```

When using these aliases your build/run commands are much shorter.
Lets run the blinky example again, using `cargo rra` for running
on ARM in release mode and `cargo rrr` for running on RISC-V in release mode:
For the RISC-V it is currently possible to build only *some* of the examples. See
[`riscv_examples.txt`](./riscv_examples.txt) for a list of known working examples.
The missing ones probably rely on interrupts, or some other thing we
haven't ported to work in RISC-V mode yet.

Here is an example using the `blinky` example in RISC-V mode. We'll build and
run it first in non-release emulating the developement cycle **Note:** be sure
the pico 2 is in BOOTSEL mode before the `run` command:
```console
$ cargo rra --bin blinky
$ cargo rrr --bin blinky
$ cargo build --bin blinky --target=riscv32imac-unknown-none-elf
Compiling rp235x-hal-examples v0.1.0
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s
$ cargo run --bin blinky --target=riscv32imac-unknown-none-elf
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
Running `picotool load -u -v -x -t elf target/riscv32imac-unknown-none-elf/debug/blinky`
Family id 'rp2350-riscv' can be downloaded in absolute space:
00000000->02000000
Loading into Flash: [==============================] 100%
Verifying Flash: [==============================] 100%
OK

The device was rebooted to start the application.
```

These are exactly the same as:
At this point the development version is running on the RP2350 and the LED is blinking.
When we look at `blinky` using `file` we see we have an RISC-V ELF file and using `ls`
we see it is quite large, 2.4M:
```console
$ cargo run --target thumbv8m.main-none-eabihf --release --bin blinky
$ cargo run --target riscv32imac-unknown-none-elf --release --bin blinky
$ file ./target/riscv32imac-unknown-none-elf/debug/blinky
./target/riscv32imac-unknown-none-elf/debug/blinky: ELF 32-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
$ ls -l ./target/riscv32imac-unknown-none-elf/debug/blinky
-rwxr-xr-x 2 wink users 2432556 Oct 29 12:59 ./target/riscv32imac-unknown-none-elf/debug/blinky
$ ls -lh ./target/riscv32imac-unknown-none-elf/debug/blinky
-rwxr-xr-x 2 wink users 2.4M Oct 29 12:59 ./target/riscv32imac-unknown-none-elf/debug/blinky
```

Here is the output of running the `blinky` example in release mode on ARM
after cleaning the build **Note:** have the pico 2 in BOOTSEL mode before
running this command:
Next we'll build and run it in release mode for "final" testing,
again be sure the pico 2 is in BOOTSEL mode:
```console
$ cargo clean
Removed 3565 files, 1.4GiB total
$ cargo rra --bin blinky
$ cargo run --bin blinky --target=riscv32imac-unknown-none-elf --release
Compiling proc-macro2 v1.0.89
Compiling unicode-ident v1.0.13
..
Compiling rp235x-hal v0.2.0
Compiling pio-parser v0.2.2
Compiling pio-proc v0.2.2
Finished `release` profile [optimized] target(s) in 11.72s
Running `picotool load -u -v -x -t elf target/thumbv8m.main-none-eabihf/release/blinky`
Family id 'rp2350-arm-s' can be downloaded in absolute space:
Finished `release` profile [optimized] target(s) in 17.05s
Running `picotool load -u -v -x -t elf target/riscv32imac-unknown-none-elf/release/blinky`
Family id 'rp2350-riscv' can be downloaded in absolute space:
00000000->02000000
Loading into Flash: [==============================] 100%
Verifying Flash: [==============================] 100%
Expand All @@ -180,14 +209,35 @@ Verifying Flash: [==============================] 100%
The device was rebooted to start the application.
```

And you can build first and then run, in this case the `blinky` example was already built:
The LED should be blinking and looking at `blinky` we see
it is now much smaller at 87K:
```console
$ cargo bra --bin blinky
Finished `release` profile [optimized] target(s) in 0.05s
$ cargo rra --bin blinky
Finished `release` profile [optimized] target(s) in 0.05s
Running `picotool load -u -v -x -t elf target/thumbv8m.main-none-eabihf/release/blinky`
Family id 'rp2350-arm-s' can be downloaded in absolute space:
$ file ./target/riscv32imac-unknown-none-elf/release/blinky
./target/riscv32imac-unknown-none-elf/release/blinky: ELF 32-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, not stripped
$ ls -lh ./target/riscv32imac-unknown-none-elf/release/blinky
-rwxr-xr-x 2 wink users 87K Oct 29 12:55 ./target/riscv32imac-unknown-none-elf/release/blinky
```

The above commands work well, but the commands are somewhat verbose.
To make building and running commands more succinct an `[alias]` section
has been added to [.cargo/config.toml](../.cargo/config.toml) that define:
| Command Alias | Description |
|---|---|
| build-arm | build for ARM |
| build-riscv | build for RISC-V |
| run-arm | run on ARM |
| run-riscv | run on RISC-V |
| rrr-blinky | run release on RISC-V blinky |

When using these aliases your build and run commands are much shorter.
Below we see the development cycle using `build-riscv` and `run-riscv`:
```console
$ cargo build-riscv --bin blinky
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
$ cargo run-riscv --bin blinky
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
Running `picotool load -u -v -x -t elf target/riscv32imac-unknown-none-elf/debug/blinky`
Family id 'rp2350-riscv' can be downloaded in absolute space:
00000000->02000000
Loading into Flash: [==============================] 100%
Verifying Flash: [==============================] 100%
Expand All @@ -196,20 +246,12 @@ Verifying Flash: [==============================] 100%
The device was rebooted to start the application.
```

It is currently possible to build *some* of the examples in RISC-V mode. See
[`riscv_examples.txt`](./riscv_examples.txt) for a list of the examples known to
work. The missing ones probably rely on interrupts, or some other thing we
haven't ported to work in RISC-V mode yet.

Here is an example using the `blinky` example in RISC-V mode:
And for the `run` command in `--release` mode for the RISC-V we added the `rrr-blinky` alias
as an example of customization. You might want to add others as you see fit:
```console
cargo build --bin blinky --target=riscv32imac-unknown-none-elf
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
$ file ./target/riscv32imac-unknown-none-elf/debug/blinky
./target/riscv32imac-unknown-none-elf/debug/blinky: ELF 32-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
$ cargo run --bin blinky --target=riscv32imac-unknown-none-elf
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
Running `picotool load -u -v -x -t elf target/riscv32imac-unknown-none-elf/debug/blinky`
$ cargo rrr-blinky
Finished `release` profile [optimized] target(s) in 0.05s
Running `picotool load -u -v -x -t elf target/riscv32imac-unknown-none-elf/release/blinky`
Family id 'rp2350-riscv' can be downloaded in absolute space:
00000000->02000000
Loading into Flash: [==============================] 100%
Expand Down

0 comments on commit ab44340

Please sign in to comment.