atmega328P losing flash

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
toddkuen
 
Posts: 6
Joined: Fri Aug 16, 2013 11:06 am

atmega328P losing flash

Post by toddkuen »

I purchased three ATMEGA 328P-PU chips from Adafruit last week.

I have a AVRISP mkII programmer that works for a variety of other chips I have (ATMEGA 328P-PU's and 32u4's). I program the 328P's on a couple of Arduino UNO boards I have - one newer (R3) purchased in the last month or so, one a couple of years old.

(BTW - the original 328P from the older board also exhibited this problem.)

In any case I can Flash the chips I just bought with the AVRIPS mkII via AVRStudio 6.1 Tools > Device Programming. It sees the chips correctly, reads the code back, and flashes and verifies without error (I think all the settings are right, i.e., the programming dialog matches the chip type, etc.)

I also have the "erase before programming" checked and the programmer verifies the programming correctly each time I burn the chips.

I burn amforth into the chips and what happens is amforth will run for any where from not at all to about 20 minutes. Then forth fails and the AVRISP programmer reports Flash verification errors when I use the "Verify" option in Tools > Device Programming. The failures look like bit rot because the forth will first start misbehaving and then go bad and it works as long as verification is good. Smaller programs exhibit the same behavior though tend to work better and longer.)

On the "good" chips the identical burn works and sticks - though I did have some trouble on a 32u4 that I fixed by re-burning a few times.

Do the ATmega chips go through runs of "bad" chips like this or is there some settings I don't know about???

As far as I can tell the programmer is set up right, etc.

I am not yet convinced the chips are "bad" but I will become so if no one has any other ideas about something I might be doing wrong.

User avatar
toddkuen
 
Posts: 6
Joined: Fri Aug 16, 2013 11:06 am

Re: atmega328P losing flash

Post by toddkuen »

I have gotten one of the chips to work by turning down the "programming speed" from 125K to 64K...

Not sure what this means but perhaps its something to do with the Arduino board design not working with the ISP??

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: atmega328P losing flash

Post by adafruit_support_bill »

Hmmm. I've never experienced that problem. I'll check with some of the other engineers.

User avatar
toddkuen
 
Posts: 6
Joined: Fri Aug 16, 2013 11:06 am

Re: atmega328P losing flash

Post by toddkuen »

Two of the "problem" chips are now working and seem to stay working - only been running them for about 18hrs but it looks much better than it did so far...

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: atmega328P losing flash

Post by adafruit_support_rick »

Can you upload a "bad" flash and manually compare? (Not necessarily suggesting a byte-by-byte comparison, unless you've got a tool which will do that. Maybe look for a page that's reverted to FF, or something like that...)

I've had similarly bizarre flash problems with an 8051-derivative processor, but I've never seen it with Atmel.

User avatar
phild13
 
Posts: 247
Joined: Mon Sep 10, 2012 1:05 pm

Re: atmega328P losing flash

Post by phild13 »

The trouble programming the chips from Adafruit may be because the atmega328p's purchased from Adafruit have a Arduino bootloader already on them. The Arduino uses an external 16 MHz oscillator, so an ATmega328p with an Arduino bootloader (such as from Adafruit) are configured to use an external 16 MHz oscillator. New bare chips that don't contain a bootloader are configured to use the internal 8 MHz oscillator and can be properly programmed using a programmer. The easiest way to reprogram chips that have the bootloader already on them put them in an Arduino Uno or such and reprogram the fuse settings to use the internal 8 MHz oscillator.

See this post for a bit more info. http://forums.adafruit.com/viewtopic.ph ... 24#p184813
The poster jarchie has programmed the proper fuse settings and a "make install-fuse" will run just the reprogram fuse part in his xmas-icetube clock firmware. Github link to the firmware https://github.com/johngarchie/xmas-icetube

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: atmega328P losing flash

Post by westfw »

I burn amforth into the chips and ... Then forth fails and the AVRISP programmer reports Flash verification errors when I use the "Verify" option in Tools > Device Programming. The failures look like bit rot ...
AMForth uses bootloader-like code so that it can burn user-defined words into flash, so it's not unexpected that flash contents would change and fail verification "after a while." This also means that a misconfigured or buggy copy of AMForth, or a particularly badly behaved Forth user program could corrupt the flash entirely (leaving it non-working.)

I didn't experiment with AMForth more than to get it running, and that was a few years ago (and there have been a bunch of edits over that time), so I don't know if there are any "known" common ways that user manage to shoot themselves in the foot. But IMO, it's much more likely that the flash is being actively damaged, rather than "losing" the initial contents due to a failure of the ISP programmer or initial programming. (Unlike SOME programmable components, the AVR does not have any options where it would become "weakly programmed.")

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: atmega328P losing flash

Post by adafruit_support_rick »

westfw wrote:AMForth uses bootloader-like code so that it can burn user-defined words into flash
:shock: :shock: :shock:
Wow. I think we have our smoking gun. Thanks!

User avatar
toddkuen
 
Posts: 6
Joined: Fri Aug 16, 2013 11:06 am

Re: atmega328P losing flash

Post by toddkuen »

No, I never store any forth values or words in my tests - just run it at the command prompt and print numbers, e.g., "0 ." or something like that. I fully expect a problem with the compare if I store values into flash or eeprom.

I could not even get to the startup prompt sometimes.

In any case the flash is now sticking with the Flash rate turned down to 64kHz. So I think the default value of 128kHz is too fast, at least for the Arduino board and/or 328P's I am using.

It was my problem in believing the default AVR settings for device programming were correct.

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: atmega328P losing flash

Post by westfw »

This is the same problem being discussed on avrfreaks here: http://www.avrfreaks.net/index.php?name ... c&t=135538
Where the latest theory is that Atmel Studio is not behaving "predictably" with respect to burning fuse values. Right?

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”