Reputation: 577
How do I setup QEMU to emulate ARM Cortex M3 system?
I am trying to build a kernel(C and/or assembly) for ARM based chips from the scratch. In order to accomplish that first I must emulate the system itself on QEMU so that I can run my code. The microcontroller I am using is NXP LPC1768(Cortex M3, 512KB Flash, 64KB SRAM , Ethernet).
Would be grateful if someone can help out with this. I do not access to a physical LPC1768 at the moment.
Upvotes: 2
Views: 6795
Reputation: 730
You would use the qemu-system-arm
command. Adding the -machine help
arguments currently outputs a list of 111 supported machines. You can fiilter that to only Cortex-M3 machines like this, with the current output:
% qemu-system-arm -machine help | grep Cortex-M3 | grep -v Cortex-M33
lm3s6965evb Stellaris LM3S6965EVB (Cortex-M3)
lm3s811evb Stellaris LM3S811EVB (Cortex-M3)
mps2-an385 ARM MPS2 with AN385 FPGA image for Cortex-M3
mps2-an511 ARM MPS2 with AN511 DesignStart FPGA image for Cortex-M3
netduino2 Netduino 2 Machine (Cortex-M3)
stm32vldiscovery ST STM32VLDISCOVERY (Cortex-M3)
I believe the closest option to the NXP chip you're asking about would be the STM32F2 in the netduino2
machine. Boot your firmware on that machine with:
qemu-system-arm -M netduino2 -kernel firmware.bin
Here's a relevant page in the qemu docs for more info: https://www.qemu.org/docs/master/system/arm/stm32.html
Taking the next step, assuming you want to debug using gdb, a more full example would go as follows. In one terminal, you start the emulation, freezing the CPU at startup with the -S flag:
qemu-system-arm -cpu cortex-m3 -machine netduino2 -gdb tcp::3333 -S -nographic -kernel firmware.bin
Then in another terminal, start a gdb client:
arm-none-eabi-gdb firmware.bin
Then at the (gdb)
prompt, connect with:
target remote :3333
Upvotes: 3