Hello all,
I am trying to understand the hex file and the way it is written in controller's flash memory.
As per now, I have been following
AVR In system programming guide & and Atmega328/8's Datasheet.
- I am using Blink.cpp.hex thus generated by compiler(using Arduino only).
- I am trying to read the flash memory contents of Controller.
I have made this tentative code to access the flash memory contents. I am pretty sure that the code is working as I have the modified program for reading EEPROM memory as it is verified i.e. it is entering programming mode and I am able to get the fuse bytes and everything else.
void read_flash(int blocks)
{
unsigned char counter=0;
unsigned long address=0;
Serial.print("Reading whole Flash\t");
Serial.println(" ");
byte array[4]={0};
unsigned int address_m=0;
unsigned int address_l=0;
for(address_m=0;address_m<blocks;address_m++)
{
address=(unsigned long)address_m*256+address_l;
Serial.print(address,HEX);
Serial.print("\t");
for(address_l=0;address_l<256;address_l++)
{
array[0]=SPI.transfer(0x28);
array[1]=SPI.transfer(address_m);
array[2]=SPI.transfer(address_l);
array[3]=SPI.transfer(0);
Serial.print(array[3],HEX);
array[0]=SPI.transfer(0x20);
array[1]=SPI.transfer(address_m);
array[2]=SPI.transfer(address_l);
array[3]=SPI.transfer(0);
Serial.print(array[3],HEX);
Serial.print(" ");
counter++;
if(counter==16)
{
Serial.println("");
counter=0;
address=(unsigned long)address_m*256+address_l;
Serial.print(address,HEX);
Serial.print("\t");
}
}
}
}
I would like to see that exact hex file or the data in it, that I may see using the "hexdump" or "xdd" command on terminal and match that content by reading the Flash memory of MCU.
Attached are the images for what I am getting by now. Kindly help me out as I am not able to endorse the thing.
Plz. do rectify me if I am wrong in the way.