A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/esp-rs/esp-hal/discussions/922 below:

When enabling interrupts and using clocks, ESP32 runs for 18 seconds and hangs · esp-rs/esp-hal · Discussion #922 · GitHub

Hi, I'm trying to use interrupts with ESP32. Once I enable interrups when using clocks, after some time (consistently 18 seconds of simple looping and logging) the device stops/hangs.

This to related to the combination of clocks enabling interrupts because if I disable all interrupts or don't create the clocks (ClockControl) then device continues to work.
I'm using ESP32 basic version, I tried disabling the watchdogs of both timer groups and the rtc, but it still happens.
It happens on two different ESP32 boards.

This is the code that reproduces the issue, nothing special about it:

#![no_std]
#![no_main]

extern crate alloc;
use core::mem::MaybeUninit;
use esp_backtrace as _;
use esp_println::println;
use hal::{clock::ClockControl, peripherals::{Peripherals, self}, prelude::*, Delay, IO, Rtc, timer::TimerGroup};

#[global_allocator]
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();

fn init_heap() {
    const HEAP_SIZE: usize = 32 * 1024;
    static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();

    unsafe {
        ALLOCATOR.init(HEAP.as_mut_ptr() as *mut u8, HEAP_SIZE);
    }
}
#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = peripherals.SYSTEM.split();
    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

    let clocks = ClockControl::max(system.clock_control).freeze();
    let mut delay = Delay::new(&clocks);

    // setup logger
    // To change the log_level change the env section in .cargo/config.toml
    // or remove it and set ESP_LOGLEVEL manually before running cargo run
    // this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358
    esp_println::logger::init_logger_from_env();
    log::info!("Logger is setup");
    println!("Hello world!");

    // Disable the RTC and TIMG watchdog timers
    let mut rtc = Rtc::new(peripherals.RTC_CNTL);
    let mut timer_group0 = TimerGroup::new(
        peripherals.TIMG0,
        &clocks,
        // removed: &mut system.peripheral_clock_control, // not available in esp32
    );
    let mut wdt0 = timer_group0.wdt;

    let mut timer_group1 = TimerGroup::new(
        peripherals.TIMG1,
        &clocks,
        // removed: &mut system.peripheral_clock_control, // not available in esp32
    );
    let mut wdt1 = timer_group1.wdt;

    // removed: rtc.swd.disable(); // fn not found in esp32 (not c2) // not available in esp32
    rtc.rwdt.disable(); // every 10 sec or so
    wdt0.disable(); // every sec or so
    wdt1.disable(); 
    timer_group0.timer0.unlisten();
    timer_group0.timer1.unlisten();
    timer_group1.timer0.unlisten();
    timer_group1.timer1.unlisten();

    rtc.rwdt.unlisten();

    unsafe {
        hal::xtensa_lx::interrupt::enable();
    }

    let mut counter = 0;
    loop {
        counter += 1;
        println!("Loop...{}", counter);
        delay.delay_ms(1000u32);
    }
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4