Pico crash/reboot on EEPROM.put() #1479
-
Hi, My Settings object uses a struct "_Settings" to store misc settings in NVram, using the Arduino-Pico EEPROM emulation. It looks like this:
And this has worked through several versions of that Settings struct. But today, after I've modified the struct, all further calls to EEPROM.put() seem to cause my Pico to restart. (I only see the first line "going to put settings", then it reboots.) The new struct "s" is much like the old struct, but with a new boolean member & a 32-bit integer changed to 16-bit.
Is there some reason why EEPROM.put() would choke on this structure? Could some content of the variables themselves cause this? Is there a size limit? Any other gotchas? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 14 replies
-
Can you make an MCVE (minimal sketch to reproduce)? That would help others to look into it. |
Beta Was this translation helpful? Give feedback.
-
Working on it. For the record, tho: does calling EEPROM.put() from core 0 require that core 1 be available? I have presumed not. But in my getting-more-minimal sketch it appears that even if setup1() and loop1() are both empty, pausing core 1 gives me the bug, whereas allowing core 1 to run does not. If EEPROM.put() uses both cores, that would be one explanation. |
Beta Was this translation helpful? Give feedback.
-
MCVE: https://github.com/myklemykle/syncmaker_EEPROM_troubles |
Beta Was this translation helpful? Give feedback.
-
OK, I've replaced that idle & restart strategy with having setup1() wait to start until setup() signals its done via the FIFO. With that, everything seems to be working. I don't even hear any skipped samples during the write. Thank you for elucidating all this. It still looks to me that doing either freeze&continue or freeze&restart of core1 during setup() can cause EEPROM.commit() to be flaky later on. If that's not expected behavior, I can try again to get a smaller working example of the problem. If it is expected behavior, I'd like to add it to the docs. |
Beta Was this translation helpful? Give feedback.
-
FWIW, in the end this turned out to be a really basic out-of-memory problem. When I reduced memory allocation elsewhere in my sketch, the problem went away. So it wasn't really related to EEPROM flashing at all, except that EEPROM routines apparently use RAM. |
Beta Was this translation helpful? Give feedback.
No, the exact opposite. As a user you can run your own
setup1/loop1
and never ever callrp2040.idle/resumeOtherCore
and write to flash via EEPROM or LittleFS. The Arduino core plumbing here does all that for you. In fact, I'd say 99.999% of users should never callrp2040.idle/resumeOtherCore
.If you try and freeze the other core while it's already frozen (i.e. if you called
rp2040.idleOtherCore
in yoursetup()
and then tried to do anEEPROM.commit()
, then the commit would wait forever since core1 will never respond to the interrupt...).