From 5c272093917b4c2122ff3030ed304857c3c18b2c Mon Sep 17 00:00:00 2001 From: Carson Swoveland Date: Thu, 8 Feb 2024 11:08:55 -0500 Subject: [PATCH] Initial commit --- .cargo/config.toml | 4 ++-- .gitignore | 3 ++- Cargo.toml | 4 ++-- memory.x | 23 +++++++++++++++++++++++ src/bin/minimal.rs | 17 +++++++++++------ src/lib.rs | 2 +- 6 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 memory.x diff --git a/.cargo/config.toml b/.cargo/config.toml index da541f4..f3529af 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,6 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] # TODO(2) replace `$CHIP` with your chip's name (see `probe-rs chip list` output) -runner = "probe-rs run --chip $CHIP" +runner = "probe-rs run --chip STM32L412KBUx" rustflags = [ "-C", "linker=flip-link", "-C", "link-arg=-Tlink.x", @@ -17,7 +17,7 @@ rustflags = [ # target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ # target = "thumbv7m-none-eabi" # Cortex-M3 # target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) -# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) +target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) [alias] rb = "run --bin" diff --git a/.gitignore b/.gitignore index 869df07..ad2f0ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -Cargo.lock \ No newline at end of file +Cargo.lock +.DS_Store \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 67fa538..83ccbd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ defmt = { version = "0.3", features = ["encoding-rzcobs"] } defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] } panic-probe = { version = "0.3", features = ["print-defmt"] } # TODO(4) Select the correct rtic backend -rtic = { version = "2.0.0", features = [ "$RTIC_BACKEND" ] } +rtic = { version = "2.0.0", features = [ "thumbv7-backend" ] } # TODO(5) Add hal as dependency -some-hal = "1.2.3" +stm32l4xx-hal = { version = "0.7.1", features = ["stm32l442"] } # TODO add a monotonic if you use scheduling # rtic-monotonics = { version = "1.0.0", features = [ "cortex-m-systick" ]} diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..fdf940d --- /dev/null +++ b/memory.x @@ -0,0 +1,23 @@ +MEMORY +{ + /* NOTE K = KiBi = 1024 bytes */ + /* TODO Adjust these memory regions to match your device memory layout */ + FLASH : ORIGIN = 0x8000000, LENGTH = 128K + RAM : ORIGIN = 0x20000000, LENGTH = 32K +} + +/* This is where the call stack will be allocated. */ +/* The stack is of the full descending type. */ +/* You may want to use this variable to locate the call stack and static + variables in different memory regions. Below is shown the default value */ +/* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */ + +/* You can use this symbol to customize the location of the .text section */ +/* If omitted the .text section will be placed right after the .vector_table + section */ +/* This is required only on microcontrollers that store some configuration right + after the vector table */ +/* _stext = ORIGIN(FLASH) + 0x400; */ + +/* Size of the heap (in bytes) */ +/* _heap_size = 1024; */ diff --git a/src/bin/minimal.rs b/src/bin/minimal.rs index ca09ad5..372eef6 100644 --- a/src/bin/minimal.rs +++ b/src/bin/minimal.rs @@ -7,12 +7,16 @@ use test_app as _; // global logger + panicking-behavior + memory layout // TODO(7) Configure the `rtic::app` macro #[rtic::app( // TODO: Replace `some_hal::pac` with the path to the PAC - device = some_hal::pac, + device = stm32l4xx_hal::pac, // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used // You can usually find the names of the interrupt vectors in the some_hal::pac::interrupt enum. - dispatchers = [FreeInterrupt1, ...] + dispatchers = [EXTI0] )] mod app { + use stm32l4xx_hal as hal; + + use hal::{pac, prelude::*}; + // Shared resources go here #[shared] struct Shared { @@ -26,7 +30,9 @@ mod app { } #[init] - fn init(cx: init::Context) -> (Shared, Local) { + fn init(_cx: init::Context) -> (Shared, Local) { + let peripherals = pac::Peripherals::take(); + defmt::info!("init"); // TODO setup monotonic if used @@ -34,8 +40,7 @@ mod app { // let token = rtic_monotonics::create_systick_token!(); // rtic_monotonics::systick::Systick::new(cx.core.SYST, sysclk, token); - - task1::spawn().ok(); + blink_led::spawn().ok(); ( Shared { @@ -59,7 +64,7 @@ mod app { // TODO: Add tasks #[task(priority = 1)] - async fn task1(_cx: task1::Context) { + async fn blink_led(_cx: blink_led::Context) { defmt::info!("Hello from task1!"); } } diff --git a/src/lib.rs b/src/lib.rs index 3ac29a5..43db348 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ use defmt_brtt as _; // global logger use panic_probe as _; // TODO(6) Import your HAL -use some_hal as _; // memory layout +use stm32l4xx_hal as _; // memory layout // same panicking *behavior* as `panic-probe` but doesn't print a panic message // this prevents the panic message being printed *twice* when `defmt::panic` is invoked