From 2fc1f94b3e2788fb6837ffb22f93e954c78949f3 Mon Sep 17 00:00:00 2001 From: Michael Kamprath Date: Sun, 29 Sep 2024 20:48:22 -0700 Subject: [PATCH] adjusted logging --- .cargo/config.toml | 2 +- Cargo.toml | 12 ++- src/main.rs | 77 +++++++++----------- src/robot/file_storage.rs | 4 +- src/robot/file_storage/sd_card_spi_device.rs | 22 +++--- 5 files changed, 55 insertions(+), 62 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index c909f85..61e6a86 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -27,4 +27,4 @@ rustflags = [ target = "thumbv6m-none-eabi" [env] -DEFMT_LOG = "debug" +DEFMT_LOG = "info" diff --git a/Cargo.toml b/Cargo.toml index b3a20ea..534aca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,11 +36,11 @@ rp-pico = "0.9" # sparkfun-pro-micro-rp2040 = "0.7" # If you're not going to use a Board Support Package you'll need these: -rp2040-hal = { version = "0.10", features = [ - "rt", - "critical-section-impl", - "defmt", -] } +# rp2040-hal = { version = "0.10", features = [ +# "rt", +# "critical-section-impl", +# "defmt", +# ] } # rp2040-boot2 = "0.3" # cargo build/run @@ -99,5 +99,3 @@ opt-level = 3 mpu6050 = { path = "../mpu6050" } [patch.crates-io] -mcp230xx = { path = "../mcp230xx" } -shared-bus = { path = "../shared-bus" } diff --git a/src/main.rs b/src/main.rs index 27c1604..7c736d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,45 +5,36 @@ mod model; mod robot; mod system; -use bsp::{ - entry, - hal::{fugit::HertzU32, gpio}, -}; use core::cell::RefCell; use defmt::{error, info, panic}; use defmt_rtt as _; use embedded_alloc::LlffHeap as Heap; use panic_probe as _; -use rp2040_hal::{ - gpio::{ - bank0::{Gpio0, Gpio2, Gpio3}, - FunctionI2C, FunctionSpi, Pin, PullDown, PullUp, - }, - pac::SPI0, -}; // Provide an alias for our BSP so we can switch targets quickly. // Uncomment the BSP you included in Cargo.toml, the rest of the code does not need to change. use rp_pico as bsp; // use sparkfun_pro_micro_rp2040 as bsp; - +use crate::robot::Robot; +use bsp::{ + entry, + hal::fugit::HertzU32, + hal::{ + clocks::{init_clocks_and_plls, Clock}, + gpio::{FunctionI2C, Pin, PullUp}, + pac, + pwm::Slices, + sio::Sio, + watchdog::Watchdog, + }, +}; +use driver::Driver; +use system::millis::init_millis; extern crate alloc; #[global_allocator] static HEAP: Heap = Heap::empty(); -use bsp::hal::{ - clocks::{init_clocks_and_plls, Clock}, - pac, - pwm::Slices, - sio::Sio, - watchdog::Watchdog, -}; - -use crate::robot::Robot; -use driver::Driver; -use system::millis::init_millis; - #[entry] fn main() -> ! { // Initialize the allocator BEFORE you use it @@ -117,22 +108,26 @@ fn main() -> ! { // set up SPI #[allow(clippy::type_complexity)] - let spi: rp_pico::hal::Spi< - rp_pico::hal::spi::Disabled, - SPI0, - ( - rp_pico::hal::gpio::Pin, - rp_pico::hal::gpio::Pin, - rp_pico::hal::gpio::Pin, - ), - > = bsp::hal::Spi::new( - pac.SPI0, - ( - pins.gpio3.into_function::(), - pins.gpio0.into_function::(), - pins.gpio2.into_function::(), - ), - ); + // let spi: rp_pico::hal::Spi< + // rp_pico::hal::spi::Disabled, + // SPI0, + // ( + // rp_pico::hal::gpio::Pin, + // rp_pico::hal::gpio::Pin, + // rp_pico::hal::gpio::Pin, + // ), + // > = bsp::hal::Spi::new( + // pac.SPI0, + // ( + // pins.gpio3.into_function::(), + // pins.gpio0.into_function::(), + // pins.gpio2.into_function::(), + // ), + // ); + let spi_mosi = pins.gpio3.into_function::(); + let spi_miso = pins.gpio0.into_function::(); + let spi_sclk = pins.gpio2.into_function::(); + let spi = bsp::hal::spi::Spi::<_, _, _, 8>::new(pac.SPI0, (spi_mosi, spi_miso, spi_sclk)); // Exchange the uninitialised SPI driver for an initialised one let spi = spi.init( @@ -155,7 +150,7 @@ fn main() -> ! { match sd.spi(|spi| { spi.bus.set_baudrate( clocks.peripheral_clock.freq(), - HertzU32::from_raw(20_000_000), + HertzU32::from_raw(16_000_000), ) }) { Some(speed) => { diff --git a/src/robot/file_storage.rs b/src/robot/file_storage.rs index c3b97a6..bf18f77 100644 --- a/src/robot/file_storage.rs +++ b/src/robot/file_storage.rs @@ -5,7 +5,7 @@ pub mod sd_file; use alloc::{rc::Rc, string::ToString, vec::Vec}; use core::cell::RefCell; -use defmt::{debug, error, info}; +use defmt::{debug, error, info, trace}; use embedded_hal::{delay::DelayNs, spi::SpiDevice}; use embedded_sdmmc::{ DirEntry, Mode, RawDirectory, RawVolume, SdCard, SdCardError, TimeSource, Timestamp, VolumeIdx, @@ -67,7 +67,7 @@ where } } - debug!("Getting Volume 0..."); + trace!("Getting Volume 0..."); let volume = match volume_mgr.open_volume(VolumeIdx(0)) { Ok(v) => v, Err(e) => { diff --git a/src/robot/file_storage/sd_card_spi_device.rs b/src/robot/file_storage/sd_card_spi_device.rs index 633d23b..4157b56 100644 --- a/src/robot/file_storage/sd_card_spi_device.rs +++ b/src/robot/file_storage/sd_card_spi_device.rs @@ -1,4 +1,4 @@ -use defmt::{debug, error}; +use defmt::{error, trace}; use embedded_hal::{ delay::DelayNs, digital::OutputPin, @@ -52,59 +52,59 @@ where DELAY: DelayNs, { fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { - debug!( + trace!( "SDCardSPIDevice::transaction - operations.len = {}", operations.len() ); // Implement the SPI transaction here - if self.cs.set_high().is_err() { + if self.cs.set_low().is_err() { return Err(SDCardSPIDeviceError::ChipSelect); } for operation in operations { if let Err(_e) = match operation { Operation::Write(data) => { - debug!( + trace!( "SDCardSPIDevice::transaction - write data.len = {}", data.len() ); self.bus.write(data) } Operation::Transfer(read_buf, write_buf) => { - debug!("SDCardSPIDevice::transaction - transfer read_buf.len = {}, write_buf.len = {}", read_buf.len(), write_buf.len()); + trace!("SDCardSPIDevice::transaction - transfer read_buf.len = {}, write_buf.len = {}", read_buf.len(), write_buf.len()); self.bus.transfer(read_buf, write_buf) } Operation::Read(data) => { - debug!( + trace!( "SDCardSPIDevice::transaction - read data.len = {}", data.len() ); self.bus.read(data) } Operation::TransferInPlace(data) => { - debug!( + trace!( "SDCardSPIDevice::transaction - transfer_in_place data.len = {}", data.len() ); self.bus.transfer_in_place(data) } Operation::DelayNs(time) => { - debug!("SDCardSPIDevice::transaction - delay_ns time = {}", time); + trace!("SDCardSPIDevice::transaction - delay_ns time = {}", time); self.delay.delay_ns(*time); Ok(()) } } { // iff an error accurs, deassert CS pin and return error - self.cs.set_low().ok(); + self.cs.set_high().ok(); error!("SDCardSPIDevice::transaction - error"); return Err(SDCardSPIDeviceError::Spi); } } if self.bus.flush().is_err() { - self.cs.set_low().ok(); + self.cs.set_high().ok(); error!("SDCardSPIDevice::transaction - flush error"); return Err(SDCardSPIDeviceError::Spi); } - if self.cs.set_low().is_err() { + if self.cs.set_high().is_err() { error!("SDCardSPIDevice::transaction - chip select error"); return Err(SDCardSPIDeviceError::ChipSelect); }