rust-embedded / cortex-m-quickstart

Template to develop bare metal applications for Cortex-M microcontrollers
815 stars 169 forks source link

Is it possible to run examples in `qemu`? #119

Closed xphoniex closed 1 year ago

xphoniex commented 1 year ago

I have tried running rp pico (Cortex M0+) in qemu-system-arm with no luck (ref). I expected other processor to have better support in qemu so I compiled hello.rs example of for Cortex M3 but I can't get that to work either:

$ qemu-system-arm -M stm32vldiscovery -kernel target/thumbv7m-none-eabi/debug/examples/hello -nographic -serial tcp::5678,server=on
QEMU 6.2.0 monitor - type 'help' for more information
(qemu) qemu-system-arm: -serial tcp::5678,server=on: info: QEMU waiting for connection on: disconnected:tcp:0.0.0.0:5678,server=on
qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1)

R00=2000ffe0 R01=00000004 R02=00000000 R03=00000000
R04=00000000 R05=00000000 R06=00000000 R07=00000000
R08=00000000 R09=00000000 R10=00000000 R11=00000000
R12=00000000 R13=2000ffe0 R14=fffffff9 R15=00001454
XPSR=41000003 -Z-- T handler
FPSCR: 00000000
fish: Job 2, 'qemu-system-arm -M stm32vldisco…' terminated by signal SIGABRT (Abort)

other variants I have tried:

$ qemu-system-arm -M stm32vldiscovery -cpu cortex-m3  -kernel target/thumbv7m-none-eabi/debug/examples/hello -nographic -serial tcp::5678,server=on

$ arm-none-eabi-objcopy target/thumbv7m-none-eabi/debug/examples/hello -O ihex helloi.hex
$ qemu-system-arm -M stm32vldiscovery -cpu cortex-m3 -kernel  helloi.hex -nographic -serial tcp::5678,server=on

none works. I need a way to verify my lib works on target CPU without running hardware first, there are a lot of iterations involved and testing on hardware directly is not feasible. Is there a way for this?

xphoniex commented 1 year ago

found the correct command in .cargo/config.toml:

$ qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel target/thumbv7m-none-eabi/debug/examples/hello
Timer with period zero, disabling
Hello, world!