From 75f626ef02798989eaf67250c4097abca6d75691 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Tue, 31 Jan 2023 09:59:52 +0100 Subject: [PATCH] Initial commit --- .cargo/config.toml | 29 +++++++++++++++ .gitignore | 2 ++ .vscode/settings.json | 8 +++++ Cargo.toml | 13 +++++++ Embed.toml | 82 +++++++++++++++++++++++++++++++++++++++++++ memory.x | 15 ++++++++ rust-toolchain.toml | 4 +++ src/main.rs | 67 +++++++++++++++++++++++++++++++++++ 8 files changed, 220 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 Cargo.toml create mode 100644 Embed.toml create mode 100644 memory.x create mode 100644 rust-toolchain.toml create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..1acd241 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,29 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# Choose a default "cargo run" tool: +# - probe-run provides flashing and defmt via a hardware debugger +# - cargo embed offers flashing, rtt, defmt and a gdb server via a hardware debugger +# it is configured via the Embed.toml in the root of this project +# - elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode +# runner = "probe-run --chip RP2040" +# runner = "cargo embed" +runner = "elf2uf2-rs -d" + +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" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..869df07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9c5d0dc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "workbench.colorCustomizations": { + "activityBar.background": "#0B341F", + "titleBar.activeBackground": "#10492C", + "titleBar.activeForeground": "#F2FCF7" + }, + "rust-analyzer.check.allTargets": false, +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b25cbd0 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "mouse_hid" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cortex-m = "0.7.2" +cortex-m-rt = "0.7.2" +rp-pico = "0.6.0" +panic-halt = "0.2.0" +defmt = "0.3.0" \ No newline at end of file diff --git a/Embed.toml b/Embed.toml new file mode 100644 index 0000000..9365af2 --- /dev/null +++ b/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/memory.x b/memory.x new file mode 100644 index 0000000..070eac7 --- /dev/null +++ b/memory.x @@ -0,0 +1,15 @@ +MEMORY { + BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} + +EXTERN(BOOT2_FIRMWARE) + +SECTIONS { + /* ### Boot loader */ + .boot2 ORIGIN(BOOT2) : + { + KEEP(*(.boot2)); + } > BOOT2 +} INSERT BEFORE .text; \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..43a6a39 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = ["rustfmt"] +targets = ["thumbv6m-none-eabi"] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..54383b0 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,67 @@ +#![no_std] +#![no_main] + +// Ensure we halt the program on panic (if we don't mention this crate it won't +// be linked) +use panic_halt as _; + +// Pull in any important traits +use rp_pico::{ + entry, + hal::{self, pac, prelude::*}, +}; + +/// Entry point to our bare-metal application. +/// +/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function +/// as soon as all global variables are initialised. +/// +/// The function configures the RP2040 peripherals, then blinks the LED in an +/// infinite loop. +#[entry] +fn main() -> ! { + // Grab our singleton objects + let mut pac = pac::Peripherals::take().unwrap(); + let core = pac::CorePeripherals::take().unwrap(); + + // Set up the watchdog driver - needed by the clock setup code + let mut watchdog = hal::Watchdog::new(pac.WATCHDOG); + + // Configure the clocks + // + // The default is to generate a 125 MHz system clock + let clocks = hal::clocks::init_clocks_and_plls( + rp_pico::XOSC_CRYSTAL_FREQ, + pac.XOSC, + pac.CLOCKS, + pac.PLL_SYS, + pac.PLL_USB, + &mut pac.RESETS, + &mut watchdog, + ) + .ok() + .unwrap(); + + // The delay object lets us wait for specified amounts of time (in + // milliseconds) + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); + + // The single-cycle I/O block controls our GPIO pins + let sio = hal::Sio::new(pac.SIO); + + // Set the pins up according to their function on this particular board + let pins = rp_pico::Pins::new( + pac.IO_BANK0, + pac.PADS_BANK0, + sio.gpio_bank0, + &mut pac.RESETS, + ); + + // Set the LED to be an output + let mut led_pin = pins.led.into_push_pull_output(); + + // Blink the LED at 1 Hz + loop {} +} + +// End of file