How to clear flash / wear leveling ?

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I am working with avrdude under Linux.

 

I want to clear that portion of the flash, which contains the program code without clearing the bootloader (which is a boards vendor own product it seems).

Doing this I dont want to fiddle with fuses and lock bit for this time (fear of a newbie... ;)  )

Targets are an ATmega328p (3.3V,8MHz) and an ATmega2560 (5V,16MHz).

As I understood the manpage, avrdude -e clears the whole flash including the bootloader...

How can I do this?

 

Another question:

Does the flash of ATmega MCUs have a wear leveling as used with USBsticks and other flash media?

 

Thank you ver much in advance for any help!

Cheers

mcc

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The AVRs have NOR flash rather than NAND flash that is used in the likes of sdcards and usb sticks. NOR doesn't require wear levelling (at least to nowhere near the same extent as NAND).

As for 'clearing' the flash, create a bin or hex file with 0xff's and flash that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As for 'clearing' the flash, create a bin or hex file with 0xff's and flash that.

Using the bootloader.  ISP programming doesn't have any "partial erase" capability.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you use the bootloader, the chip erase command will erase only the application code, the bootloader remains untouched.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

 

thanks for the input! It looks like it could be done by simply send "chip erase" to the bootloader instead of via ISP.

 

Is this correct (better to ask first than to loose the vendors bootloader afterwards... ;) ):

 

1) connect the board via USB->Serial adapter

2) use avrdude -e?

?

 

Cheers.

mcc

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The correct process should be in the board manufacturers documentation

 

It should not be possible to erase the boot loader if you are correctly using the boot loader to program the device.

 

if you were to specify which board you were using some MIGHT* be able to help

 

*if they have used that particular board in the past

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

the boards are to simple as to come with any more advanced docs.

 

The one board is:

Inhaos MEGA2560 CORE

Vendors site and product: http://www.inhaos.com/product_in...

Docs: http://www.inhaos.com/downcount....

 

The others are:

http://www.robotdyn.com/catalog/...

http://www.robotdyn.com/catalog/...

Doc at the bottom of the page each.

 

Cheers

mcc

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is really no need to erase the flash when using the bootloader, just upload your new code!

If you erase the flash via isp, it will erase all of the flash including the bootloader, no way around that, that I know of.

Just use the bootloader and enjoy!

 

Jim

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe Xmega have the ability to just erase app or boot sections independently - presumably a feature introduced to address this thread? I guess there new Xtiny things have inherited the same? (or do they even have boot support?)

 

BTW if the original question is really about putting an app and a bootloader into a chip at the same time then use srec_cat to join two hex and program as one.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Those appear to be Arduino clones, so if the bootloader is lost when programming via isp, just reload the bootloader following standard Arduino methods, i.e. use the Arduino IDE to burn the bootloader to return to normal use again.

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you use the bootloader, the chip erase command will erase only the application code, the bootloader remains untouched.

Except that avrdude ignores pages containing only 0xFF.  It doesn't even pass those pages onto the programmer/bootloader.

 

$ avrdude -p atmega328p -c arduino -P /dev/ttyACM0 -b 115200 -e -U flash:w:ff.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: erasing chip
avrdude: reading input file "ff.hex"
avrdude: input file ff.hex auto detected as Intel Hex
avrdude: writing flash (0 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 0 bytes of flash written
avrdude: verifying flash memory against ff.hex:
avrdude: load data flash data from input file ff.hex:
avrdude: input file ff.hex auto detected as Intel Hex
avrdude: input file ff.hex contains 0 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 8.61s

avrdude: verifying ...
avrdude: 0 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

The file ff.hex contains a full-size (32256) image with all bytes 0xFF.  Note how avrdude reports the size as 0 bytes, and programming takes 0.00 seconds.  The verify operation proceeds, but succeeds even though the images don't match.  This would seem to be a shortcoming.  I can find no avrdude option which would change this behaviour.

 

It looks like it could be done by simply send "chip erase" to the bootloader instead of via ISP.

The bootloader has to support that.  The most common bootloader, Optiboot, doesn't.  It silently ignores chip erase commands.  Which bootloader are you using?  The Pro-mini clone product page suggests it is using a larger bootloader, perhaps one which does honour the chip erase command.  The other pages make no mention of which bootloader is used.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Wed. Sep 20, 2017 - 03:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Pro-mini clone product page suggests it is using a larger bootloader, perhaps one which does honour the chip erase command.

All of the Arduino bootloaders ignore the "chip erase" commands, assuming that they will erase each individual page before re-programming.