Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtensa-lx-rt: Re-enabling hw-fp after ISR doesn't seem to work #2056

Closed
bjoernQ opened this issue Sep 2, 2024 · 1 comment
Closed

xtensa-lx-rt: Re-enabling hw-fp after ISR doesn't seem to work #2056

bjoernQ opened this issue Sep 2, 2024 · 1 comment
Labels
bug Something isn't working package:xtensa-lx-rt Issues related to the xtensa-lx-rt package status:needs-attention This should be prioritized

Comments

@bjoernQ
Copy link
Contributor

bjoernQ commented Sep 2, 2024

Example to be run on e.g. ESP32-S3

//! This shows how to use the TIMG peripheral interrupts.
//!
//! There is TIMG0 which contains a general purpose timer and a watchdog timer.

//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3

#![no_std]
#![no_main]

use core::cell::RefCell;

use critical_section::Mutex;
use esp_backtrace as _;
use esp_hal::{
    clock::ClockControl,
    interrupt::{self, Priority},
    peripherals::{Interrupt, Peripherals, TIMG0},
    prelude::*,
    system::SystemControl,
    timer::timg::{Timer, Timer0, TimerGroup},
};

static TIMER0: Mutex<RefCell<Option<Timer<Timer0<TIMG0>, esp_hal::Blocking>>>> =
    Mutex::new(RefCell::new(None));

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = SystemControl::new(peripherals.SYSTEM);
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
    let timer0 = timg0.timer0;
    timer0.set_interrupt_handler(tg0_t0_level);

    interrupt::enable(Interrupt::TG0_T0_LEVEL, Priority::Priority1).unwrap();
    timer0.load_value(500u64.millis()).unwrap();
    timer0.start();
    timer0.listen();

    critical_section::with(|cs| {
        TIMER0.borrow_ref_mut(cs).replace(timer0);
    });

    let delay = esp_hal::delay::Delay::new(&clocks);

    let mut i = 0;
    loop {
        delay.delay_millis(1500);
        esp_println::println!("Let's do some math");
        esp_println::println!("{}", i as f32 * 2f32);
        i += 1;
    }
}

#[handler]
fn tg0_t0_level() {
    critical_section::with(|cs| {
        esp_println::println!(
            "Interrupt at {} ms",
            esp_hal::time::current_time()
                .duration_since_epoch()
                .to_millis()
        );

        let mut timer0 = TIMER0.borrow_ref_mut(cs);
        let timer0 = timer0.as_mut().unwrap();

        timer0.clear_interrupt();
        timer0.load_value(500u64.millis()).unwrap();
        timer0.start();
    });
}

Output:

Interrupt at 674 ms
Interrupt at 1174 ms
Interrupt at 1674 ms
Let's do some math



Exception occured 'Cp0Disabled'
Context
PC=0x4200100b       PS=0x00060730
0x4200100b - timer_interrupt::__xtensa_lx_rt_main
    at C:\projects\clean\esp-hal\examples\src\bin\timer_interrupt.rs:51
A0=0x820096dd       A1=0x3fcdc640       A2=0x00000100       A3=0x60023004       A4=0x00000001
A5=0x00000000       A6=0x20000000       A7=0x00000000       A8=0x3fcdc6a0       A9=0x00000000
A10=0x00060720      A11=0x00000000      A12=0x3fc898bc      A13=0x60038004      A14=0x40000000
A15=0x00000002
SAR=00000004
EXCCAUSE=0x00000020 EXCVADDR=0x00000000
LBEG=0x403cea32     LEND=0x403cea36     LCOUNT=0x00000000
THREADPTR=0x00000000
SCOMPARE1=0x00000100
BR=0x00000000
ACCLO=0x00000000    ACCHI=0x00000000
M0=0x00000000       M1=0x00000000       M2=0x00000000       M3=0x00000000
F64R_LO=0xb771a38d  F64R_HI=0xfda3967a  F64S=0xceabbb75
FCR=0xad079982      FSR=0xe9b6ceef
F0=0xb42c050c       F1=0xf3136273       F2=0xfdf79f6b       F3=0x2138d447       F4=0x3937a6fe
F5=0x3c76fd99       F6=0x73228270       F7=0xde1e6a95       F8=0x11e78072       F9=0xd4a13bb0
F10=0x4016858f      F11=0x3278441b      F12=0xc7feff6f      F13=0xfe4cf3ff      F14=0x08361538
F15=0xff8a7623
0x40378da1
ESP32Reset
    at ??:??

So apparently after running the ISR Cp0 is still disabled.

@bjoernQ bjoernQ added bug Something isn't working package:xtensa-lx-rt Issues related to the xtensa-lx-rt package labels Sep 2, 2024
@github-project-automation github-project-automation bot moved this to Todo in esp-rs Sep 2, 2024
@SergioGasquez SergioGasquez added the status:needs-attention This should be prioritized label Sep 2, 2024
@bjoernQ
Copy link
Contributor Author

bjoernQ commented Sep 2, 2024

Closed via #2057

@bjoernQ bjoernQ closed this as completed Sep 2, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:xtensa-lx-rt Issues related to the xtensa-lx-rt package status:needs-attention This should be prioritized
Projects
Archived in project
Development

No branches or pull requests

2 participants