Can contents of PROGMEM (flash memory) be changed in runtime?
My goal was to store a ml model in progmem when flashing, and switch the previous
model to a new one while the microcontroller is running instead of having to reflash the device.
I can’t store the model inside the RAM because it is too big, so declaring the array in my main.ino would
be unfeasible.
How much space do you need for your model? An easier solution might be to use external NOR flash or FRAM to store it.
If your model doesn’t change frequently and you declare it as a constant, if I am not mistaken it will be stored in flash and not reside fully in RAM. I guess it would depend on the data structure though. I haven’t really delved much into that myself. You could update the model by OTA flashing new code that way.
There was an array that was stored in PROGMEM since the first version did not require an update of the ml model on the device itself. (was classifying same gestures in the same environment)
My intention was to move the model from PROGMEM to EEPROM since that space can be written/read from during runtime, I can receive a model from the cloud through sending multiple requests, string cutting, and atoi from cloud functions. The size is about 1750 ints/floats - 4 *1750 ~ 7000 bytes.
My guess is that because the EEPROM is only 2048 bytes, it cannot hold the model as big. Do you have any suggestions on how to overcome this hardware limitation?
One solution I am thinking of is just reflashing the particle through a serverside computer; after calculating the parameters of the new model, will update the header that once contained the model and send the cloud flash command to all the photons out onto the field. The problem with this approach, however, is that all the photons would need to be stopped at some point and it is unsure whether they will come back online.
The response I wrote earlier summarizes my problem in more detail.
I think I will want the model to be updated more often than never, and yes I am thinking about the OTA method as you mentioned. The data structure currently is just a simple float array. I believe due to the current way that the ml algorithm is calculating values, it will be difficult to change the structure of the array so it would be best to keep the size and structure.
As I mentioned in my reply, do you have suggestions other than the method I described above? I am not sure what to do now…
The EEPROM object uses wear leveling to “spread” the 2K over two banks with 16KB respectively 64KB (as the memory map shows).
So it would be possible but is not officially supported and hence even if you may be able to use the low level functions to directly write to that area it’s not guaranteed that this will work in future releases.
Maybe @rickkas7 can comment on that.