Skip to content

Commit

Permalink
demo: sdio demo for ch32v307
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed May 5, 2024
1 parent 86b1587 commit c0cf76b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
17 changes: 13 additions & 4 deletions examples/ch32v307/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FT24C32(I2C2 with pull up)
- SCL: PB10
- SDA: PB11

W32Q16(SPI1)
W25Q16(SPI1)

- CS: PA2
- DO(IO1): PA6
Expand All @@ -24,11 +24,20 @@ W32Q16(SPI1)

Micro SD Card / TFCard (SDIO)

- DAT0: PC8
- DAT1: PC9
- DAT0: PC8 (requires soldering the jumper on the back of the board)
- DAT1: PC9 (requires soldering the jumper on the back of the board)
- DAT2: PC10
- DAT3: PC11
- CLK: PC12
- CMD: PD2

- TFSW: PD7
- TFSW: PD7 (requires soldering the jumper on the back of the board)

Ethernet (requires soldering the jumper on the back of the board)

- PC0, LINK LED
- PC1, ACT LED
- PC7, RXN
- PC6, RXP
- PC9, TXN
- PC8, TXP
63 changes: 63 additions & 0 deletions examples/ch32v307/src/bin/sdmmc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

use ch32_hal as hal;
use ch32_hal::sdio::Sdmmc;
use ch32_hal::time::mhz;
use ch32_hal::{bind_interrupts, peripherals, sdio};
use embassy_executor::Spawner;
use hal::println;

bind_interrupts!(struct Irqs {
SDIO => sdio::InterruptHandler<peripherals::SDIO>;
});

#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(_spawner: Spawner) {
hal::debug::SDIPrint::enable();
let mut config = hal::Config::default();
config.rcc = hal::rcc::Config::SYSCLK_FREQ_96MHZ_HSE;
let p = hal::init(config);
hal::embassy::init();

println!("clk => {}", hal::rcc::clocks().hclk.0);

println!("Hello World!");

let mut sdmmc = Sdmmc::new_4bit(
p.SDIO,
Irqs,
p.DMA2_CH4,
p.PC12,
p.PD2,
p.PC8,
p.PC9,
p.PC10,
p.PC11,
Default::default(),
);

// let mut tfsw = Output::new(p.PD7, Level::Low, Default::default());
// tfsw.set_low();

// Should print 400kHz for initialization
println!("Configured clock: {}", sdmmc.clock().0);

sdmmc.init_card(mhz(10)).await.unwrap();

println!("init ok");

let card = sdmmc.card().unwrap();

println!("Card: {:#?}", card);

loop {}
}

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
let _ = println!("\n\n\n{}", info);

loop {}
}

0 comments on commit c0cf76b

Please sign in to comment.