STM32CubeIDE Projects: How to add textural version no and date to project binary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-09-30 3:31 AM
Hi,
I have small headless firmware and wish to include a version constant in the Binary image so I can determine the version when using the debugger.
It's easy if your project has a display, but I can't figure out an easy way of doing it for a simple system. If I put a string constant in main.c the linker doesn't include it as the string isn't used anywhere.
Does anyone know of an easy way to do this with an example?
Regards
Rob
Solved! Go to Solution.
- Labels:
-
Documentation
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-09-30 8:29 PM
Hi,
I figured it out:
main.c
static const char version[] __attribute__((used)) __attribute__((section (".version"))) = "Ver: V2.0.0 01/10/2023 13:27";
Linker Script
...
/* Version Data Into Flash */
.version :
{
. = ALIGN(4);
KEEP(*(.version))
KEEP(*(.version*))
. = ALIGN(4);
} >FLASH_CODE
 All good
Regards
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-09-30 4:12 AM - edited ‎2023-09-30 4:14 AM
The quickest way is to make a reference to this string somewhere in code or data, so that compiler or linker cannot tell that it is unused.
If you have more time see this thread (about the linker, custom sections, KEEP...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-09-30 8:29 PM
Hi,
I figured it out:
main.c
static const char version[] __attribute__((used)) __attribute__((section (".version"))) = "Ver: V2.0.0 01/10/2023 13:27";
Linker Script
...
/* Version Data Into Flash */
.version :
{
. = ALIGN(4);
KEEP(*(.version))
KEEP(*(.version*))
. = ALIGN(4);
} >FLASH_CODE
 All good
Regards
Rob
