From 81a36c59e5793a4cbb43fba684c9757fdfd5dc58 Mon Sep 17 00:00:00 2001 From: ragarnoy Date: Sat, 17 Feb 2024 00:47:18 +0100 Subject: [PATCH] Update radar logging and version retrieval, tweak 'xe125' example Changes include updated logging formatting in the hal.rs file, improved version retrieval and printing in radar.rs, and modification of version methods. For the 'xe125' example, removed probe-rs 'verify' flag and defmt log attribute from .cargo/config.toml, added new imported 'radar' structures in main.rs, and adjusted for new version retrieval method. The `__hardfp_sqrtf` function was also added to main.rs following the `__hardfp_roundf` function, providing the square root of the input float as a return. The same file also discards the optional 'chip-erase' flag and removes git-fetch-with-cli from the net environment in the .cargo/config.toml file. --- examples/xe125/.cargo/config.toml | 6 +----- examples/xe125/src/main.rs | 21 +++++++++++++++++---- src/hal.rs | 4 ++-- src/radar.rs | 20 +++++++++++++------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/examples/xe125/.cargo/config.toml b/examples/xe125/.cargo/config.toml index 0c25598..2cf1397 100644 --- a/examples/xe125/.cargo/config.toml +++ b/examples/xe125/.cargo/config.toml @@ -1,5 +1,5 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "probe-rs run --chip STM32L431CBYx --chip-erase --connect-under-reset --verify" +runner = "probe-rs run --chip STM32L431CBYx --connect-under-reset" [target.thumbv7em-none-eabihf] rustflags = [ @@ -13,7 +13,3 @@ target = "thumbv7em-none-eabihf" [env] DEFMT_LOG = "trace" - -[net] -git-fetch-with-cli = true - diff --git a/examples/xe125/src/main.rs b/examples/xe125/src/main.rs index 57ce45a..a710f3f 100644 --- a/examples/xe125/src/main.rs +++ b/examples/xe125/src/main.rs @@ -3,6 +3,8 @@ use core::cell::RefCell; +use a121_rs::radar; +use a121_rs::radar::Radar; use defmt::info; use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; @@ -15,7 +17,7 @@ use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embassy_time::{Delay, Duration, Timer}; use embedded_hal_bus::spi::ExclusiveDevice; -use a121_rs::radar::Radar; +use radar::rss_version; #[allow(unused_imports)] use {defmt_rtt as _, panic_probe as _}; @@ -56,11 +58,17 @@ async fn main(_spawner: Spawner) { enable.set_high(); Timer::after(Duration::from_millis(10)).await; - let radar = Radar::new(1, spi_mut_ref.get_mut(), interrupt).enable(); + info!("RSS Version: {}", rss_version()); + + let mut radar = Radar::new(1, spi_mut_ref.get_mut(), interrupt).enable(); info!("Radar enabled"); + let mut buffer = [0u8; 100]; + let mut calibration = radar.sensor.calibrate(&mut buffer).await.unwrap(); + radar + .sensor + .prepare(&radar.config, &mut calibration, &mut buffer) + .unwrap(); - let rss_version = radar.version(); - info!("RSS Version: {}", rss_version); loop { Timer::after(Duration::from_secs(1)).await; info!("Hello, radar!"); @@ -113,3 +121,8 @@ pub extern "C" fn __hardfp_sinf(f: f32) -> f32 { pub extern "C" fn __hardfp_roundf(f: f32) -> f32 { libm::roundf(f) } + +#[no_mangle] +pub extern "C" fn __hardfp_sqrtf(f: f32) -> f32 { + libm::sqrtf(f) +} diff --git a/src/hal.rs b/src/hal.rs index 2910b7c..af391d8 100644 --- a/src/hal.rs +++ b/src/hal.rs @@ -80,7 +80,7 @@ impl AccHalImpl { ) { let tmp_buf = unsafe { core::slice::from_raw_parts_mut(buffer, buffer_length) }; trace!( - "Transfer16 function called: buffer={:x} (size:{})", + "Transfer16 function called: buffer={:#X} (size:{})", tmp_buf, buffer_length ); @@ -90,7 +90,7 @@ impl AccHalImpl { let spi = binding.as_mut().unwrap_unchecked(); // Perform the SPI transfer spi.transfer_in_place(tmp_buf).unwrap_unchecked(); - trace!("Transfer16 function completed, buffer={:x}", tmp_buf); + trace!("Transfer16 function completed, buffer={:#X}", tmp_buf); }); } diff --git a/src/radar.rs b/src/radar.rs index b8ac39b..e7efdd8 100644 --- a/src/radar.rs +++ b/src/radar.rs @@ -22,11 +22,17 @@ where /// Radar Sensor Software Version /// 0xMMMMmmPP where M is major, m is minor and P is patch -#[derive(Debug, defmt::Format)] +#[derive(Debug)] pub struct RssVersion { version: u32, } +impl defmt::Format for RssVersion { + fn format(&self, f: defmt::Formatter) { + defmt::write!(f, "{}.{}.{}", self.major(), self.minor(), self.patch()) + } +} + impl Display for RssVersion { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}.{}.{}", self.major(), self.minor(), self.patch()) @@ -43,11 +49,11 @@ impl RssVersion { } pub fn minor(&self) -> u8 { - ((self.version & 0x0000FF00) >> 16) as u8 + ((self.version & 0x0000FF00) >> 8) as u8 } pub fn patch(&self) -> u8 { - ((self.version & 0x000000FF) >> 8) as u8 + (self.version & 0x000000FF) as u8 } } @@ -92,9 +98,9 @@ where pub fn id(&self) -> u32 { self.id } +} - pub fn version(&self) -> RssVersion { - let version = unsafe { acc_version_get_hex() }; - RssVersion::new(version) - } +pub fn rss_version() -> RssVersion { + let version = unsafe { acc_version_get_hex() }; + RssVersion::new(version) }