Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Invalid PlatformIO option for memory offset #22017

Conversation

brianredbeard
Copy link

Description

A subset of STM32F1 & STM32F4 board definitions are using the option
board_build.address to specifying the memory location for firmware.

The correct option to be used is board_upload.offset_address, which
was added in platformio/platform-ststm32#853208d1. PR #21488
(recently submitted) uses the correct option for some newly added
hardware abstractions, but left this in place for existing hardware.

Using this option presently overwrites the bootloader when using
openocd and an STLinkV2.

For example: https://ask.csdn.net/questions/4185515

This is occurring because the option gets ignored and the default vector
table location of 0x08000000 gets used (which is the location of the
bootloader).

NOTE: All changes were made using the following mechanism

sed -i 's/board_build.address/board_upload\.offset_address/g' ini/stm32f{1,4}.ini

No other changes to spacing or validation beyond verification on the
STM32F103RE_btt board. This is confirmed operational with the offset
previously used with the invalid option, 0x08007000.

Requirements

STM32

Benefits

Users with conforming boards should be able to upload directly using OpenOCD without obliterating their bootloader (though it seems this should, long term, really be added to the processor definition as opposed to individual boards).

Related Issues

Affects:

A subset of STM32F1 & STM32F4 board definitions are using the option
`board_build.address` to specifying the memory location for firmware.

The correct option to be used is `board_upload.offset_address`, which
was added in [platformio/platform-ststm32#853208d1][1].  PR MarlinFirmware#21488
(recently submitted) uses the correct option for some _newly_ added
hardware abstractions, but left this in place for existing hardware.

Using this option presently overwrites the bootloader when using
`openocd` and an STLinkV2.

For example: https://ask.csdn.net/questions/4185515

This is occurring because the option gets ignored and the default vector
table location of `0x08000000` gets used (which is the location of the
bootloader).

NOTE: All changes were made using the following mechanism

```bash
sed -i 's/board_build.address/board_upload\.offset_address/g' ini/stm32f{1,4}.ini
```

No other changes to spacing or validation beyond verification on the
STM32F103RE_btt board.  This is confirmed operational with the offset
previously used with the invalid option, `0x08007000`.

[1]: platformio/platform-ststm32@853208d1
@thinkyhead
Copy link
Member

That value is there for use by buildroot/share/PlatformIO/scripts/custom_board.py:

#
# buildroot/share/PlatformIO/scripts/custom_board.py
#
import marlin
board = marlin.env.BoardConfig()

address = board.get("build.address", "")
if address:
	marlin.relocate_firmware(address)

ldscript = board.get("build.ldscript", "")
if ldscript:
	marlin.custom_ld_script(ldscript)

@thinkyhead thinkyhead closed this Jun 2, 2021
@brianredbeard brianredbeard deleted the stm32-offset-address-fix branch June 2, 2021 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants