Programming a batch of devices with unique MACRO for each

Yes, but, if you allow that “Upload” is pressed multiple times, for each device once, you can execute Python logic that reads the current device name (or a counter) from a file and injects that as a macro in the build process. (See first example script).

You can also use dynamic variables to reference an environment variable. A batch or shell script can then, in a loop, set the environment variable to some value and call pio run -t upload normally.

build_flags =
   -DDEVICE_NAME=${sysenv.DEVICE_NAME} 

plus some batch scripting.

All of this however requires a recompilation of the project. If that is unacceptable, one can also do a faster hack: Build the executable once with an arbitrary DEVICE_NAME, say "DEVICE1", and you get a firmware.bin that contains that string.

You can then find the location in the binary where that string is stored and overwrite it with something else of the same length. That doesn’t break the binary. Once the .bin file is modified you can either use PlatformIO to upload it (Upload Latest build without a Compile/Link - #4 by ivankravets) or a manual upload invocation with the modified binary as PlatformIO would do (that can be inspected with pio run -t uplaod -v).

1 Like