I have a question regarding custom upload options:
I’d like to have different serial numbers on my devices which should be located at a specific flash location on my STM32L device (e.g. max_flash_addr - 2KB or similar). These values can be later read when the program is running.
With OpenOCD commands (program with a specific address and .bin file of arbitrary content) you can then write to these addresses. For this you can create a custom target that triggers this write, or implement a fully custom upload method that flashes both firmware and some custom binary blob (Redirecting...).
PlatformIO doesn’t have the STM32CubeProgrammerCLI as a package, so you will have to do manual work to get that in the PlatformIO system. The easiest way is to use the already existing OpenOCD package. That’s the most direct and portable way.
I read through all the material you posted and modifying the linker script seems valid way to make sure a certain area at the end of the flash memory is reservered.
You’re right, it makes sense to use an modified OpenOCD upload. I’m just not 100% sure where to start. Which Platformio script controls the upload process and how can I substitute that script to make OpenOCD write variables into the flash on upload?