Thumbnail

steew/gilgamesh.git

Clone URL: https://git.buni.party/steew/gilgamesh.git

commit 46dcede5e2ea61bfed8e2576476c19c423479606 Author: Daniel P. <daniel@steew.eu> Date: Wed Oct 29 22:38:09 2025 +0000 feat: working transmission diff --git a/fw/RustFM/.cargo/config b/fw/RustFM/.cargo/config deleted file mode 100644 index 70caeff..0000000 --- a/fw/RustFM/.cargo/config +++ /dev/null @@ -132 +00 @@ -#[target.thumbv7m-none-eabi] -# uncomment this to make `cargo run` execute programs on QEMU -# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" - -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# uncomment ONE of these three option to make `cargo run` start a GDB session -# which option to pick depends on your system -# runner = "arm-none-eabi-gdb -q -x openocd.gdb" -# runner = "gdb-multiarch -q -x openocd.gdb" -# runner = "gdb -q -x openocd.gdb" -runner = "probe-rs run --chip STM32L431RCTx" - -rustflags = [ - # LLD (shipped with the Rust toolchain) is used as the default linker - "-C", "link-arg=-Tlink.x", - - # if you run into problems with LLD switch to the GNU linker by commenting out - # this line - # "-C", "linker=arm-none-eabi-ld", - - # if you need to link to pre-compiled C libraries provided by a C toolchain - # use GCC as the linker by commenting out both lines above and then - # uncommenting the three lines below - # "-C", "linker=arm-none-eabi-gcc", - # "-C", "link-arg=-Wl,-Tlink.x", - # "-C", "link-arg=-nostartfiles", -] - -[build] -# Pick ONE of these compilation targets -# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) -target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) \ No newline at end of file diff --git a/fw/RustFM/Cargo.toml b/fw/RustFM/Cargo.toml index 5ea3526..bda5274 100644 --- a/fw/RustFM/Cargo.toml +++ b/fw/RustFM/Cargo.toml @@ -177 +177 @@ mpu6050-dmp = "0.3.0"  # 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"]} +rtic-monotonics = {version = "2.1.0", features = ["stm32_tim2", "stm32l431rc"]}    [dependencies.stm32l4xx-hal]  version = "0.7.1" diff --git a/fw/RustFM/memory.x b/fw/RustFM/memory.x index 33e05f4..3ec49df 100644 --- a/fw/RustFM/memory.x +++ b/fw/RustFM/memory.x @@ -27 +28 @@ MEMORY  {   /* NOTE K = KiBi = 1024 bytes */   /* TODO Adjust these memory regions to match your device memory layout */ - FLASH : ORIGIN = 0x08000000, LENGTH = 256K + /* FLASH : ORIGIN = 0x08000000, LENGTH = 256K */ + FLASH : ORIGIN = 0x08000000, LENGTH = 256K   RAM : ORIGIN = 0x20000000, LENGTH = 64K  }   diff --git a/fw/RustFM/rustfmt.toml b/fw/RustFM/rustfmt.toml new file mode 100644 index 0000000..c51666e --- /dev/null +++ b/fw/RustFM/rustfmt.toml @@ -00 +1 @@ +edition = "2018" \ No newline at end of file diff --git a/fw/RustFM/src/main.rs b/fw/RustFM/src/main.rs index 041b412..5c50a94 100644 --- a/fw/RustFM/src/main.rs +++ b/fw/RustFM/src/main.rs @@ -322 +321 @@    use panic_halt as _;  extern crate cortex_m; -#[macro_use] +// #[macro_use]  extern crate cortex_m_rt as rt;  extern crate cortex_m_semihosting as sh;   -use cortex_m_rt::ExceptionFrame; -  #[rtic::app(device = stm32l4xx_hal::pac, peripherals = true, dispatchers = [SAI1, ADC1_2, SPI1])]  mod app {   - - use core::any::Any; use cortex_m_semihosting::hprintln; // use embedded_hal_compat::{ForwardCompat, ReverseCompat}; // use critical_section::*; // use mpu6050::{device::CLKSEL, Mpu6050}; use mpu6050_dmp::{address::Address, sensor::Mpu6050}; + use rtic_monotonics::{stm32::prelude::*, stm32_tim2_monotonic}; + stm32_tim2_monotonic!(Mono, 100); + use rtic_sync::{ channel::{Receiver, Sender}, make_channel, @@ -278 +268 @@ mod app { delay::Delay, flash::FlashExt, gpio::{ - Alternate, Input, OpenDrain, Output, PullDown, PushPull, PA10, PA12, PA6, PA9, - PC14, PC15, + Alternate, Input, OpenDrain, Output, PullDown, PushPull, PA10, PA12, PA6, PA9, PC14, + PC15, }, i2c::{self, I2c}, pac::{I2C1, NVIC, TIM7}, @@ -647 +638 @@ mod app { // Led blink speeds in Hz #[derive(Copy, Clone)] pub enum BlinkSpeed { - SLOW = 1, MEDIUM = 3, + SLOW = 1, + MEDIUM = 3, FAST = 5, HOLD = 0, } @@ -908 +907 @@ mod app { 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>, + mpu: Mpu6050<I2c<I2C1, (PA9<Alternate<OpenDrain, 4>>, PA10<Alternate<OpenDrain, 4>>)>>, // mpu: Mpu6050<I2c>, }   const CAPACITY: usize = 1; @@ -11915 +11827 @@ mod app {   let mut gpioc = dp.GPIOC.split(&mut rcc.ahb2); let mut gpioa = dp.GPIOA.split(&mut rcc.ahb2); + let mut gpiob = dp.GPIOB.split(&mut rcc.ahb2); + let led_ok = gpioc .pc14 .into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper); let led_fail = gpioc .pc15 .into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper); - let txpin = gpioa + let mut txpin = gpioa .pa6 .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper); + let mut rxen = gpiob + .pb0 + .into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper); + let mut txen = gpiob + .pb1 + .into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper); + + // setup for transmission + rxen.set_high(); + txen.set_low();   // initialize i2c peripheral let scl = gpioa.pa9.into_alternate_open_drain::<4>( @@ -1629 +17316 @@ mod app { .pa11 .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper); // Force low the address of the I2C IMU peripheral - // mpu_slave_add_lsb.set_low(); + mpu_slave_add_lsb.set_low(); // let mut mpu = Mpu6050::new(iic); - let mut timer = Delay::new(c.core.SYST, clocks); + let mut delay = Delay::new(c.core.SYST, clocks); + + // init sequence for max7044 + txpin.set_low(); + delay.delay_ms(1_u32); + txpin.set_high(); + delay.delay_ms(1_u32); + txpin.set_low();   // let init_result = mpu.init(&mut timer); // // Set the mpu clock source to the x axis gyroscope @@ -17716 +19521 @@ mod app { // mpu.write_bit(MpuRegs::INT_ENABLE.into(), 0, false).unwrap();   let mut mpu = Mpu6050::new(iic, Address::default()).unwrap(); - mpu.initialize_dmp(&mut timer).unwrap(); + mpu.initialize_dmp(&mut delay).unwrap(); mpu.enable_dmp().unwrap(); mpu.boot_firmware().unwrap(); + mpu.set_clock_source(mpu6050_dmp::clock_source::ClockSource::Xgyro) + .unwrap(); + + Mono::start(12_000_000);   // mpu.disable_dmp - + + #[allow(unused_variables)] let (send, receive) = make_channel!(usize, CAPACITY); transmitter::spawn(receive).unwrap(); - sender1::spawn(send).unwrap(); - + // sender1::spawn(send).unwrap(); + let status = SysStatus::FAIL; ( Shared { status }, @@ -2079 +23012 @@ mod app { }   #[task(priority = 1)] - async fn sender1(_c: sender1::Context, mut sender: Sender<'static, usize, CAPACITY>) { - hprintln!("Sender 1 sending: 1"); - sender.send(1).await.unwrap(); + async fn sender1(_: sender1::Context, mut sender: Sender<'static, usize, CAPACITY>) { + loop { + // hprintln!("Sender 1 sending: 1"); + sender.send(1).await.unwrap(); + Mono::delay(50_u64.millis()).await + } }   #[task(binds = EXTI15_10, priority = 7, local = [mpu, imu_int])] @@ -23513 +26114 @@ mod app { ) { hprintln!("Waiting for data to transmit"); // Wait until we receive data to send - while let Ok(data) = receiver.recv().await { - hprintln!("Got data to transmit: {}", data); - // TODO: transmit data and delay + while let Ok(_data) = receiver.recv().await { + // hprintln!("Got data to transmit: {}", data); ctx.shared.status.lock(|s| { *s = SysStatus::TX; }); + ctx.local.txpin.toggle(); } + hprintln!("No more data received."); ctx.shared.status.lock(|s| { *s = SysStatus::IDLE; });