esp-hal/esp32s2-hal/examples/ram.rs
Scott Mabin 9064177e99
Initial embassy support (#225)
* wip: timg embassy driver

- read_raw on timg renamed to now()
- timg initialized and stored in static for use in the embassy driver
- timg sets alarm value
- untested whether alarms actually trigger

* TIMG timer driver for esp32, esp32s3

- Adds the timg timer block as a time driver for embassy
- Not enabled on the C3 as it only has one timer block, better to use
  systimer
- s2 example added but can't build due to atomic requirements in
  futures-core

* Add S2 atomic support with emulation, fixup embassy support for the S2

* Move executor & static-cell to dev deps. Make eha optional

* Add c2 support, run fmt

* Update to crates.io embassy releases

* Update eha

* update timg time driver to new trait

* Remove exception feature of esp-backtrace and use the user handler for backtracing

* Add async testing workflow

* Update systick example

* Fix S2 examples

* Update xtensa-toolchain

* set rustflags for s2 target

* Disable systick for esp32s2 until we can fix the noted issues

* review improvements

- Fix intr prio array being off by one
- emabssy time prio interrupt set to max prio
- use cfg instead of feature for systick detection

* Update example time delays
2022-11-09 08:04:38 -08:00

114 lines
3.0 KiB
Rust

//! This shows how to use RTC memory.
//! RTC memory is retained during resets and during most sleep modes.
//! Initialized memory is always re-initialized on startup.
//! Uninitialzed memory isn't initialized on startup and can be used to keep
//! data during resets. Zeroed memory is initialized to zero on startup.
//! We can also run code from RTC memory.
#![no_std]
#![no_main]
use esp32s2_hal::{
clock::ClockControl,
macros::ram,
pac::Peripherals,
prelude::*,
timer::TimerGroup,
};
use esp_backtrace as _;
use esp_println::println;
use xtensa_atomic_emulation_trap as _;
use nb::block;
use xtensa_lx_rt::entry;
#[ram(rtc_fast)]
static mut SOME_INITED_DATA: [u8; 2] = [0xaa, 0xbb];
#[ram(rtc_fast, uninitialized)]
static mut SOME_UNINITED_DATA: [u8; 2] = [0; 2];
#[ram(rtc_fast, zeroed)]
static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8];
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take().unwrap();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut timer0 = timer_group0.timer0;
let mut wdt = timer_group0.wdt;
// Disable MWDT flash boot protection
wdt.disable();
// The RWDT flash boot protection remains enabled and it being triggered is part
// of the example
timer0.start(1u64.secs());
println!(
"IRAM function located at {:p}",
function_in_ram as *const ()
);
unsafe {
println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA);
println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA);
println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA);
SOME_INITED_DATA[0] = 0xff;
SOME_ZEROED_DATA[0] = 0xff;
println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA);
println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA);
println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA);
if SOME_UNINITED_DATA[0] != 0 {
SOME_UNINITED_DATA[0] = 0;
SOME_UNINITED_DATA[1] = 0;
}
if SOME_UNINITED_DATA[1] == 0xff {
SOME_UNINITED_DATA[1] = 0;
}
println!("Counter {}", SOME_UNINITED_DATA[1]);
SOME_UNINITED_DATA[1] += 1;
}
println!(
"RTC_FAST function located at {:p}",
function_in_rtc_ram as *const ()
);
println!("Result {}", function_in_rtc_ram());
loop {
function_in_ram();
block!(timer0.wait()).unwrap();
}
}
#[ram]
fn function_in_ram() {
println!("Hello world!");
}
#[ram(rtc_fast)]
fn function_in_rtc_ram() -> u32 {
42
}
#[xtensa_lx_rt::exception]
fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) {
use esp_println::*;
println!("\n\nException occured {:?} {:x?}", cause, frame);
let backtrace = esp_backtrace::arch::backtrace();
for b in backtrace.iter() {
if let Some(addr) = b {
println!("0x{:x}", addr)
}
}
}