John Dews
John Dews

Reputation: 513

Flashing "Arduinos" In Production

So the issue I'm having revolves around programming a bunch esp8266 ESP-12 with ardunio code.

The main issue is that each esp8266 needs to have a token which allows it to authenticate with our server, however going through and changing token = ___ each time requires a full recompile and takes almost a minute from start to finish (which is a lot when flashing 1000's of boards).

In short is there a simpler way to include run time vars that doesn't involve recompiling the whole thing?

Upvotes: 1

Views: 417

Answers (2)

Julien
Julien

Reputation: 1910

You could put the ID into EEPROM but if you inly want to flash one file (Flash content) you can use static const uint32_t UniqueID __attribute__((section(".progmem"))) = 0x12345678; but you will not know the address in flash and it may change when you recompile. PROGMEM reference

You can also define a section to a known address in Flash (may be in the end of memory) I know this works with GCC but never tested in Arduino IDE.

static const uint32_t UniqueID __attribute__((section(".mySection"))) = 0x12345678;

Last solution is to simply define an address in the code where to read with pgm_read_*

The .hex file can then easily be modified with srec_cat to change the ID and then be flashed. This can be used in production to give unique ID to each chip.

Upvotes: 1

Pete Kirkham
Pete Kirkham

Reputation: 49331

I'm not familiar with ESP8266, but most MCUs you can do one or more of the following, depending whether the programmer allows programming parts of the flash separately or whether it has an externally programmable EEPROM:

  • put the token in EEPROM and program as an additional step to flashing the program memory
  • put it at a fixed memory location in program flash which is outside the main program, and program it as a second step using the offset for that location
  • open the compiled hex, find the token's offset in program flash and program those bytes only as a second step overwriting the default after the program has been flashed
  • open the compiled hex, find the token's offset, then before each module is flashed run a script to create a new hex with the token replaced, then program the flash in one go.
  • use a good default for the token which will not otherwise occur in the hex, then before each module is flashed use a search and replace script to create a new hex with the token replaced, then program the flash in one go.

Upvotes: 1

Related Questions