Pages: [1]   Go Down
Author Topic: Including a .hex file into C code (allocating memory for external hex file).  (Read 272 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 2
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am quite new to Arduino and have searched the forum and google for a way to include an external hex file into my C code.  My project will program external SPI memory devices.  I want to include the default programming into the AVR flash memory so I can read from the memory directly and load the contents to the external ee2 through the SPI port.  Is there an easy way to do this in the Arduino IDE?  My target board is a Due.  Thanks in advance for any assistance you can give.
Code:
#include <SPI.h>
#include <stdio.h>
#include <stdlib.h>


 


void setup() {
  // put your setup code here, to run once:
  FILE * pFile;
  long lSize;
  char * buffer;
  size_t result;

  pFile = fopen ( "C:\Documents and Settings\rway\My Documents\Downloads\extern_eep.hex", "rb" );
  if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

  // obtain file size:
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

  // allocate memory to contain the whole file:
  buffer = (char*) malloc (sizeof(char)*lSize);
  if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

  // copy the file into the buffer:
  result = fread (buffer,1,lSize,pFile);
  if (result != lSize) {fputs ("Reading error",stderr); exit (3);}

  /* the whole file is now loaded in the memory buffer. */

  // terminate
  fclose (pFile);
  free (buffer);

}

void loop() {
  // put your main code here, to run repeatedly:

}
Logged

Pages: [1]   Go Up
Jump to: