2 Commits

Author SHA1 Message Date
Priec
a3344efcde fixed properly 2025-10-21 11:28:07 +02:00
Priec
4f486eaead printing in a loop 2025-10-21 09:08:53 +02:00
5 changed files with 46 additions and 14 deletions

View File

@@ -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"
'';
};
};

View File

@@ -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

View File

@@ -0,0 +1,5 @@
# rust-toolchain.toml
[toolchain]
channel = "stable"
components = ["rust-src", "rustfmt", "clippy"]
targets = ["thumbv8m.main-none-eabihf"]

View File

@@ -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;

View File

@@ -7,6 +7,7 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::rng::Rng;
use embassy_stm32::{bind_interrupts, peripherals, rng};
use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@@ -22,6 +23,11 @@ async fn main(_spawner: Spawner) {
let mut rng = Rng::new(p.RNG, Irqs);
let mut buf = [0u8; 16];
unwrap!(rng.async_fill_bytes(&mut buf).await);
info!("random bytes: {:02x}", buf);
loop {
unwrap!(rng.async_fill_bytes(&mut buf).await);
info!("random bytes: {:02x}", buf);
Timer::after(Duration::from_secs(1)).await;
}
}