Creating STM32 Arduino framework firmware with bootloader



How do I create firmware using STM32 Arduino framework that is usable with bootloader? As far as I understand, I need to tell linker to shift the firmware to higher addresses. How can I do that? Should I just pass some flag to linker, or there’s some option that can be added to platformio.ini? Perhaps any examples?

My MCU is STM32F103CB.


I’ve noticed there’s upload_protocol = dfu option that, according to builder\frameworks\arduino\maple\ sets appropriate linker script to offset the application to 0x8002000 address.

It apparently can be used with any bootloader, including custom. The only requirement is to fit the bootloader code in the freed ROM region. If it doesn’t fit, that file and bootloader script can be edited, though.


Does anyone know how to supply custom .ld file path to the linker to avoid editing the files supplied with PlatformIO?
I can put it into variant’s ld subfolder inside Arduino STM32 framework, but what about a subfolder inside a project folder?


Got it.
-Wl,-T./my.ld. The path is relative to project root dir.


When I try to pass custom vector table start address by defining VECT_TAB_ADDR, I get the following error:

TypeError: unhashable type: 'list':
File "C:\.platformio\penv\lib\site-packages\platformio\builder\", line 162:
File "C:\.platformio\packages\tool-scons\script\..\engine\SCons\Script\", line 541:
return _SConscript(self.fs, *files, **subst_kw)
File "C:\.platformio\packages\tool-scons\script\..\engine\SCons\Script\", line 250:
exec _file_ in call_stack[-1].globals
File "C:\.platformio\platforms\ststm32\builder\", line 127:
target_elf = env.BuildProgram()
File "C:\.platformio\packages\tool-scons\script\..\engine\SCons\", line 224:
return self.method(*nargs, **kwargs)
File "C:\.platformio\penv\lib\site-packages\platformio\builder\tools\", line 67:
File "C:\.platformio\packages\tool-scons\script\..\engine\SCons\", line 224:
return self.method(*nargs, **kwargs)
File "C:\.platformio\penv\lib\site-packages\platformio\builder\tools\", line 173:
all_flags = set(all_flags)

My platformio.ini file’s relevant portion:

build_flags = -Wl,-T./my.ld -v -DVECT_TAB_ADDR=134238208
build_unflags = -DVECT_TAB_ADDR=134217728

Adding a space between -D and VECT_TAB_ADDR doesn’t help.


It was a bug, it’s fixed now for some time already.
No more questions :slight_smile: