From f74e59ddad85f573a5f5919b652e083260f1a375 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sun, 23 Oct 2022 14:44:11 +0200 Subject: [PATCH] Testing embedded environment --- rust/pico/.vscode/tasks.json | 23 ++++++++++ rust/pico/Cargo.toml | 2 +- rust/pico/Embed.toml | 82 ++++++++++++++++++++++++++++++++++++ rust/pico/src/main.rs | 9 +++- 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 rust/pico/.vscode/tasks.json create mode 100644 rust/pico/Embed.toml diff --git a/rust/pico/.vscode/tasks.json b/rust/pico/.vscode/tasks.json new file mode 100644 index 0000000..07196d4 --- /dev/null +++ b/rust/pico/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cargo", + "command": "build", + "problemMatcher": [ + "$rustc" + ], + "group": "build", + "label": "rust: cargo build" + }, + { + "type": "cargo", + "command": "run", + "problemMatcher": [ + "$rustc" + ], + "group": "build", + "label": "rust: cargo run" + } + ] +} \ No newline at end of file diff --git a/rust/pico/Cargo.toml b/rust/pico/Cargo.toml index fdf2e44..ae5d049 100644 --- a/rust/pico/Cargo.toml +++ b/rust/pico/Cargo.toml @@ -14,7 +14,7 @@ defmt-rtt = "0.3" panic-probe = { version = "0.3", features = ["print-defmt"] } # We're using a Pico by default on this template -rp-pico = "0.4" +rp-pico = "0.5" # but you can use any BSP. Uncomment this to use the pro_micro_rp2040 BSP instead # sparkfun-pro-micro-rp2040 = "0.3" diff --git a/rust/pico/Embed.toml b/rust/pico/Embed.toml new file mode 100644 index 0000000..9365af2 --- /dev/null +++ b/rust/pico/Embed.toml @@ -0,0 +1,82 @@ +[default.probe] +# USB vendor ID +# usb_vid = "1337" +# USB product ID +# usb_pid = "1337" +# Serial number +# serial = "12345678" +# The protocol to be used for communicating with the target. +protocol = "Swd" +# The speed in kHz of the data link to the target. +speed = 20000 + +[default.flashing] +# Whether or not the target should be flashed. +enabled = true +# Whether or not the target should be halted after reset. +# DEPRECATED, moved to reset section +halt_afterwards = false +# Whether or not bytes erased but not rewritten with data from the ELF +# should be restored with their contents before erasing. +restore_unwritten_bytes = false +# The path where an SVG of the assembled flash layout should be written to. +# flash_layout_output_path = "out.svg" +# Triggers a full chip erase instead of a page by page erase. +do_chip_erase = false + +[default.reset] +# Whether or not the target should be reset. +# When flashing is enabled as well, the target will be reset after flashing. +enabled = true +# Whether or not the target should be halted after reset. +halt_afterwards = false + +[default.general] +# The chip name of the chip to be debugged. +chip = "RP2040" +# A list of chip descriptions to be loaded during runtime. +chip_descriptions = [] +# The default log level to be used. Possible values are one of: +# "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" +log_level = "WARN" +# Use this flag to assert the nreset & ntrst pins during attaching the probe to the chip. +connect_under_reset = false + +[default.rtt] +# Whether or not an RTTUI should be opened after flashing. +enabled = true +# How the target handles RTT outputs that won't fit in the buffer. This can be +# overridden per-channel. If left unset, the firmware will determine the default +# for each RTT up channel. +# NoBlockSkip - Skip writing the data completely if it doesn't fit in its +# entirety. +# NoBlockTrim - Write as much as possible of the data and ignore the rest. +# BlockIfFull - Spin until the host reads data. Can result in app freezing. +# +up_mode = "NoBlockSkip" + +# A list of channel associations to be displayed. If left empty, all channels are displayed. +# up, down (Optional) - RTT channel numbers +# name (Optional) - String to be displayed in the RTTUI tab +# up_mode (Optional) - RTT channel specific as described above +# format (Required) - How to interpret data from target firmware. One of: +# String - Directly show output from the target +# Defmt - Format output on the host, see https://defmt.ferrous-systems.com/ +# BinaryLE - Display as raw hex +channels = [ + { up = 0, down = 0, name = "name", up_mode = "NoBlockSkip", format = "Defmt" }, +] +# The duration in ms for which the logger should retry to attach to RTT. +timeout = 3000 +# Whether timestamps in the RTTUI are enabled +show_timestamps = true +# Whether to save rtt history buffer on exit. +log_enabled = false +# Where to save rtt history buffer relative to manifest path. +log_path = "./logs" + +[default.gdb] +# Whether or not a GDB server should be opened after flashing. +enabled = false +# The connection string in host:port format wher the GDB server will open a socket. +gdb_connection_string = "127.0.0.1:1337" \ No newline at end of file diff --git a/rust/pico/src/main.rs b/rust/pico/src/main.rs index ff36fc0..36c242b 100644 --- a/rust/pico/src/main.rs +++ b/rust/pico/src/main.rs @@ -26,10 +26,10 @@ use bsp::hal::{ #[entry] fn main() -> ! { info!("Program start"); + let mut pac = pac::Peripherals::take().unwrap(); let core = pac::CorePeripherals::take().unwrap(); let mut watchdog = Watchdog::new(pac.WATCHDOG); - let sio = Sio::new(pac.SIO); // External high-speed crystal on the pico board is 12Mhz let external_xtal_freq_hz = 12_000_000u32; @@ -45,7 +45,9 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); + + let sio = Sio::new(pac.SIO); let pins = bsp::Pins::new( pac.IO_BANK0, @@ -59,9 +61,12 @@ fn main() -> ! { loop { info!("on!"); led_pin.set_high().unwrap(); + delay.delay_ms(200); + info!("off!"); led_pin.set_low().unwrap(); + delay.delay_ms(200); } }