diff --git a/flake.nix b/flake.nix index 5c96c60..0078156 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,10 @@ outputs = { self, nixpkgs }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; + rust = pkgs.rust-bin.stable.latest.default.override { + targets = [ "thumbv8m.main-none-eabihf" ]; + extensions = [ "rust-src" "rustfmt" "clippy" ]; + }; in { devShells.${system}.default = pkgs.mkShell { packages = with pkgs; [ @@ -34,25 +38,28 @@ ]; shellHook = '' - # Set up Rust target - rustup target add thumbv7em-none-eabihf 2>/dev/null || true + echo ">>> STM32 DevShell" - # Ensure probe-rs binary is in PATH - if ! command -v probe-rs >/dev/null; then - echo "⚠️ probe-rs not found! (check nix installation)" - fi + export PATH=${pkgs.rust-analyzer}/bin:$PATH + export PATH=$HOME/.cargo/bin:$PATH - export RUST_TARGET=thumbv7em-none-eabihf + rustup default stable + rustup component add rust-src rustfmt clippy 2>/dev/null || true + rustup target add thumbv8m.main-none-eabihf 2>/dev/null || true + + export RUST_TARGET=thumbv8m.main-none-eabihf export CARGO_TARGET_DIR=target + export DEFMT_LOG=info export PATH=$PATH:${pkgs.gcc-arm-embedded}/bin + export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/library" rustc --version arm-none-eabi-gcc --version | head -n1 echo "cargo build --release --target thumbv8m.main-none-eabihf" echo "cargo flash --release --chip STM32U575ZI" - echo "export DEFMT_LOG=info" echo "cargo run --bin main" echo "probe-rs run --chip STM32U575ZITxQ target/thumbv8m.main-none-eabihf/release/main" + echo "target/**/build/embassy-stm32-*/out/_generated.rs" ''; }; }; diff --git a/hal_adc/openocd-u5.cfg b/hal_adc/openocd-u5.cfg deleted file mode 100644 index 5ac6db7..0000000 --- a/hal_adc/openocd-u5.cfg +++ /dev/null @@ -1,4 +0,0 @@ -source [find interface/stlink.cfg] -transport select hla_swd -source [find target/stm32u5x.cfg] -reset_config srst_only srst_nogate connect_assert_srst diff --git a/hal_adc/rust-toolchain.toml b/hal_adc/rust-toolchain.toml new file mode 100644 index 0000000..3ab7c52 --- /dev/null +++ b/hal_adc/rust-toolchain.toml @@ -0,0 +1,5 @@ +# rust-toolchain.toml +[toolchain] +channel = "stable" +components = ["rust-src", "rustfmt", "clippy"] +targets = ["thumbv8m.main-none-eabihf"] diff --git a/hal_adc/src/bin/main.rs b/hal_adc/src/bin/main.rs index 2a4c3c9..0f0aad2 100644 --- a/hal_adc/src/bin/main.rs +++ b/hal_adc/src/bin/main.rs @@ -23,6 +23,15 @@ async fn main(_spawner: embassy_executor::Spawner) { adc1.set_sample_time(adc::SampleTime::CYCLES160_5); let max1 = adc::resolution_to_max_count(adc::Resolution::BITS14); + // **** ADC2 init **** + let mut adc2 = adc::Adc::new(p.ADC2); + let mut adc2_pin1 = p.PC3; // A2 + let mut adc2_pin2 = p.PB0; // A3 + adc2.set_resolution(adc::Resolution::BITS14); + adc2.set_averaging(adc::Averaging::Samples1024); + adc2.set_sample_time(adc::SampleTime::CYCLES160_5); + let max2 = adc::resolution_to_max_count(adc::Resolution::BITS14); + // **** ADC4 init **** let mut adc4 = adc4::Adc4::new(p.ADC4); let mut adc4_pin1 = p.PC1; // A4 @@ -41,6 +50,15 @@ async fn main(_spawner: embassy_executor::Spawner) { let volt: f32 = 3.3 * raw as f32 / max1 as f32; info!("Read adc1 pin 2 {}", volt); + // **** ADC2 blocking read **** + let raw: u16 = adc2.blocking_read(&mut adc2_pin1); + let volt: f32 = 3.3 * raw as f32 / max2 as f32; + info!("Read adc2 pin 1 {}", volt); + + let raw: u16 = adc2.blocking_read(&mut adc2_pin2); + let volt: f32 = 3.3 * raw as f32 / max2 as f32; + info!("Read adc2 pin 2 {}", volt); + // **** ADC4 blocking read **** let raw: u16 = adc4.blocking_read(&mut adc4_pin1); let volt: f32 = 3.3 * raw as f32 / max4 as f32;