fixed properly
This commit is contained in:
23
flake.nix
23
flake.nix
@@ -6,6 +6,10 @@
|
|||||||
outputs = { self, nixpkgs }: let
|
outputs = { self, nixpkgs }: let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
rust = pkgs.rust-bin.stable.latest.default.override {
|
||||||
|
targets = [ "thumbv8m.main-none-eabihf" ];
|
||||||
|
extensions = [ "rust-src" "rustfmt" "clippy" ];
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
devShells.${system}.default = pkgs.mkShell {
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
@@ -34,25 +38,28 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
# Set up Rust target
|
echo ">>> STM32 DevShell"
|
||||||
rustup target add thumbv7em-none-eabihf 2>/dev/null || true
|
|
||||||
|
|
||||||
# Ensure probe-rs binary is in PATH
|
export PATH=${pkgs.rust-analyzer}/bin:$PATH
|
||||||
if ! command -v probe-rs >/dev/null; then
|
export PATH=$HOME/.cargo/bin:$PATH
|
||||||
echo "⚠️ probe-rs not found! (check nix installation)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
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 CARGO_TARGET_DIR=target
|
||||||
|
export DEFMT_LOG=info
|
||||||
export PATH=$PATH:${pkgs.gcc-arm-embedded}/bin
|
export PATH=$PATH:${pkgs.gcc-arm-embedded}/bin
|
||||||
|
export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/library"
|
||||||
|
|
||||||
rustc --version
|
rustc --version
|
||||||
arm-none-eabi-gcc --version | head -n1
|
arm-none-eabi-gcc --version | head -n1
|
||||||
echo "cargo build --release --target thumbv8m.main-none-eabihf"
|
echo "cargo build --release --target thumbv8m.main-none-eabihf"
|
||||||
echo "cargo flash --release --chip STM32U575ZI"
|
echo "cargo flash --release --chip STM32U575ZI"
|
||||||
echo "export DEFMT_LOG=info"
|
|
||||||
echo "cargo run --bin main"
|
echo "cargo run --bin main"
|
||||||
echo "probe-rs run --chip STM32U575ZITxQ target/thumbv8m.main-none-eabihf/release/main"
|
echo "probe-rs run --chip STM32U575ZITxQ target/thumbv8m.main-none-eabihf/release/main"
|
||||||
|
echo "target/**/build/embassy-stm32-*/out/_generated.rs"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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
|
|
||||||
5
hal_adc/rust-toolchain.toml
Normal file
5
hal_adc/rust-toolchain.toml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# rust-toolchain.toml
|
||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
|
components = ["rust-src", "rustfmt", "clippy"]
|
||||||
|
targets = ["thumbv8m.main-none-eabihf"]
|
||||||
@@ -23,6 +23,15 @@ async fn main(_spawner: embassy_executor::Spawner) {
|
|||||||
adc1.set_sample_time(adc::SampleTime::CYCLES160_5);
|
adc1.set_sample_time(adc::SampleTime::CYCLES160_5);
|
||||||
let max1 = adc::resolution_to_max_count(adc::Resolution::BITS14);
|
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 ****
|
// **** ADC4 init ****
|
||||||
let mut adc4 = adc4::Adc4::new(p.ADC4);
|
let mut adc4 = adc4::Adc4::new(p.ADC4);
|
||||||
let mut adc4_pin1 = p.PC1; // A4
|
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;
|
let volt: f32 = 3.3 * raw as f32 / max1 as f32;
|
||||||
info!("Read adc1 pin 2 {}", volt);
|
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 ****
|
// **** ADC4 blocking read ****
|
||||||
let raw: u16 = adc4.blocking_read(&mut adc4_pin1);
|
let raw: u16 = adc4.blocking_read(&mut adc4_pin1);
|
||||||
let volt: f32 = 3.3 * raw as f32 / max4 as f32;
|
let volt: f32 = 3.3 * raw as f32 / max4 as f32;
|
||||||
|
|||||||
Reference in New Issue
Block a user