Skip to content

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

Open
@JOE1994

Description

@JOE1994

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 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions