Flash memory must be deleted before overwriting it.
monitor flash protect 0 0 11 off monitor flash erase_address 0x08000000 0x40000 monitor flash write_image erase *"/path/to/hex/file.hex"* 0 ihex
Or, instead of telnet and hex files, use arm-none-eabi-gdb and ELF with the following commands:
arm-none-eabi-gdb target remote localhost:3333 monitor reset halt file */path/to/elf/file.elf* load monitor reset continue
Please note that when using ELF files, you do not need to specify the address where it will be (usually 0x08000000 or 0x08008000 with bootloaders).
Also consider using a loader such as OpenBLT , this will help you master principles such as VTOR, offsets, stack addresses, etc.
source share