Skip to content

'get_ticks_per_10ms' works like 'get_ticks_per_1ms' on QEMU #182

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

Open
JOE1994 opened this issue Jan 5, 2020 · 1 comment
Open

'get_ticks_per_10ms' works like 'get_ticks_per_1ms' on QEMU #182

JOE1994 opened this issue Jan 5, 2020 · 1 comment

Comments

@JOE1994
Copy link
Contributor

JOE1994 commented Jan 5, 2020

Hello,
Using the Cargo config as below,

...
[target.thumbv7m-none-eabi]
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
[build]
target = "thumbv7m-none-eabi"    # Cortex-M3
...

I tested running the below program using QEMU.

#![no_std]
#![no_main]
extern crate panic_halt;
use cortex_m::asm;
use cortex_m_rt::entry;
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m::peripheral::SYST;
use cortex_m_semihosting::{debug, hprintln};
#[entry]
fn main() -> ! {
    let p = cortex_m::Peripherals::take().unwrap();
    let mut syst = p.SYST;

    syst.set_clock_source(SystClkSource::Core);
    syst.set_reload(SYST::get_ticks_per_10ms() * 1000); // Works strange in QEMU?
    syst.enable_counter();
    hprintln!(
        "{} ticks = 10 millisecond", SYST::get_ticks_per_10ms()
    ).unwrap();
    let mut seconds: usize = 0;
    loop {
        // busy wait until the timer wraps around
        while !syst.has_wrapped() {}
        seconds += 1;
        hprintln!("{} seconds passed", seconds).unwrap(); // prints every second!
    }
}

I checked that fn get_ticks_per_10ms always returns 10_000 in my program.
Since I set called the set_reload function with an argument of get_ticks_per_10ms() * 1_000,
I expected the program to print out to the console every 10 seconds (since ticks_per_10ms * 1_000 == ticks_per_10seconds).
However, the program prints out to the console every 1 second.

I tried changing the argument fed to set_reload(), and it seems like the get_ticks_per_10ms() is behaving like get_ticks_per_1ms().

Unfortunately, I do not have an actual cortex-m device to test this behavior.
I'm currently not sure whether this is an issue with the api of the cortex-m crate, or QEMU.
If this is an issue with the cortex-m crate, maybe the function name of fn get_ticks_per_10ms should be changed to fn get_ticks_per_1ms.

Thank you for reading 😄

@TDHolmes
Copy link
Contributor

My bet is the qemu model has just implemented the calib register wrong. Could you check is_precise? perhaps qemu agrees that the value returned by calib is wrong

adamgreig pushed a commit that referenced this issue Jan 12, 2022
182: Add thumbv8m.main support. r=korken89 a=thejpster

* Add thumbv8m.main support.
* Also adds feature flags into build.rs so SecureFault gets included.

Co-authored-by: Jonathan 'theJPster' Pallant <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants