1

I've been using ESP-IDF for quite some time and there is default option to use text file as a version provider. Which is compiled into a code and available at runtime.

  1. I wish to do the same on STM32, so whenever I change the file content (which is project version string "v0.000") its gonna be compiled into FLASH section that I've created.

version.txt

    v0.000
  1. I wanted to include that file using symbols but I just dont know how to...
  • -d
  • All Iam getting is the PATH to file. Maybe there is a way to use that path, to read from file at this point?
  1. For now I am convering string into a word (uint32) and specify that in my main.c

main.c

    const uint32_t version[] __attribute__((section(".version"))) = {
        0xC0FEBABE, 0x76302E30, 0x30300000
    };

FLASH

    .version :
    {
        KEEP(*(.version))
    } >FLASH
Coffeeye
  • 31
  • 6
  • 1
    Can you change the content of the file to hold a C string literal including the quotes: `"v0.000"` ? Then you could just do something like `const char version[] __attribute__((section(".version"))) = \r #include "version.txt" \r ;` – Gerhardh Apr 21 '23 at 13:10
  • 1
    It's often a sensible solution to run a script pre-compilation which generates the .c source file. All IDEs should support this so it's a fairly portable way of solving the problem, without dragging all manner of platform-specific tricks into your source and/or linker script. – Lundin Apr 21 '23 at 13:54
  • @Gerhardh Sorry for late response, I have used your solution but it functions as a workaround. It's becouse I need 0xC0FEBABE to be written at compilation time. Usint your way All I get is an ASCII string – Coffeeye May 08 '23 at 09:24
  • I've just added `const uint32_t version[] __attribute__((section(".version"))) = 0xC0FEBABE` to my code after include version.txt (noted that compilator needs correct order) And there goes a question. Is this relevant ? and certain ? – Coffeeye May 08 '23 at 10:04

0 Answers0