mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 22:55:26 +00:00

* Create the `esp32c6-hal` package * Teach `esp-hal-common` about the ESP32-C6 * Get a number of peripheral drivers building for the ESP32-C6 bckup initial clocks_ii * Create the `esp32c6-hal` package C6: update * Simplify and fix the linker script update * C6: add I2S * Create the `esp32c6-hal` package * Teach `esp-hal-common` about the ESP32-C6 * Get a number of peripheral drivers building for the ESP32-C6 bckup initial clocks_ii * Create the `esp32c6-hal` package * C6: update * Simplify and fix the linker script * update * C6: add I2S * update * C6 Interrupts * C6: Update build.rs, linker scripts and initial examples * C6: RMT * Fix interrupt handling * Fix `ClockControl::configure` * C6: revert to I2S0 instead of just I2S * C6: rebase and update * RTC not buildable * Implement RWDT and SWD disable * C6: working LEDC * C6: working RMT * C6: add aes * C6: add mcpwm * C6: add rtc_cntln - not finished * C6: update and formatting * C6: add pcnt * C6: add examples and format * Remove inline assembly, fix interrupts and linker scripts * Remove unused features, update cargo config for atomic emu, misc cleanup * Get ADC building and example "working" (as much as it ever does) * Remove a bunch of unused constants which were copied from ESP-IDF * The `mcpwm` example now works correctly * Get `TWAI` peripheral driver building for C6 * Clean up the `rtc_cntl` module and get all the other HALs building again * Add the C6 to our CI workflow * Fix various things that have been missed when rebasing Still missing a few examples (`clock_monitor`, `embassy_spi`, `ram`) * C6: Small updates in wdt (#1) * C6: Update WDT * C6: Update examples with WDT update * Update `esp-println` dependency to fix build errors * Fix formatting issues causing pre-commit hook to fail * Get some more examples working * Working `ram` example * Sync with changes in `main` after rebasing * Working `embassy_spi` example * Use a git dependency for the PAC until we publish a release * Fix I2S for ESP32-C6 * Fix esp32c6 direct boot (#4) * Add direct boot support for C6 * Fix direct boot for c6 - Actually copy into rtc ram - remove dummy section that is no longer needed (was just a waste of flash space) - Move RTC stuff before the no load sections * Update RWDT and refactor RTC (#3) * C6: Update RWDT and add example, refactor RTC and add not-really-good example * Update based on review comments, resolve bunch of warnings and run cargo fmt * Update C6 esp-pacs rev commit * Fix clocks_ll/esp32c6.rs * Fix riscv interrupts * Remove clock_monitor example for now * RAM example works in direct-boot mode * Add a TODO for &mut TIMG0 and cargo fmt * Fix linker script after a bad rebase * Update CI and Cargo.toml embassy required features * use riscv32imac-unknown-none-elf target for C6 in CI * change default target to riscv32imac-unknown-none-elf * add riscv32imac-unknown-none-elf target to MSRV job * another cleanup --------- Co-authored-by: bjoernQ <bjoern.quentin@mobile-j.de> Co-authored-by: Jesse Braham <jesse@beta7.io> * Make required changes to include new `RADIO` peripheral * Use published versions of PAC and `esp-println` * Use the correct target extensions (`imac`) * Fix the super watchdog timer, plus a few more examples * Fix UART clock configuration * Make sure to sync UART registers when configuring AT cmd detection * Disable APM in direct-boot mode * Address a number of review comments * Fix `SPI` clocks and `rtc_watchdog` example (#6) * fix SPI clocks * run cargo fmt * Add comment about used default clk src * Fix rtc_watchdog example in BL mode * run cargo fmt * Update rtc_watchdog example that it works in DB mode * README and example fixes/cleanup * Add I2C peripheral enable and reset * Fix `ApbSarAdc` configuration in `system.rs` --------- Co-authored-by: bjoernQ <bjoern.quentin@mobile-j.de> Co-authored-by: Juraj Sadel <juraj.sadel@espressif.com> Co-authored-by: Juraj Sadel <jurajsadel@gmail.com> Co-authored-by: Scott Mabin <scott@mabez.dev>
81 lines
3.0 KiB
Rust
81 lines
3.0 KiB
Rust
//! Demonstrates the use of the SHA peripheral and compares the speed of
|
|
//! hardware-accelerated and pure software hashing.
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp32c6_hal::{
|
|
clock::ClockControl,
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
sha::{Sha, ShaMode},
|
|
timer::TimerGroup,
|
|
Rtc,
|
|
};
|
|
use esp_backtrace as _;
|
|
use esp_println::println;
|
|
use nb::block;
|
|
use sha2::{Digest, Sha256};
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let system = peripherals.PCR.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
|
let mut wdt = timer_group0.wdt;
|
|
let mut rtc = Rtc::new(peripherals.LP_CLKRST);
|
|
|
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
|
wdt.disable();
|
|
rtc.rwdt.disable();
|
|
|
|
let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes();
|
|
let mut remaining = source_data.clone();
|
|
let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA256);
|
|
|
|
// Short hashes can be created by decreasing the output buffer to the desired
|
|
// length
|
|
let mut output = [0u8; 32];
|
|
|
|
// let pre_calc = xtensa_lx::timer::get_cycle_count();
|
|
// The hardware implementation takes a subslice of the input, and returns the
|
|
// unprocessed parts The unprocessed parts can be input in the next
|
|
// iteration, you can always add more data until finish() is called. After
|
|
// finish() is called update()'s will contribute to a new hash which
|
|
// can be extracted again with finish().
|
|
|
|
while remaining.len() > 0 {
|
|
// Can add println to view progress, however println takes a few orders of
|
|
// magnitude longer than the Sha function itself so not useful for
|
|
// comparing processing time println!("Remaining len: {}",
|
|
// remaining.len());
|
|
|
|
// All the HW Sha functions are infallible so unwrap is fine to use if you use
|
|
// block!
|
|
remaining = block!(hasher.update(remaining)).unwrap();
|
|
}
|
|
|
|
// Finish can be called as many times as desired to get mutliple copies of the
|
|
// output.
|
|
block!(hasher.finish(output.as_mut_slice())).unwrap();
|
|
// let post_calc = xtensa_lx::timer::get_cycle_count();
|
|
// let hw_time = post_calc - pre_calc;
|
|
// println!("Took {} cycles", hw_time);
|
|
println!("SHA256 Hash output {:02x?}", output);
|
|
|
|
// let pre_calc = xtensa_lx::timer::get_cycle_count();
|
|
let mut hasher = Sha256::new();
|
|
hasher.update(source_data);
|
|
let soft_result = hasher.finalize();
|
|
// let post_calc = xtensa_lx::timer::get_cycle_count();
|
|
// let soft_time = post_calc - pre_calc;
|
|
// println!("Took {} cycles", soft_time);
|
|
println!("SHA256 Hash output {:02x?}", soft_result);
|
|
|
|
// println!("HW SHA is {}x faster", soft_time/hw_time);
|
|
|
|
loop {}
|
|
}
|