From bd81c400bc9629615dcacb09abbe1a4e57e08d32 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Sat, 6 Apr 2024 04:15:09 +0100 Subject: [PATCH] Make runner command selectable (#74) --- cargo-generate.toml | 15 +++++++++++--- cargo-generate/config.toml | 36 +++++++++++++++++++++++++++++++++ cargo-generate/remove_rprs.rhai | 1 + 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 cargo-generate/config.toml diff --git a/cargo-generate.toml b/cargo-generate.toml index db18e4c..8a61ba3 100644 --- a/cargo-generate.toml +++ b/cargo-generate.toml @@ -2,6 +2,15 @@ cargo_generate_version = ">=0.9.0" [hooks] -pre = [ - "cargo-generate/remove_rprs.rhai" -] +pre = ["cargo-generate/remove_rprs.rhai"] + +[placeholders] +flash_method = { prompt = "Which flashing method do you intend to use?", choices = [ + "probe-rs", + "elf2uf2-rs", + "custom", + "none" +], default = "probe-rs", type = "string" } + +[conditional.'flash_method == "custom"'.placeholders] +flash_method_custom = { prompt = "Enter the runner command to use", type = "string" } diff --git a/cargo-generate/config.toml b/cargo-generate/config.toml new file mode 100644 index 0000000..8295a52 --- /dev/null +++ b/cargo-generate/config.toml @@ -0,0 +1,36 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# Choose a default "cargo run" tool (see README for more info) +# - `probe-rs` provides flashing and defmt via a hardware debugger, and stack unwind on panic +# - elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode +# runner = "probe-rs run --chip RP2040 --protocol swd" +# runner = "elf2uf2-rs -d" +{% case flash_method -%} + {%- when "probe-rs" -%} + runner = "probe-rs run --chip RP2040 --protocol swd" + {%- when "elf2uf2-rs" -%} + runner = "elf2uf2-rs -d" + {%- when "none" -%} + {%- else -%} + {%- if flash_method != "" -%} + runner = "{{ flash_method_custom }}" + {%- endif -%} +{%- endcase %} +rustflags = [ + "-C", "linker=flip-link", + "-C", "link-arg=--nmagic", + "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tdefmt.x", + + # Code-size optimizations. + # trap unreachable can save a lot of space, but requires nightly compiler. + # uncomment the next line if you wish to enable it + # "-Z", "trap-unreachable=no", + "-C", "inline-threshold=5", + "-C", "no-vectorize-loops", +] + +[build] +target = "thumbv6m-none-eabi" + +[env] +DEFMT_LOG = "debug" diff --git a/cargo-generate/remove_rprs.rhai b/cargo-generate/remove_rprs.rhai index fea7c2b..decd34c 100644 --- a/cargo-generate/remove_rprs.rhai +++ b/cargo-generate/remove_rprs.rhai @@ -3,4 +3,5 @@ file::delete("debug_probes.md"); file::delete("CODE_OF_CONDUCT.md"); file::delete("Cargo.toml"); file::rename("cargo-generate/Cargo.toml", "Cargo.toml"); +file::rename("cargo-generate/config.toml", ".cargo/config.toml"); file::delete("cargo-generate")