STM32F103RE Bootloader offset

I am trying to upload “Hello world” to STM32F103RE. The tricky part is that the chip has preinstalled bootloader so i need to apply an offset:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K - 40
FLASH (rx) : ORIGIN = 0x08007000, LENGTH = 512K - 28K
}

I have success with CUBEMX but i fail with PlatFormIO. The program compiles without errors but nothing seems to work in the case of PlatFormIO.

CUBEMX source:
https://github.com/PanagiotisMenounos/3DHex/tree/master/MCU/CUBEMX/Creality_v4.2.7_Silent

PlatFormIO source:
https://github.com/PanagiotisMenounos/3DHex/tree/master/MCU/PlatFormIO/Creality%20v4.2.7

Note that i am using the same STM32F103RETX_FLASH.ld.

Any ideas? Thank you in advance

Try adding

board_upload.offset_address = 0x08007000

to the platformio.ini.

Double check the programmer’s invocation with project task Advanced → Verbose Upload. Is the upload offset contained there with the .bin file or is it using the .elf file?

Also if it uploaded it once to the 0x0 offset the bootloader is gone, you must reflash it.

1 Like

Thank you for your answer.
i upload the fw via sd card slot with preinstalled bottloader. In order to upload i need .bin file.

The address of .isr_vector is looking good

>>> hex(134246400)
'0x8007000'

so the .bin file should be fine and also be based on that start address.

There might be additional things going wrong in the firmware that cause it to not boot. In the CubeMX source you’re using the CubeMX / STM32HAL, in PlatformIO you are using the Arduino framework.

Have you reflashed your bootloader already?

Hi Max,

The bootloader is flashed no problem with that.
I would like to keep Arduino framework but so far i have not managed to get it work.

This is a 3d printer controller board, creality v4.2.7 i am not sure if i need to create a board variant like marlin: Marlin/buildroot/share/PlatformIO/variants/MARLIN_F103Rx at 2.0.x · MarlinFirmware/Marlin · GitHub

Have you tried to

  • only use PlatformIO + Arduino without a modified linker script? (Overwrites bootloader but tests that basic Arduino is working)
  • use PlatformIO + CubeMX firmware moth modified or original linkerscript?

You should be able to use a ST-Link and the SWD connections on the board to connect to the chip directly + flash it.

You can definitely make use of that variatn like e.g. shown in GitHub - maxgerhardt/pio-custom-stm32duino-variants: A short example of how to use a custom variant folder for the PlatformIO + STM32Duino environment.

Unfortunately i can only upload the firmware from SD card slot so only modified linker will work.
In you example how i can tell which of the three variants to compile? Is this done by specific line in platformio.ini : https://github.com/maxgerhardt/pio-custom-stm32duino-variants/blob/main/platformio.ini

The project has 3 environments so you select which one to compile for in the project environment switcher.

Which environment are you using in Marlin? This one?

Can you try whether GitHub - maxgerhardt/pio-marlin-test: Temporary works?