From 7554d41e008fe1f738cf3bc6cfdbdd5fe371f896 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Fri, 25 Oct 2024 21:07:17 -0700 Subject: [PATCH 1/8] feat: Make it easier to specify target architecture Create aliases build-arm run-arm build-riscv and run-riscv in .cargo/config.toml. With these defined you can now use the alias which will be converted to the full target name: cargo build-arm -> cargo build --target thumbv8m.main-none-eabihf cargo run-arm -> cargo run --target thumbv8m.main-none-eabihf cargo build-riscv -> cargo build --target riscv32imac-unknown-none-elf cargo run-risv -> cargo run --target riscv32imac-unknown-none-elf Append --release parameter to do release builds and runs. For example: cargo run-riscv --release -> cargo run --target riscv32imac-unknown-none-elf --release feat: Make it easier to specify target architecture Create aliases build-arm run-arm build-riscv and run-riscv in .cargo/config.toml. With these defined you can now use the alias which will be converted to the full target name: cargo build-arm --bin blinky -> cargo build --bin blinky --target=thumbv8m.main-none-eabihf cargo run-arm --bin blinky -> cargo run --bin blinky --target=thumbv8m.main-none-eabihf cargo build-riscv --bin blinky -> cargo build --bin blinky --target=riscv32imac-unknown-none-elf cargo run-risv --bin blinky -> cargo run --bin blinky --target=riscv32imac-unknown-none-elf Append --release parameter to do release builds and runs. For example: cargo run-risv --bin blinky --release -> cargo run --bin blinky --target=thumbv8m.main-none-eabihf --release --- rp235x-hal-examples/.cargo/config.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rp235x-hal-examples/.cargo/config.toml b/rp235x-hal-examples/.cargo/config.toml index 1f5f243d7..8d161223e 100644 --- a/rp235x-hal-examples/.cargo/config.toml +++ b/rp235x-hal-examples/.cargo/config.toml @@ -5,6 +5,13 @@ # writing programs for Raspberry Silicon microcontrollers. # +# Add aliases for building and running for the ARM and RISC-V targets. +[alias] +build-arm = "build --target=thumbv8m.main-none-eabihf" +run-arm = "run --target=thumbv8m.main-none-eabihf" +build-riscv = "build --target=riscv32imac-unknown-none-elf" +run-riscv = "run --target=riscv32imac-unknown-none-elf" + [build] # Set the default target to match the Cortex-M33 in the RP2350 target = "thumbv8m.main-none-eabihf" From 91552901849792143400e9fc167a0255574250d1 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Mon, 28 Oct 2024 15:14:45 -0700 Subject: [PATCH 2/8] feat: Document the aliases in README.me Also, tweak the aliases and add dev and release modes with shorter names. --- rp235x-hal-examples/.cargo/config.toml | 24 +++- rp235x-hal-examples/README.md | 160 +++++++++++++++++++++---- 2 files changed, 158 insertions(+), 26 deletions(-) diff --git a/rp235x-hal-examples/.cargo/config.toml b/rp235x-hal-examples/.cargo/config.toml index 8d161223e..a9af1a3ea 100644 --- a/rp235x-hal-examples/.cargo/config.toml +++ b/rp235x-hal-examples/.cargo/config.toml @@ -7,11 +7,31 @@ # Add aliases for building and running for the ARM and RISC-V targets. [alias] -build-arm = "build --target=thumbv8m.main-none-eabihf" + +# Build arm or riscv using defaults or other options +bld-arm = "build --target=thumbv8m.main-none-eabihf" +bld-riscv = "build --target=riscv32imac-unknown-none-elf" + +# Run arm or riscv using defaults or other options run-arm = "run --target=thumbv8m.main-none-eabihf" -build-riscv = "build --target=riscv32imac-unknown-none-elf" run-riscv = "run --target=riscv32imac-unknown-none-elf" +# Build dev and release for arm +bda = "bld-arm" +bra = "bld-arm --release" + +# Build dev and release for risc-v +bdr = "bld-riscv" +brr = "bld-riscv --release" + +# Run dev and release for arm +rda = "run-arm" +rra = "run-arm --release" + +# Run dev and release for risc-v +rdr = "run-riscv" +rrr = "run-riscv --release" + [build] # Set the default target to match the Cortex-M33 in the RP2350 target = "thumbv8m.main-none-eabihf" diff --git a/rp235x-hal-examples/README.md b/rp235x-hal-examples/README.md index 6395e2c4c..c3840a788 100644 --- a/rp235x-hal-examples/README.md +++ b/rp235x-hal-examples/README.md @@ -56,43 +56,156 @@ https://github.com/rp-rs/rp-hal-boards/ for more details. ## Getting Started -To build all the examples, first grab a copy of the source code: +To build the examples, first grab a copy of the source code: ```console $ git clone https://github.com/rp-rs/rp-hal.git ``` -Then use `rustup` to grab the Rust Standard Library for the appropriate targets. There are two targets because the RP2350 has both an Arm mode and a RISC-V mode. +Then use `rustup` to grab the Rust Standard Library for the appropriate targets. the RP2350 +has two possible targets, thumbv8m.main-none-eabihf for the ARM cpu. And riscv32imac-unknown-none-elf +for the RISC-V cpu. ```console $ rustup target add thumbv8m.main-none-eabihf $ rustup target add riscv32imac-unknown-none-elf ``` -To build all the examples for Arm mode, run: +**Note: all examples assume the current directory is /rp235x-hal-examples.** +``` +cd rp235x-hal-examples +``` +The most basic method is to use `cargo build` with the `--bin` flag to specify the example you want to +build. For example, to build the `blinky` example: ```console -$ cargo build --target=thumbv8m.main-none-eabihf - Compiling rp235x-hal-examples v0.1.0 (/home/user/rp-hal/rp235x-hal-examples) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.53s $ cargo build --bin blinky - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s + Compiling proc-macro2 v1.0.89 + Compiling unicode-ident v1.0.13 + Compiling syn v1.0.109 +... + Compiling pio-parser v0.2.2 + Compiling rp235x-hal v0.2.0 (/home/wink/prgs/rpi-pico/myrepos/rp-hal-clone/rp235x-hal) + Compiling pio-proc v0.2.2 + 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`: +```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 ``` -You can also 'run' an example, which thanks to our supplied -[`.cargo/config.toml`](./.cargo/config.toml) will invoke Raspberry Pi's -`picotool` to copy it to an RP235x in USB Bootloader mode. You should install -that if you don't have it already, from -. +If you want to build the RISC-V you can specify the target directly to override the default: +```console +$ cargo build --target=riscv32imac-unknown-none-elf --bin blinky + Compiling nb v1.1.0 + Compiling byteorder v1.5.0 + Compiling stable_deref_trait v1.2.0 +.. + Compiling futures v0.3.31 + Compiling frunk v0.4.3 + Compiling rp235x-hal v0.2.0 (/home/wink/prgs/rpi-pico/myrepos/rp-hal-clone/rp235x-hal) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.23s``` +``` + +And we see the RISC-V 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 +``` + +You can also specify the ARM target directly just pass +`--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` using command: +```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` +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 +more succinct we have added some aliases in .carog/config.toml: + +```toml +# Add aliases for building and running for the ARM and RISC-V targets. +[alias] + +# Build arm or riscv using defaults or other options +bld-arm = "build --target=thumbv8m.main-none-eabihf" +bld-riscv = "build --target=riscv32imac-unknown-none-elf" + +# Run arm or riscv using defaults or other options +run-arm = "run --target=thumbv8m.main-none-eabihf" +run-riscv = "run --target=riscv32imac-unknown-none-elf" + +# Build dev and release profiles for arm +bda = "bld-arm" +bra = "bld-arm --release" + +# Build dev and release for profiles risc-v +bdr = "bld-riscv" +brr = "bld-riscv --release" + +# Run dev and release for profiles arm +rda = "run-arm" +rra = "run-arm --release" + +# Run dev and release for profiles risc-v +rdr = "run-riscv" +rrr = "run-riscv --release" +``` + +Using the aliases the commands are much shorter the first is for +running on ARM in rlease mode and the second is for running on RISC-V in release mode: +```console +$ cargo rra --bin blinky +$ cargo rrr --bin blinky +``` + +These are exactly the same as: +```console +$ cargo run --target thumbv8m.main-none-eabihf --release --bin blinky +$ cargo run --target riscv32imac-unknown-none-elf --release --bin blinky +``` +Here is the output of running in release mode the `blinky` example on ARM +after cleaning the build **Note:** have the pico 2 in BOOTSEL mode: ```console -$ cargo run --bin blinky --target=thumbv8m.main-none-eabihf - Compiling rp235x-hal v0.10.0 (/home/user/rp-hal/rp235x-hal) - Compiling rp235x-hal-examples v0.1.0 (/home/user/rp-hal/rp235x-hal-examples) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.62s - Running `picotool load -u -v -x -t elf target/thumbv8m.main-none-eabihf/debug/blinky` +$ cargo clean + Removed 3565 files, 1.4GiB total +$ cargo rra --bin blinky + Compiling proc-macro2 v1.0.89 + Compiling unicode-ident v1.0.13 +.. + Compiling rp235x-hal v0.2.0 (/home/wink/prgs/rpi-pico/myrepos/rp-hal/rp235x-hal) + 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: + 00000000->02000000 +Loading into Flash: [==============================] 100% +Verifying Flash: [==============================] 100% + OK + +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: +```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: 00000000->02000000 Loading into Flash: [==============================] 100% @@ -107,14 +220,13 @@ It is currently possible to build *some* of the examples in RISC-V mode. See 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: ```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 brr --bin blinky + Finished `release` profile [optimized] target(s) in 0.06s +$ cargo rrr --bin blinky + Finished `release` profile [optimized] target(s) in 0.06s + 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% From c61b023670c7dd3a07feeb0328e44a98cb9d83a2 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Tue, 29 Oct 2024 08:47:06 -0700 Subject: [PATCH 3/8] fix: Adding reviewers suggestions --- rp235x-hal-examples/.cargo/config.toml | 18 +----- rp235x-hal-examples/README.md | 83 ++++++++++---------------- 2 files changed, 36 insertions(+), 65 deletions(-) diff --git a/rp235x-hal-examples/.cargo/config.toml b/rp235x-hal-examples/.cargo/config.toml index a9af1a3ea..526b42218 100644 --- a/rp235x-hal-examples/.cargo/config.toml +++ b/rp235x-hal-examples/.cargo/config.toml @@ -8,28 +8,16 @@ # Add aliases for building and running for the ARM and RISC-V targets. [alias] -# Build arm or riscv using defaults or other options +# Build arm or riscv bld-arm = "build --target=thumbv8m.main-none-eabihf" bld-riscv = "build --target=riscv32imac-unknown-none-elf" -# Run arm or riscv using defaults or other options +# Run arm or riscv run-arm = "run --target=thumbv8m.main-none-eabihf" run-riscv = "run --target=riscv32imac-unknown-none-elf" -# Build dev and release for arm -bda = "bld-arm" -bra = "bld-arm --release" - -# Build dev and release for risc-v -bdr = "bld-riscv" -brr = "bld-riscv --release" - -# Run dev and release for arm -rda = "run-arm" +# Run release for arm or riscv, add other cumstom aliases as desired. rra = "run-arm --release" - -# Run dev and release for risc-v -rdr = "run-riscv" rrr = "run-riscv --release" [build] diff --git a/rp235x-hal-examples/README.md b/rp235x-hal-examples/README.md index c3840a788..a03f6b6ff 100644 --- a/rp235x-hal-examples/README.md +++ b/rp235x-hal-examples/README.md @@ -62,10 +62,9 @@ To build the examples, first grab a copy of the source code: $ git clone https://github.com/rp-rs/rp-hal.git ``` -Then use `rustup` to grab the Rust Standard Library for the appropriate targets. the RP2350 -has two possible targets, thumbv8m.main-none-eabihf for the ARM cpu. And riscv32imac-unknown-none-elf -for the RISC-V cpu. - +Then use `rustup` to grab the Rust Standard Library for the appropriate targets. +RP2350 has two possible targets: thumbv8m.main-none-eabihf for the ARM cpu, and +riscv32imac-unknown-none-elf for the RISC-V cpu. ```console $ rustup target add thumbv8m.main-none-eabihf $ rustup target add riscv32imac-unknown-none-elf @@ -85,7 +84,7 @@ $ cargo build --bin blinky Compiling syn v1.0.109 ... Compiling pio-parser v0.2.2 - Compiling rp235x-hal v0.2.0 (/home/wink/prgs/rpi-pico/myrepos/rp-hal-clone/rp235x-hal) + Compiling rp235x-hal v0.2.0 Compiling pio-proc v0.2.2 Finished `dev` profile [unoptimized + debuginfo] target(s) in 14.97s ``` @@ -105,21 +104,21 @@ $ cargo build --target=riscv32imac-unknown-none-elf --bin blinky .. Compiling futures v0.3.31 Compiling frunk v0.4.3 - Compiling rp235x-hal v0.2.0 (/home/wink/prgs/rpi-pico/myrepos/rp-hal-clone/rp235x-hal) + Compiling rp235x-hal v0.2.0 Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.23s``` ``` -And we see the RISC-V at `./target/riscv32imac-unknown-none-elf/debug/blinky`: +And we can see that a 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 ``` -You can also specify the ARM target directly just pass +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` using command: +by using the `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 @@ -133,39 +132,20 @@ $ 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 -more succinct we have added some aliases in .carog/config.toml: - -```toml -# Add aliases for building and running for the ARM and RISC-V targets. -[alias] - -# Build arm or riscv using defaults or other options -bld-arm = "build --target=thumbv8m.main-none-eabihf" -bld-riscv = "build --target=riscv32imac-unknown-none-elf" - -# Run arm or riscv using defaults or other options -run-arm = "run --target=thumbv8m.main-none-eabihf" -run-riscv = "run --target=riscv32imac-unknown-none-elf" - -# Build dev and release profiles for arm -bda = "bld-arm" -bra = "bld-arm --release" - -# Build dev and release for profiles risc-v -bdr = "bld-riscv" -brr = "bld-riscv --release" - -# Run dev and release for profiles arm -rda = "run-arm" -rra = "run-arm --release" - -# Run dev and release for profiles risc-v -rdr = "run-riscv" -rrr = "run-riscv --release" -``` - -Using the aliases the commands are much shorter the first is for -running on ARM in rlease mode and the second is for running on RISC-V in release mode: +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 | + +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: ```console $ cargo rra --bin blinky $ cargo rrr --bin blinky @@ -177,8 +157,9 @@ $ cargo run --target thumbv8m.main-none-eabihf --release --bin blinky $ cargo run --target riscv32imac-unknown-none-elf --release --bin blinky ``` -Here is the output of running in release mode the `blinky` example on ARM -after cleaning the build **Note:** have the pico 2 in BOOTSEL mode: +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: ```console $ cargo clean Removed 3565 files, 1.4GiB total @@ -186,7 +167,7 @@ $ cargo rra --bin blinky Compiling proc-macro2 v1.0.89 Compiling unicode-ident v1.0.13 .. - Compiling rp235x-hal v0.2.0 (/home/wink/prgs/rpi-pico/myrepos/rp-hal/rp235x-hal) + Compiling rp235x-hal v0.2.0 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` @@ -222,11 +203,13 @@ haven't ported to work in RISC-V mode yet. Here is an example using the `blinky` example in RISC-V mode: ```console -$ cargo brr --bin blinky - Finished `release` profile [optimized] target(s) in 0.06s -$ cargo rrr --bin blinky - Finished `release` profile [optimized] target(s) in 0.06s - Running `picotool load -u -v -x -t elf target/riscv32imac-unknown-none-elf/release/blinky` +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` Family id 'rp2350-riscv' can be downloaded in absolute space: 00000000->02000000 Loading into Flash: [==============================] 100% From ab443408a8a7111c60ea285f939979a4d6f60a98 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Tue, 29 Oct 2024 15:34:31 -0700 Subject: [PATCH 4/8] fix: More clean up 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 --- rp235x-hal-examples/.cargo/config.toml | 10 +- rp235x-hal-examples/README.md | 152 ++++++++++++++++--------- 2 files changed, 102 insertions(+), 60 deletions(-) diff --git a/rp235x-hal-examples/.cargo/config.toml b/rp235x-hal-examples/.cargo/config.toml index 526b42218..25535aa09 100644 --- a/rp235x-hal-examples/.cargo/config.toml +++ b/rp235x-hal-examples/.cargo/config.toml @@ -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 diff --git a/rp235x-hal-examples/README.md b/rp235x-hal-examples/README.md index a03f6b6ff..687ffc406 100644 --- a/rp235x-hal-examples/README.md +++ b/rp235x-hal-examples/README.md @@ -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 @@ -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 @@ -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% @@ -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% @@ -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% From 416cdc7dc3c17de34ec0828ef6882d238d2b929a Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Wed, 30 Oct 2024 11:03:38 -0700 Subject: [PATCH 5/8] fix: Apply review suggestions from theJPster See: https://github.com/rp-rs/rp-hal/pull/869#pullrequestreview-2404012664 --- rp235x-hal-examples/README.md | 52 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/rp235x-hal-examples/README.md b/rp235x-hal-examples/README.md index 687ffc406..9fc8bbb50 100644 --- a/rp235x-hal-examples/README.md +++ b/rp235x-hal-examples/README.md @@ -63,20 +63,22 @@ $ git clone https://github.com/rp-rs/rp-hal.git ``` Then use `rustup` to grab the Rust Standard Library for the appropriate targets. -RP2350 has two possible targets: thumbv8m.main-none-eabihf for the ARM cpu, and -riscv32imac-unknown-none-elf for the RISC-V cpu. +RP2350 has two possible targets: `thumbv8m.main-none-eabihf` for the Arm mode, and +`riscv32imac-unknown-none-elf` for the RISC-V mode. + ```console $ rustup target add thumbv8m.main-none-eabihf $ rustup target add riscv32imac-unknown-none-elf ``` -**Note: all examples assume the current directory is /rp235x-hal-examples.** +**Note: all examples assume the current directory is `/rp235x-hal-examples`.** ``` cd rp235x-hal-examples ``` The most basic method is to use `cargo build` with the `--bin` flag to specify the example you want to build. For example, to build the `blinky` example: + ```console $ cargo build --bin blinky Compiling proc-macro2 v1.0.89 @@ -89,14 +91,16 @@ $ 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 and the elf file +This builds the default target, which is Arm mode 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 specify the target directly to override the default: +If you want to build the RISC-V mode you specify the target directly to override the default: + ```console $ cargo build --target=riscv32imac-unknown-none-elf --bin blinky Compiling nb v1.1.0 @@ -109,30 +113,34 @@ $ cargo build --target=riscv32imac-unknown-none-elf --bin blinky Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.23s``` ``` -And we see that the RISC-V elf file is now present at `./target/riscv32imac-unknown-none-elf/debug/blinky`: +And we see that the RISC-V mode 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 ``` -You can also specify the ARM target directly by using +You can also specify the Arm mode target directly by using `--target thumbv8m.main-none-eabihf` instead of `--target riscv32imac-unknown-none-elf`. 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 ``` -For a release build pass `--release` to the `cargo build` +For the release profile 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 ``` -For the ARM target all of the examples are built if no `--bin` is specified: +For the Arm mode target all of the examples are built if no `--bin` is specified: + ```console $ cargo clean Removed 1488 files, 398.6MiB total @@ -153,14 +161,15 @@ target/thumbv8m.main-none-eabihf/debug/vector_table target/thumbv8m.main-none-eabihf/debug/watchdog ``` -For the RISC-V it is currently possible to build only *some* of the examples. See +For the RISC-V mode 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 +run it first using the default dev profile, emulating the development cycle **Note:** be sure the pico 2 is in BOOTSEL mode before the `run` command: + ```console $ cargo build --bin blinky --target=riscv32imac-unknown-none-elf Compiling rp235x-hal-examples v0.1.0 @@ -178,19 +187,16 @@ The device was rebooted to start the application. ``` 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: +When we look at `blinky` using `file` we see we have generated a RISC-V mode ELF file: + ```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 -$ 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 ``` -Next we'll build and run it in release mode for "final" testing, +Next we'll build and run it using the release profile for "final" testing, again be sure the pico 2 is in BOOTSEL mode: + ```console $ cargo run --bin blinky --target=riscv32imac-unknown-none-elf --release Compiling proc-macro2 v1.0.89 @@ -209,13 +215,11 @@ Verifying Flash: [==============================] 100% The device was rebooted to start the application. ``` -The LED should be blinking and looking at `blinky` we see -it is now much smaller at 87K: +The LED should be blinking and looking at `blinky` + ```console $ 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. @@ -231,6 +235,7 @@ has been added to [.cargo/config.toml](../.cargo/config.toml) that define: 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 @@ -246,8 +251,9 @@ Verifying Flash: [==============================] 100% The device was rebooted to start the application. ``` -And for the `run` command in `--release` mode for the RISC-V we added the `rrr-blinky` alias +And for the `run` command in `--release` profile and a RISC-V mode we added the `rrr-blinky` alias as an example of customization. You might want to add others as you see fit: + ```console $ cargo rrr-blinky Finished `release` profile [optimized] target(s) in 0.05s From 033e5aa5ad1a4e9e14cc6c3d732072f90615f5c6 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Wed, 30 Oct 2024 19:20:55 +0000 Subject: [PATCH 6/8] Update rp235x-hal-examples/README.md --- rp235x-hal-examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rp235x-hal-examples/README.md b/rp235x-hal-examples/README.md index 9fc8bbb50..1e4c5b54d 100644 --- a/rp235x-hal-examples/README.md +++ b/rp235x-hal-examples/README.md @@ -99,7 +99,7 @@ $ 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 mode you specify the target directly to override the default: +If you want to build a binary that runs in RISC-V mode, then you must specify the RISC-V target to override the default: ```console $ cargo build --target=riscv32imac-unknown-none-elf --bin blinky From 7fc0d6a26ddb2de1cbeac58df90f2071a23ad0d3 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Wed, 30 Oct 2024 19:21:19 +0000 Subject: [PATCH 7/8] Apply suggestions from code review --- rp235x-hal-examples/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rp235x-hal-examples/README.md b/rp235x-hal-examples/README.md index 1e4c5b54d..a753ceea1 100644 --- a/rp235x-hal-examples/README.md +++ b/rp235x-hal-examples/README.md @@ -124,7 +124,7 @@ You can also specify the Arm mode target directly by using `--target thumbv8m.main-none-eabihf` instead of `--target riscv32imac-unknown-none-elf`. To build, flash and start the application on the RP235x -you use `cargo run` with one of the following commands: +you use `cargo run` with one of the following commands. Note: be sure the RP235x is in BOOTSEL mode before using the `run` command because we use `picotool` to flash and run the binary: ```console $ cargo run --target thumbv8m.main-none-eabihf --bin blinky @@ -168,7 +168,7 @@ 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 using the default dev profile, emulating the development cycle **Note:** be sure -the pico 2 is in BOOTSEL mode before the `run` command: +the RP235x is in BOOTSEL mode before using the `run` command because we use `picotool` to flash and run the binary: ```console $ cargo build --bin blinky --target=riscv32imac-unknown-none-elf @@ -195,7 +195,7 @@ $ file ./target/riscv32imac-unknown-none-elf/debug/blinky ``` Next we'll build and run it using the release profile for "final" testing, -again be sure the pico 2 is in BOOTSEL mode: +again be sure the RP235x is in BOOTSEL mode: ```console $ cargo run --bin blinky --target=riscv32imac-unknown-none-elf --release From 8ebc0ab5825948280a62832292ff04264f1abe78 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Wed, 30 Oct 2024 19:22:23 +0000 Subject: [PATCH 8/8] Update rp235x-hal-examples/README.md --- rp235x-hal-examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rp235x-hal-examples/README.md b/rp235x-hal-examples/README.md index a753ceea1..8cbef2b67 100644 --- a/rp235x-hal-examples/README.md +++ b/rp235x-hal-examples/README.md @@ -215,7 +215,7 @@ Verifying Flash: [==============================] 100% The device was rebooted to start the application. ``` -The LED should be blinking and looking at `blinky` +The LED should be blinking as we are now running this binary: ```console $ file ./target/riscv32imac-unknown-none-elf/release/blinky