MySensors
MySensors copied to clipboard
Not all SAMD devices use external eeprom
Moved from #1066.
I am using a Moteino M0. A Moteino M0 uses a ATSAMD21G18 processor. When I try to run a simple serial gateway, I found during initialization when MySensors tries to write the parent node id to eeprom, the process hanges. I put debug statements before and after each line to isolate the place it hung. According to the SAM D21 datasheet, the eeprom is emulated. Here is the line where it hangs,
https://github.com/mysensors/MySensors/blob/3ae4fb657f82ec7c10a22a8dd8c334f9d8f1f4b4/core/MySensorsCore.cpp#L165
A note from Moteino M0 guide, https://lowpowerlab.com/guide/moteino/moteinom0/
The booloader is located in the first 8KB of internal flash memory and is protected by the NVM user byte fuse. There is no dedicated EEPROM on the SAMD21 microcontroller but EEPROM can be emulated up to 16kb and the Arduino EEPROM library can be used to access this emulated EEPROM.
I also found this arduino issue related to the eeprom on SAMD.
I think the current SAMD configuration was developed around the Sensebender-Gateway. Based on the BOM, the Sensebender-Gateway has an extra "32Kb (4096x8) Serial EEPROM with Unique Serial Number"
In my local copy of MySensors, I #ifdef wrapped the calls to hwRead/hwWrite and the gateway runs as expected. In the MyHwSAMD.h, there is currently no way to opt out of the external EEPROM,
https://github.com/mysensors/MySensors/blob/3ae4fb657f82ec7c10a22a8dd8c334f9d8f1f4b4/hal/architecture/SAMD/MyHwSAMD.h#L48-L50
In my case, I can think of the following options for persisting the configuration,
- Use the emulated eeprom
- Use external flash memory (Moteino M0 has an optional
- Do not persist the configuration
I would like some help coming up with a proposed solution that can be merged into the main MySensors. The very first thing that comes to mind is adding a new defines to define what kind of storage to use (eeprom, external eeprom, i2c / spi flash, none).
Yes, I was only focusing on using the external eeprom when I made the initial samd support, so emulated eeprom was never made.
We should support the emulated part, but as the emulated eeprom is done in flash, which has a reduced re-write count (compared to real eeprom), we should still keep the external eeprom as an option for gateways etc (which stores routing tables, and other "frequently updated" content in eeprom).
Right now coding time on mysensors is almost at zero, due to other projects that has higher WAF score :) but I'll be happy to do code reviews..