Skip to content

Instantly share code, notes, and snippets.

@franzflasch
Last active July 17, 2024 18:27
Show Gist options
  • Save franzflasch/6c52f28eb1327213d5e83e299bd775eb to your computer and use it in GitHub Desktop.
Save franzflasch/6c52f28eb1327213d5e83e299bd775eb to your computer and use it in GitHub Desktop.
qemu-cortex-m-stm32

Howto qemu cortex-m (stm32)

Install prerequisites for qemu, some of them are:

apt-get install build-essential libglib2.0-dev zlib1g-dev libpixman-1-dev
apt-get install libsdl2*

Get qemu for cortex-m microcontrollers

git clone https://github.com/gnu-mcu-eclipse/qemu.git
cd qemu
git submodule update --init dtc

Build qemu from source

mkdir build
cd build
../configure --target-list="gnuarmeclipse-softmmu" --prefix=<qemu_build_dir>/_installed --disable-werror --with-sdlabi="2.0"
make && make install

Prepare some files

The qemu needs some jpg files and json configs prepared in the work directory (where qemu is started) so you need to copy the files (from the qemu bin dir, we use the olimex STM32-H103 board):

cd <qemu_build_dir>/_installed/bin
cp ../../../gnu-mcu-eclipse/devices/STM32F103xx-qemu.json .
cp ../../../gnu-mcu-eclipse/graphics/STM32-H103.jpg .

Start qemu (from qemu install bin dir)

./qemu-system-gnuarmeclipse --verbose --board STM32-H103 --image <image_deploy_dir>/test_project.elf

OPTIONAL: using qemu and gdb

1. start qemu session with:

qemu-system-gnuarmeclipse -s --verbose --board STM32-H103 --image <image_deploy_dir>/test_project.elf

2. start arm debugger

arm-none-eabi-gdb <image_deploy_dir>/test_project.elf

3. within gdb connect to the target:

target remote 172.17.0.1:1234

You can now set breakpoints etc. - do some default gdb to debug your program!

Have a nice day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment