SpenceKonde / megaTinyCore

Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Other
564 stars 148 forks source link

EEPROM erased when programming #186

Closed pgwthf closed 4 years ago

pgwthf commented 4 years ago

Regardless of the "EEPROM (not) retained" setting, EEPROM is always erased when programming.

I change the setting to EEPROM retained and burn bootloader

I made a test sketch that reads an EE address and then writes a value to it.

When I upload this sketch it writes a value to EEPROM and reads 0xFF (which is correct) When I upload this sketch again, it reads 0xFF again (incorrect, it should be the new value). But if I power-cycle, all EEPROM is retained and the new value is correctly read.

System: OSX 10.14.6 Arduino 1.8.12 MegaTinyCore 2.0.2 Processor: ATtiny402 Programmer: Arduino Nano / JTAG2UPDI

SpenceKonde commented 4 years ago

Thanks for reporting. I will investigate - at first glance though, it looks like it should be setting the fuses correctly. You did burn bootloader with recent version of core, right? IIRC it wasn't that long ago that I fixed this, so if you burned bootloader a while back, that would explain it....

pgwthf commented 4 years ago

Hi Spence, immediately before reporting I downloaded the latest MegaTinyCore 2.02 and burnt bootloader (several times, with and without setting "retained"). Or are there other packages that should be updated, besides the ones I mentioned in the 1st post?

SpenceKonde commented 4 years ago

No. that's the one - I was just concerned that you may have burned bootloader a while ago setting it to be retained, then updated, and then noticed that uploading didn't retain eeprom, having never reburned bootloader.

I am currently up to my elbows in a different (exciting and promising) project, once I have my new version of jtag2updi working, I'll take a look at this

pgwthf commented 4 years ago

No worries, I know what the issue is, so I can work around it. Thanks for all the good work anyway!

SpenceKonde commented 4 years ago

I will say that I am somewhat alarmed to hear that it doesn't work as is though - like, I don't see an obvious reason for it not to be working

SpenceKonde commented 4 years ago

Moved this to next release. Have been getting complaints from more than one other person. I have a sense of forboding about this though... Cause like, the fuse is being set correctly. So why ain't it doing what the datasheet says it should?

My current most likely theory is - see there are 2 ways to do a chip erase - one is via a UPDI "key", and the other is by using UPDI to send that command via NVMCTRL. What if one of those ignored that fuse?

SpenceKonde commented 4 years ago

This seems to be working now. There were some issues in EEPROM library. I saw some whack shit with EEPROM address 0, but after some changes I cant reproduce that anymore. I did not EVER see the issue with the EESAVE setting being ignored. Note that you must burn bootloader to change it.