Go Down

Topic: Atmega Self programming (Read 131 times) previous topic - next topic

chippevijaya

I am new to atmel family ... I am looking for a feature as Atmel Image(hex file) in the external EEPROM(I2C) and make a bootloader(of ATMega8) capable of self programming from the EEPROM and execute the sketch/program.

If any one gone with this kind of feature please help me.

I am using ATMega8 connected to EEPROM. and every time new hex file updated to EEPROM.

Koepel

I think that is not possible. The bootloader would have to include I2C code, and that would make it big.
The most used bootloader is OptiBoot : https://github.com/Optiboot/optiboot/

Here is a topic about it : https://forum.arduino.cc/index.php?topic=169988.0

Tell us about your project. Perhaps there are other (and better) ways to achieve your goal.

CrossRoads

How does the EEPROM get loaded?
Bootloader sizes of 256 bytes, 512 bytes, 1K bytes, and 2Kbytes are supported.

How much of the Atmega8's 8K of flash is needed to access the external EEPROM?
- 8KBytes of In-System Self-programmable Flash program memory
- 512Bytes EEPROM
- 1KByte Internal SRAM


Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

musskopf

Got a similar setup, but using an external 4Mbit SPI Flash, mainly because of speed and size. But should be very similar using I2C.

The basic idea is to have the "Main program" responsible for storing a new firmware into the SPI Flash, in my project the new firmware is sent over-the-air (RF) from a base node. After the new firmware is received and verified a few parameters are stored on a dedicated area of the MCU EEPROM.

Every time the MCU boots the bootloader will read the MCU EEPROM, looking for a new firmware configuration on the same dedicated are, including which address and size the new firmware is stored in the external SPI Flash. If everything is ok the bootloader will run a few CRC checks before and start programming. If no EEPROM info is found, the process logs the error and restart, which will fall-back to the standard Serial Port programming.

The operation result, being an error or success gets logged back into the MCU EEPROM, so the main program will know what happen after the next reset. It happen only once per "new firmware", so the bootloader won't try indefinitely to install the firmware, avoiding to keep writing to EEPROM every boot.

I also included a feature to "factory reset": If the board is powered while holding a button for a few seconds, it check a reserved area of the Flash and, if there's a valid image there, it writes to the board. The "factory firmware" in this case is a "Main program" capable of receiving and storing a new firmware, in other words, you would never need to connect the board to a PC again to program.

All of that is running on top of the OptiBoot and takes around 1.6K and there's probably room for a few optimizations, I just decided to keep the code more readable. The project is based on Atmega328P, so 2K is not that much compared to the functionalities you get. To keep size small, the code doesn't use any Arduino libraries, just a few from the AVR Libc.

Advanced features like, reverting the previous/factory firmware in case the new image is broken, or the new Main Program is unable to contact the base station is also possible.

If you're interested the code for this bootloader and additional documentation, everything will be release very soon, as part of a board launching I'm organizing. You can get more details of those links https://bitbucket.org/talk2/whisper-node-avr/overview and https://talk2.wisen.com.au/product-talk2-whisper-node-avr/

Cheers

http://talk2.wisen.com.au

chippevijaya

Hi Koepel, CrossRoads

Thank you guys for reply...sorry for my late reply...

   As of now my thought of project is as shown in below flow
   
   ESP8266 will receive latest hex file from the WiFi and stores into external EEPROM and it will send a update command to ATmega8. ATmega8 will initiate soft reset, and updates the hex file from eeprom (bootloader) and performs self flash. 
   
   I have no choice, I have to try code size of bootloader as minimum as possbile to fit in bootloader area along with I2C. I will take care of hex file should not reach the beyond capacity of external eeprom and ATmega8(8kBytes).
   
   EEPROM is as of now only hex file holder only, No other contents I am going to load in this.
   
And Hi musskopf,
   
   Thanks a lot for your project...It looks more similar to my plan. I try with your references and will update you once I get any update.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy