2025-12-19 6:19 AM
It happens to from time to time that I have a flashed project in a hardware, e.g. a bluepill, but I forgot which source project was belonging to it in the STM32CubeIDE's project treeview.
Is there a way to write the name of the project by means of some C-macro in text form into the program as kind of a signature or even more safely, compute a checksum of the flash binary and write that checksum into the program (yes I know, this may become tricky since the checksum alters the checksum itself :)
Is there a common technique for this?
2025-12-19 6:24 AM - edited 2025-12-19 6:29 AM
@chriskuku wrote:Is there a way to write the name of the project by means of some C-macro in text form into the program as kind of a signature
Sure there is - no need for macros; eg,
const char signature[] = "This is my Signature string";The string will be readable in flash.
Better yet, have your code write it out to a UART on startup.
PS:
You could locate that string at a specific address, to make it easier to find; eg,
Locate Constant Data in Flash at Fixed Address
https://stackoverflow.com/a/54128613
Defining Variables at Absolute Addresses with gcc
GCC Documentation: Specifying Attributes of Variables
2025-12-19 6:34 AM
The least I'm demanding is an automatism that gets the project name as a string. (similar to __DATE__,__TIME__, __LINE__,__FILE__ macros in C). Or some Makefile construct, that does something like "echo "const char signature =\" `echo $(PROJECT)` \";" >project.h".
2025-12-19 12:47 PM
@Andrew Neil wrote:
@chriskuku wrote:Is there a way to write the name of the project by means of some C-macro in text form into the program as kind of a signature
Sure there is - no need for macros; eg,
const char signature[] = "This is my Signature string";The string will be readable in flash.
No, it will not unless it is referenced in the program code. Normally all the non-referenced objects are removed during linking.
The solution is to use custom section name for the object and define this section in the link script with KEEP(). it may be put at the end of .isr_vector output section.
Code:
__attribute__((section(".my_sig")))const char sig[] = "My signature";Link script modification to put the signature in a fixed location, right after exception vector table:
/* The startup code into "FLASH" Rom type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
KEEP(*(.my_sig))
. = ALIGN(4);
} >FLASH