commit 92857fae5f9b4364ea377048239d603f2f19ba54
Author: Daniel P. <daniel@steew.eu>
Date: Sun Oct 26 00:43:54 2025 +0000
diff --git a/fw/RustFM/Cargo.toml b/fw/RustFM/Cargo.toml
index ffdc8fe..cc073b6 100644
--- a/fw/RustFM/Cargo.toml
+++ b/fw/RustFM/Cargo.toml
@@ -515 +516 @@ edition = "2021"
[dependencies]
embedded-hal = "0.2.7"
-nb = "1"
-cortex-m = {version = "0.7.7", features = ["critical-section-single-core"]}
+nb = "1.1.0"
+cortex-m = {git = "https://github.com/rust-embedded/cortex-m", features = ["critical-section-single-core"]}
critical-section = { version = "1.2.0" }
cortex-m-rt ="0.7.5"
panic-halt = "0.2.0"
panic-semihosting = "0.6.0"
cortex-m-semihosting = "0.5.0"
-mpu6050 = "0.1.6"
-embedded-hal-compat = "0.13.0"
+# mpu6050 = "0.1.6"
+mpu6050-dmp = "0.6.1"
+# embedded-hal-compat = "0.13.0"
rtic = {version = "2.2.0", features=["thumbv7-backend"]}
rtic-sync = "1.4.0"
# rtic-monotonics = {version = "2.1.0", features = ["stm32_tim3", "stm32l431rc"]}
diff --git a/fw/RustFM/src/main.rs b/fw/RustFM/src/main.rs
index 8cc2272..cff9f16 100644
--- a/fw/RustFM/src/main.rs
+++ b/fw/RustFM/src/main.rs
@@ -1123 +1159 @@ use cortex_m_rt::ExceptionFrame;
#[rtic::app(device = stm32l4xx_hal::pac, peripherals = true, dispatchers = [SAI1, ADC1_2, SPI1])]
mod app {
-
- use mpu6050::Mpu6050;
- use rtic_sync::{channel::{Receiver, Sender}, make_channel};
- use stm32l4xx_hal::{delay::Delay, flash::FlashExt, gpio::{Alternate, OpenDrain, Output, Pin, PushPull, PA6, PC14, PC15}, i2c::{self, I2c, SclPin, SdaPin}, pac::{dma1::ccr1::PL_A, I2C1, TIM7}, prelude::*, pwr::PwrExt, rcc::{ClockSecuritySystem, CrystalBypass, RccExt}, timer::{Event, Timer}};
+
+
- use critical_section::*;
-
+ use embedded_hal_compat::{ForwardCompat, ReverseCompat};
+ // use critical_section::*;
+ // use mpu6050::{device::CLKSEL, Mpu6050};
+ use mpu6050_dmp::{address::Address, sensor::Mpu6050};
+ use rtic_sync::{
+ channel::{Receiver, Sender},
+ make_channel,
+ };
+ use stm32l4xx_hal::{
+ delay::Delay,
+ flash::FlashExt,
+ gpio::{
+ Alternate, Input, OpenDrain, Output, PullDown, PushPull, PA10, PA12, PA6, PA9,
+ PC14, PC15,
+ },
+ i2c::{self, I2c},
+ pac::{I2C1, NVIC, TIM7},
+ prelude::*,
+ pwr::PwrExt,
+ rcc::{ClockSecuritySystem, CrystalBypass, RccExt},
+ stm32,
+ timer::{Event, Timer},
+ };
+
+ #[allow(non_camel_case_types)]
+ #[repr(u8)]
+ // MPU6050 registers
+ pub enum MpuRegs {
+ INT_PIN_CFG = 55,
+ INT_ENABLE = 56,
+ INT_STATUS = 58,
+ }
+
+ pub enum MpuFields {}
+
+ impl From<MpuRegs> for u8 {
+ fn from(r: MpuRegs) -> u8 {
+ r as u8
+ }
+ }
+
- GREEN
+ GREEN,
- SLOW = 1,
- MEDIUM = 3,
+ SLOW = 1, MEDIUM = 3,
@@ -387 +747 @@ mod app {
- TX
+ TX,
@@ -4834 +8438 @@ mod app {
-
- timer7: Timer<TIM7>, // led blink timer
- led_ok: PC14<Output<PushPull>>, // green led
- led_fail: PC15<Output<PushPull>>, // red led
- txpin: PA6<Output<PushPull>>, // outgoing transmit data
- // mpu: Mpu6050<I2c<I2C1, (Alternate<OpenDrain, 4>, Alternate<OpenDrain, 4>)>>
- mpu: Mpu6050<I2c<I2C1, (SclPin, SdaPin)>>
-
+ timer7: Timer<TIM7>, // led blink timer
+ led_ok: PC14<Output<PushPull>>, // green led
+ led_fail: PC15<Output<PushPull>>, // red led
+ txpin: PA6<Output<PushPull>>, // outgoing transmit data
+ imu_int: PA12<Input<PullDown>>,
+ mpu: Mpu6050<I2c<I2C1, (PA9<Alternate<OpenDrain, 4>>, PA10<Alternate<OpenDrain, 4>>)>>,
+ // mpu: Mpu6050<I2c>,
- let dp = c.device;
+ let mut dp = c.device;
- let clocks = rcc.cfgr
- .hse(12.MHz(), CrystalBypass::Disable, ClockSecuritySystem::Disable)
+ let clocks = rcc
+ .cfgr
+ .hse(
+ 12.MHz(),
+ CrystalBypass::Disable,
+ ClockSecuritySystem::Disable,
+ )
-
+
-
+
@@ -8737 +12776 @@ mod app {
-
+
- let scl = gpioa
- .pa9
- .into_alternate_open_drain::<4>(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
- let sda = gpioa
- .pa10
- .into_alternate_open_drain::<4>(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
-
- let iic = i2c::I2c::i2c1(dp.I2C1, (scl, sda), i2c::Config::new(400.kHz(), clocks), &mut rcc.apb1r1);
+ let scl = gpioa.pa9.into_alternate_open_drain::<4>(
+ &mut gpioa.moder,
+ &mut gpioa.otyper,
+ &mut gpioa.afrh,
+ );
+ let sda = gpioa.pa10.into_alternate_open_drain::<4>(
+ &mut gpioa.moder,
+ &mut gpioa.otyper,
+ &mut gpioa.afrh,
+ );
+
+ // Configure the external interrupt for MPU6050 data
+ let mut imu_int = gpioa
+ .pa12
+ .into_pull_down_input(&mut gpioa.moder, &mut gpioa.pupdr);
+ imu_int.make_interrupt_source(&mut dp.SYSCFG, &mut rcc.apb2);
+ imu_int.trigger_on_edge(&mut dp.EXTI, stm32l4xx_hal::gpio::Edge::Rising);
+ imu_int.enable_interrupt(&mut dp.EXTI);
+ unsafe {
+ NVIC::unmask(stm32::interrupt::EXTI15_10);
+ }
+
+ let iic = i2c::I2c::i2c1(
+ dp.I2C1,
+ (scl, sda),
+ i2c::Config::new(400.kHz(), clocks),
+ &mut rcc.apb1r1,
+ );
- mpu_slave_add_lsb.set_low();
- let mut mpu = Mpu6050::new(iic);
- let mut timer = Delay::new(c.core.SYST, clocks);
+ // mpu_slave_add_lsb.set_low();
+ // let mut mpu = Mpu6050::new(iic);
+ // let mut timer = Delay::new(c.core.SYST, clocks);
+
+ // let init_result = mpu.init(&mut timer);
+ // // Set the mpu clock source to the x axis gyroscope
+ // mpu.set_clock_source(CLKSEL::GXAXIS).unwrap();
+ // hprintln!("Initialized MPU peripheral: {:?}", init_result);
+
+ // // Enable clear interrupt on read operation
+ // mpu.write_bit(MpuRegs::INT_PIN_CFG.into(), 4, true).unwrap();
+ // // Enable interrupt on data ready
+ // mpu.write_bit(MpuRegs::INT_ENABLE.into(), 0, false).unwrap();
- let init_result = mpu.init(&mut timer);
- hprintln!("Initialized MPU peripheral: {:?}", init_result);
+ let mut mpu = Mpu6050::new(iic, Address::default()).unwrap();
- let status = SysStatus::FAIL;
- (Shared {status}, Local {timer7, led_ok, led_fail, txpin, mpu})
+ let status = SysStatus::FAIL;
+ (
+ Shared { status },
+ Local {
+ timer7,
+ led_ok,
+ led_fail,
+ txpin,
+ imu_int,
+ mpu,
+ },
+ )
- fn idle (_: idle::Context) -> ! {
+ fn idle(_: idle::Context) -> ! {
@@ -12714 +20625 @@ mod app {
- #[task(priority = 7, local = [mpu])]
- async fn mpu_read(c: mpu_read::Context) {
+ #[task(binds = EXTI15_10, priority = 7, local = [imu_int])]
+ fn mpu_read(c: mpu_read::Context) {
+ hprintln!("Read TEMP value: {:?}", c.local.mpu.get_temp().unwrap());
+
+ c.local.imu_int.clear_interrupt_pending_bit();
+ // Clear the interrupt after reading the INT status register
+ c.local
+ .mpu
+ .read_bits(MpuRegs::INT_STATUS.into(), 0, 0)
+ .unwrap();
-
+
- async fn transmitter(mut ctx: transmitter::Context, mut receiver: Receiver<'static, usize, CAPACITY>) {
+ async fn transmitter(
+ mut ctx: transmitter::Context,
+ mut receiver: Receiver<'static, usize, CAPACITY>,
+ ) {
@@ -14638 +23635 @@ mod app {
-
- fn status_leds (mut ctx: status_leds::Context) {
+ fn status_leds(mut ctx: status_leds::Context) {
- ctx.shared.status.lock(|status| {
- match status {
- SysStatus::IDLE => {
- led = LEDS::GREEN;
- speed = BlinkSpeed::SLOW;
- },
- SysStatus::FAIL => {
- led = LEDS::RED;
- speed = BlinkSpeed::HOLD;
- },
- SysStatus::BOOT => {
- led = LEDS::GREEN;
- speed = BlinkSpeed::MEDIUM;
- },
- SysStatus::TX => {
- led = LEDS::GREEN;
- speed = BlinkSpeed::FAST;
- },
-
- _ => {
- led = LEDS::RED;
- speed = BlinkSpeed::HOLD;
- }
+ ctx.shared.status.lock(|status| match status {
+ SysStatus::IDLE => {
+ led = LEDS::GREEN;
+ speed = BlinkSpeed::SLOW;
+ }
+ SysStatus::FAIL => {
+ led = LEDS::RED;
+ speed = BlinkSpeed::HOLD;
+ }
+ SysStatus::BOOT => {
+ led = LEDS::GREEN;
+ speed = BlinkSpeed::MEDIUM;
+ }
+ SysStatus::TX => {
+ led = LEDS::GREEN;
+ speed = BlinkSpeed::FAST;
+ }
+
+ _ => {
+ led = LEDS::RED;
+ speed = BlinkSpeed::HOLD;
@@ -1867 +2737 @@ mod app {
- },
+ }
@@ -1977 +2846 @@ mod app {
-
}
@@ -2469 +3329 @@ mod app {
// .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
// // mpu_slave_add_lsb.set_low();
-// let mut mpu = Mpu6050::new(iic);
+// let mut mpu = Mpu6050::new(iic);
// let init_result = mpu.init(&mut timer);
-
+
// loop {
// writeln!(hstdout,"r/p: {:?}", acc);