diff --git a/boards/feather_m0/Cargo.toml b/boards/feather_m0/Cargo.toml index 0e826e05ed62..dde98cdc4ed0 100644 --- a/boards/feather_m0/Cargo.toml +++ b/boards/feather_m0/Cargo.toml @@ -39,7 +39,7 @@ version = "0.3.1" [dependencies.embedded-sdmmc] optional = true -version = "0.3" +version = "0.9" [dev-dependencies] cortex-m = "0.7" @@ -49,6 +49,7 @@ defmt-rtt = "0.4" drogue-nom-utils = "0.1" embassy-executor = {version = "0.6.2", features = ["arch-cortex-m", "executor-thread", "task-arena-size-64"]} embedded-graphics = "0.7.1" +embedded-hal-bus = "0.3.0" heapless = "0.8" nom = {version = "5", default-features = false} panic-halt = "0.2" diff --git a/boards/feather_m0/examples/adalogger.rs b/boards/feather_m0/examples/adalogger.rs index 13dfecc89df8..e34f028addb3 100644 --- a/boards/feather_m0/examples/adalogger.rs +++ b/boards/feather_m0/examples/adalogger.rs @@ -11,7 +11,8 @@ use core::sync::atomic; use cortex_m::interrupt::free as disable_interrupts; use cortex_m::peripheral::NVIC; -use embedded_sdmmc::{Controller, SdMmcSpi, VolumeIdx}; +use embedded_hal_bus::spi::ExclusiveDevice; +use embedded_sdmmc::{SdCard, VolumeIdx, VolumeManager}; use usb_device::bus::UsbBusAllocator; use usb_device::prelude::*; use usbd_serial::{SerialPort, USB_CLASS_CDC}; @@ -26,6 +27,7 @@ use hal::fugit::RateExtU32; use hal::pac::{interrupt, CorePeripherals, Peripherals}; use hal::prelude::*; use hal::rtc; +use hal::timer::TimerCounter; use hal::usb::UsbBus; use heapless::String; @@ -48,8 +50,21 @@ fn main() -> ! { let timer_clock = clocks .configure_gclk_divider_and_source(ClockGenId::Gclk3, 32, ClockSource::Osc32k, true) .unwrap(); + + // Setup timer clock from + let tc45 = &clocks.tc4_tc5(&timer_clock).unwrap(); + + // Setup a timer for the SPI driver delay source + let timer_spi = TimerCounter::tc4_(tc45, peripherals.tc4, &mut peripherals.pm); + + // Setup a timer for the SPI driver delay source + let timer_sdcard = TimerCounter::tc5_(tc45, peripherals.tc5, &mut peripherals.pm); + + // Setup the RTC for the SD card volume time source let rtc_clock = clocks.rtc(&timer_clock).unwrap(); - let timer = rtc::Rtc::clock_mode(peripherals.rtc, rtc_clock.freq(), &mut peripherals.pm); + let rtc = rtc::Rtc::clock_mode(peripherals.rtc, rtc_clock.freq(), &mut peripherals.pm); + + // Setup red led let pins = bsp::Pins::new(peripherals.port); let mut red_led: bsp::RedLed = pin_alias!(pins.red_led).into(); @@ -91,9 +106,9 @@ fn main() -> ! { // Now work on the SD peripherals. Slow SPI speed required on init let spi_sercom = periph_alias!(peripherals.spi_sercom); - let spi = bsp::spi_master( + let spi_bus = bsp::spi_master( &mut clocks, - 400_u32.kHz(), + 4.MHz(), spi_sercom, &mut peripherals.pm, pins.sclk, @@ -125,32 +140,31 @@ fn main() -> ! { usbserial_write!("Card inserted!\r\n"); delay.delay_ms(250_u32); - let mut controller = Controller::new(SdMmcSpi::new(spi, sd_cs), timer); + let spi_device = ExclusiveDevice::new(spi_bus, sd_cs, timer_spi).unwrap(); + let sdcard = SdCard::new(spi_device, timer_sdcard); - match controller.device().init() { - Ok(_) => { - // speed up SPI and read out some info - controller - .device() - .spi() - .reconfigure(|c| c.set_baud(4.MHz())); + match sdcard.num_bytes() { + Ok(num_bytes) => { usbserial_write!("OK!\r\nCard size...\r\n"); - match controller.device().card_size_bytes() { - Ok(size) => usbserial_write!("{} bytes\r\n", size), - Err(e) => usbserial_write!("Err: {:?}\r\n", e), - } + usbserial_write!("{} bytes\r\n", num_bytes); + + let volume_manager = VolumeManager::new(sdcard, rtc); for i in 0..=3 { - let volume = controller.get_volume(VolumeIdx(i)); + let volume = volume_manager.open_volume(VolumeIdx(i)); usbserial_write!("volume {:?}\r\n", volume); if let Ok(volume) = volume { - let root_dir = controller.open_root_dir(&volume).unwrap(); - usbserial_write!("Listing root directory:\r\n"); - controller - .iterate_dir(&volume, &root_dir, |x| { - usbserial_write!("\tFound: {:?}\r\n", x); - }) - .unwrap(); + match volume.open_root_dir() { + Ok(root_dir) => { + usbserial_write!("Listing root directory:\r\n"); + root_dir + .iterate_dir(|x| { + usbserial_write!("\tFound: {:?}\r\n", x); + }) + .unwrap(); + } + Err(e) => usbserial_write!("Directory err: {:?}!\r\n", e), + } } } } diff --git a/boards/feather_m0/examples/adc.rs b/boards/feather_m0/examples/adc.rs index 6194e9d26b28..69e4c4ad725e 100644 --- a/boards/feather_m0/examples/adc.rs +++ b/boards/feather_m0/examples/adc.rs @@ -17,7 +17,7 @@ use bsp::Pins; use pac::{CorePeripherals, Peripherals}; use hal::{ - adc::{Accumulation, Adc, Prescaler, Resolution}, + adc::{Accumulation, Prescaler}, clock::GenericClockController, }; @@ -46,8 +46,8 @@ fn main() -> ! { let mut adc_pin = pins.a0.into_alternate(); loop { - let res = adc.read(&mut adc_pin); + let _res = adc.read(&mut adc_pin); #[cfg(feature = "use_semihosting")] - cortex_m_semihosting::hprintln!("ADC value: {}", read).unwrap(); + cortex_m_semihosting::hprintln!("ADC value: {}", _res).unwrap(); } } diff --git a/boards/feather_m0/examples/async_adc.rs b/boards/feather_m0/examples/async_adc.rs index 56139256ba01..a2b626b01eea 100644 --- a/boards/feather_m0/examples/async_adc.rs +++ b/boards/feather_m0/examples/async_adc.rs @@ -16,7 +16,7 @@ use bsp::Pins; use pac::{CorePeripherals, Peripherals}; use hal::{ - adc::{Accumulation, Adc, Adc0, Prescaler, Resolution}, + adc::{Accumulation, Adc0, Prescaler}, clock::GenericClockController, }; diff --git a/boards/feather_m4/examples/adc.rs b/boards/feather_m4/examples/adc.rs index b6b892cf43d3..d3f6adfadb74 100644 --- a/boards/feather_m4/examples/adc.rs +++ b/boards/feather_m4/examples/adc.rs @@ -17,7 +17,7 @@ use bsp::Pins; use pac::{CorePeripherals, Peripherals}; use hal::{ - adc::{Accumulation, Adc, Prescaler, Resolution}, + adc::{Accumulation, Prescaler}, clock::v2::{clock_system_at_reset, pclk::Pclk}, }; diff --git a/boards/metro_m4/examples/adc.rs b/boards/metro_m4/examples/adc.rs index 56c46bbd97f7..c4b3b5c889d9 100644 --- a/boards/metro_m4/examples/adc.rs +++ b/boards/metro_m4/examples/adc.rs @@ -17,7 +17,7 @@ use bsp::Pins; use pac::{CorePeripherals, Peripherals}; use hal::{ - adc::{Accumulation, Adc, Prescaler, Resolution}, + adc::{Accumulation, Prescaler}, clock::v2::{clock_system_at_reset, pclk::Pclk}, }; diff --git a/boards/metro_m4/examples/async_adc.rs b/boards/metro_m4/examples/async_adc.rs index 818e395734d7..3931347f8557 100644 --- a/boards/metro_m4/examples/async_adc.rs +++ b/boards/metro_m4/examples/async_adc.rs @@ -16,7 +16,7 @@ use bsp::Pins; use pac::{CorePeripherals, Peripherals}; use hal::{ - adc::{Accumulation, Adc, Adc0, Prescaler, Resolution}, + adc::{Accumulation, Adc0, Prescaler}, clock::v2::{clock_system_at_reset, pclk::Pclk}, }; diff --git a/boards/samd11_bare/examples/adc.rs b/boards/samd11_bare/examples/adc.rs index 8a4416357b2b..55b25237def5 100644 --- a/boards/samd11_bare/examples/adc.rs +++ b/boards/samd11_bare/examples/adc.rs @@ -17,7 +17,7 @@ use bsp::Pins; use pac::{CorePeripherals, Peripherals}; use hal::{ - adc::{Accumulation, Adc, Prescaler, Resolution}, + adc::{Accumulation, Prescaler}, clock::GenericClockController, }; diff --git a/hal/Cargo.toml b/hal/Cargo.toml index 3bf305003f54..81e9102d3bd5 100644 --- a/hal/Cargo.toml +++ b/hal/Cargo.toml @@ -63,7 +63,7 @@ defmt = {version = "1.0.1", optional = true} embassy-sync = {version = "0.6.0", optional = true} embedded-hal-async = {version = "1.0.0", optional = true} embedded-io-async = {version = "0.6.1", optional = true} -embedded-sdmmc = {version = "0.8.1", optional = true} +embedded-sdmmc = {version = "0.9.0", optional = true} futures = {version = "0.3.31", default-features = false, features = ["async-await"], optional = true} jlink_rtt = {version = "0.2", optional = true} mcan-core = {version = "0.2", optional = true}