Skip to content

Commit

Permalink
adjusted logging
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkamprath committed Sep 30, 2024
1 parent 20047ab commit 2fc1f94
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ rustflags = [
target = "thumbv6m-none-eabi"

[env]
DEFMT_LOG = "debug"
DEFMT_LOG = "info"
12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,5 +99,3 @@ opt-level = 3
mpu6050 = { path = "../mpu6050" }

[patch.crates-io]
mcp230xx = { path = "../mcp230xx" }
shared-bus = { path = "../shared-bus" }
77 changes: 36 additions & 41 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Gpio3, FunctionSpi, PullDown>,
rp_pico::hal::gpio::Pin<Gpio0, FunctionSpi, PullDown>,
rp_pico::hal::gpio::Pin<Gpio2, FunctionSpi, PullDown>,
),
> = bsp::hal::Spi::new(
pac.SPI0,
(
pins.gpio3.into_function::<gpio::FunctionSpi>(),
pins.gpio0.into_function::<gpio::FunctionSpi>(),
pins.gpio2.into_function::<gpio::FunctionSpi>(),
),
);
// let spi: rp_pico::hal::Spi<
// rp_pico::hal::spi::Disabled,
// SPI0,
// (
// rp_pico::hal::gpio::Pin<Gpio3, FunctionSpi, PullDown>,
// rp_pico::hal::gpio::Pin<Gpio0, FunctionSpi, PullDown>,
// rp_pico::hal::gpio::Pin<Gpio2, FunctionSpi, PullDown>,
// ),
// > = bsp::hal::Spi::new(
// pac.SPI0,
// (
// pins.gpio3.into_function::<gpio::FunctionSpi>(),
// pins.gpio0.into_function::<gpio::FunctionSpi>(),
// pins.gpio2.into_function::<gpio::FunctionSpi>(),
// ),
// );
let spi_mosi = pins.gpio3.into_function::<bsp::hal::gpio::FunctionSpi>();
let spi_miso = pins.gpio0.into_function::<bsp::hal::gpio::FunctionSpi>();
let spi_sclk = pins.gpio2.into_function::<bsp::hal::gpio::FunctionSpi>();
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(
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/robot/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
22 changes: 11 additions & 11 deletions src/robot/file_storage/sd_card_spi_device.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use defmt::{debug, error};
use defmt::{error, trace};
use embedded_hal::{
delay::DelayNs,
digital::OutputPin,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 2fc1f94

Please sign in to comment.