I forgot how did I compile all of that in those two stm32 posts, lol. The post will be very brief because this one is just a quick guide for me. I was kinda panic when I realized that I couldn’t quite recall what I have written myself…
Full Pre-requisites
sudo pacman -S arm-none-eabi-gcc gdb qemu-system-arm openocd stlink
Compile ELF
arm-none-eabi-gcc \
-mcpu=cortex-m3 \
-mthumb \
-mfloat-abi=soft \
-nostdlib \
-ffreestanding \
-Isrc -Iinc \
-T stm32f103c8t6.ld \
-Wl,-Map=build/blink.map \
-Wl,--gc-sections \
-Wl,--print-memory-usage \
src/vectors.c src/main.c \
-o build/blink.elf
Convert to .bin
arm-none-eabi-objcopy -O binary build/blink.elf build/blink.bin
Since st-flash and QEMU expect raw binary.
Flash to Hardware
I use st-link and openocd. If you ask me why did I use both, I honestly don’t remember.
st-flash
st-flash write build/blink.bin 0x8000000
To erase:
st-flash erase
openocd
openocd -f interface/stlink.cfg -f target/stm32f1x.cfg \
-c "program build/blink.elf verify reset exit"
Flash to QEMU
qemu-system-arm -M netduinoplus2 -kernel build/blink.bin -S -s &
Wrong machine model, btw. It should not have been netduinoplus2, but something else, maybe it doesn’t exist.
Regarding the Live-debug on Baremetal
While the blink was very successful. However, what I was originally want to do wasn’t. For more information see this post.
Until this day, I am still not sure why did it exactly failed, as the gdb keep disconnecting over and over again. It was speculated that the resource is too tight for an UART live debugging. Except for that, I wasn’t able to investigate further, due to fatigue I suffer from at that time.