9 years, 4 months ago.

How to embed some text in the bin file

I want to embed some text in the bin file, things like the version, build date, etc. I'd prefer to place these at the end of the file so I know where to find them. In my good old 8051 micro days you could just use asm to db "some text". Any tips on how this can be done in the mbed online compiler would be appreciated.

Thanks, Peter

1 Answer

9 years, 4 months ago.

One of the ways is a declaration of absolute constant (eg in module main.cpp), as in examples :

volatile static const char Version[] __attribute__((at(0x08005000)))= "Version 3.5.1 "\
"Copyright (c) 2010-2015 of mine " "\x03\x05\x01";


or with the build date and time automatically entered by the compiler

volatile static const char Version[] __attribute__((at(0x0800fa00)))= "Version 3.5.1 "\
"Copyright (c) 2010-2015 of mine " " Date: " __DATE__ " Time (UTC): " __TIME__;

The address specified in this declaration can be any (virtually), as long as that was the correct address in the flash space. If you give the address greater than the current size of the normal code (maybe even before the end of the flash), these strings will be located at the end of binary file (almost), and before them linker will put fillers. But how to do that automatically, these strings are always at the end, I have no idea.

Accepted Answer