* Update the `GDMA` driver to support the ESP32-H2 * Update the `SPI` driver to support the ESP32-H2 * Add `SPI` examples for ESP32-H2 * Update CHANGELOG * Remove copy-pasted references to ESP32-C6 * Update GPIO pins used in SPI examples, add `qspi_flash` example * Update SPI clock configuration to produce correct clock rate * Correct comment regarding clock source frequency Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com> * H2: Add PLL_48M_CLK src to ClockControl and RawClocks * H2: Use PLL_48M_CLK as SPI clk src * H2: cleanup commented block in SPI driver * H2: update docs comment in embassy_spi example * fmt * Add a new line in embassy_spi example --------- Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com> Co-authored-by: Juraj Sadel <juraj.sadel@espressif.com>
125 lines
3.2 KiB
Rust
125 lines
3.2 KiB
Rust
//! SPI read manufacturer id from flash chip
|
|
//!
|
|
//! Folowing pins are used:
|
|
//! SCLK GPIO1
|
|
//! MISOI/IO0 GPIO2
|
|
//! MOSI/IO1 GPIO3
|
|
//! IO2 GPIO4
|
|
//! IO3 GPIO5
|
|
//! CS GPIO11
|
|
//!
|
|
//! Depending on your target and the board you are using you have to change the
|
|
//! pins.
|
|
//!
|
|
//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status
|
|
//! register is set.
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp32h2_hal::{
|
|
clock::ClockControl,
|
|
gpio::IO,
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
spi::{Address, Command, HalfDuplexReadWrite, Spi, SpiDataMode, SpiMode},
|
|
timer::TimerGroup,
|
|
Delay,
|
|
Rtc,
|
|
};
|
|
use esp_backtrace as _;
|
|
use esp_println::println;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let mut system = peripherals.PCR.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
// Disable the watchdog timers. For the ESP32-H2, this includes the Super WDT,
|
|
// the RTC WDT, and the TIMG WDTs.
|
|
let mut rtc = Rtc::new(peripherals.LP_CLKRST);
|
|
let timer_group0 = TimerGroup::new(
|
|
peripherals.TIMG0,
|
|
&clocks,
|
|
&mut system.peripheral_clock_control,
|
|
);
|
|
let mut wdt0 = timer_group0.wdt;
|
|
let timer_group1 = TimerGroup::new(
|
|
peripherals.TIMG1,
|
|
&clocks,
|
|
&mut system.peripheral_clock_control,
|
|
);
|
|
let mut wdt1 = timer_group1.wdt;
|
|
|
|
rtc.swd.disable();
|
|
rtc.rwdt.disable();
|
|
wdt0.disable();
|
|
wdt1.disable();
|
|
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
let sclk = io.pins.gpio1;
|
|
let miso = io.pins.gpio2;
|
|
let mosi = io.pins.gpio3;
|
|
let sio2 = io.pins.gpio4;
|
|
let sio3 = io.pins.gpio5;
|
|
let cs = io.pins.gpio11;
|
|
|
|
let mut spi = Spi::new_half_duplex(
|
|
peripherals.SPI2,
|
|
Some(sclk),
|
|
Some(mosi),
|
|
Some(miso),
|
|
Some(sio2),
|
|
Some(sio3),
|
|
Some(cs),
|
|
100u32.kHz(),
|
|
SpiMode::Mode0,
|
|
&mut system.peripheral_clock_control,
|
|
&clocks,
|
|
);
|
|
|
|
let mut delay = Delay::new(&clocks);
|
|
|
|
loop {
|
|
// READ MANUFACTURER ID FROM FLASH CHIP
|
|
let mut data = [0u8; 2];
|
|
spi.read(
|
|
SpiDataMode::Single,
|
|
Command::Command8(0x90, SpiDataMode::Single),
|
|
Address::Address24(0x000000, SpiDataMode::Single),
|
|
0,
|
|
&mut data,
|
|
)
|
|
.unwrap();
|
|
println!("Single {:x?}", data);
|
|
delay.delay_ms(250u32);
|
|
|
|
// READ MANUFACTURER ID FROM FLASH CHIP
|
|
let mut data = [0u8; 2];
|
|
spi.read(
|
|
SpiDataMode::Dual,
|
|
Command::Command8(0x92, SpiDataMode::Single),
|
|
Address::Address32(0x000000_00, SpiDataMode::Dual),
|
|
0,
|
|
&mut data,
|
|
)
|
|
.unwrap();
|
|
println!("Dual {:x?}", data);
|
|
delay.delay_ms(250u32);
|
|
|
|
// READ MANUFACTURER ID FROM FLASH CHIP
|
|
let mut data = [0u8; 2];
|
|
spi.read(
|
|
SpiDataMode::Quad,
|
|
Command::Command8(0x94, SpiDataMode::Single),
|
|
Address::Address32(0x000000_00, SpiDataMode::Quad),
|
|
4,
|
|
&mut data,
|
|
)
|
|
.unwrap();
|
|
println!("Quad {:x?}", data);
|
|
delay.delay_ms(1500u32);
|
|
}
|
|
}
|