LowPowerLab Forum

Hardware support => Moteino => Topic started by: polychronis90 on January 26, 2015, 09:25:48 AM

Title: Dual Optiboot intel hex flash data format/transfer problem (atmega1284P)
Post by: polychronis90 on January 26, 2015, 09:25:48 AM
Hello,

I recently started using the Atmega1284p for a custom project and found the DualOptiboot from Felix, which was exactly what i needed. For some time i have been trying to use the custom circuit that i have on the breadboard and i had some problems with the Serial RX. I finally solved this problem by changing the Low Fuse to F7 when burning the bootloader and havent had any problems since.

What im trying to do now is to use the Bootloading from Flash capability but i havent been successfull yet. I can't use any of the libraries that Felix has provided nor the python script. So i have written my own script and my own arduino code. What i want to know is how should the bytes be saved in the flash? Im using the SPIFlash library to read/write bytes to the flash. But i dont know in what format am i supposed to save them.

I need an example. For example when i read from my .hex file "0xCB" should "CB" be saved in one byte of the flash or in separate bytes 0x0C and 0x0B (i have tried both of them). Also should it be saved as a HEX or as something else (the python script sends it as a charater i think, but i have managed to save them in both formats.)

Any help is much appreciated

PS: Im saving FLXIMG:u_int16_length_2bytes:XXXXXXXX.....XXXX.
Title: Re: Dual Optiboot Problem/ 1284p!
Post by: Felix on January 26, 2015, 09:38:00 AM
First you have to understand the intel hex format (http://en.wikipedia.org/wiki/Intel_HEX). The address data is big endian. Each record data byte is represented by 2 ascii bytes in the hex file. So you have to do some work on the data before you can dump it in the flash chip. There are several threads in the forum discussing similar efforts, a search is worth it.
You can look at the code (https://github.com/LowPowerLab/WirelessProgramming/blob/master/WirelessHEX69/WirelessHEX69.cpp) how the binary file is transferred to flash, that is working code that is the best "documentation" there is right now.
Also the wireless programming blog category (http://lowpowerlab.com/blog/category/moteino/wireless-programming/) is worth a look/read.
Title: Re: Dual Optiboot intel hex flash data format/transfer problem (atmega1284P)
Post by: polychronis90 on January 26, 2015, 09:51:42 AM
Thanks Felix for the quick response,

I will look further into the subject, because i dont have much experience.

I just want a quick pointer. When i have say this line on my .hex file (:100C94) In order for the bootloader to work this should be saved in the flash like this? "10.0C.94" (where the dot represents the separation between flash(0),flash(1),flash(2), also using your SPIFlash library example to dump the output).  of something else?

I have seen your code for the wirless programming and the wireless_programming.py but i dont have any rfm modules to check the other libraries. Im just transfering the data through serial character by character ("C"+"B") or byte by byte ("0xCB"). and i cant find the correct format and im banging my head for days.

Thank you in advance
Title: Re: Dual Optiboot intel hex flash data format/transfer problem (atmega1284P)
Post by: Felix on January 26, 2015, 10:21:18 AM
:) ....... basically you're asking for a shortcut. I don't really have one except the links I included. The data is in order, the addresses are not, you have to reverse them, then write the bytes in order. You could actually ignore the addresses if you can assume the bytes are all in order and there are no address gaps.
Each record has a record type field. You have to look for that in each record, make sure it's a data record type before you write it. You have to transfer each 2 ascii bytes as 1 binary byte. So 0xCB = 203 (decimal, or 11001011 binary byte). You have to have the right header signature and the byte count in the header. Look at the dualoptiboot code, that is plan and clear what i expects and how the data is read from the flash. Good luck.