Jump to content
daem0n

EK-TM4C123GXL - store data into FLASH/EEPROM

Recommended Posts

Hello!

 

I am using Energia to program TM4C123GXL board. The program performs a primitive data acquisition with low frequency and stores it (together with timestamps) as an array in RAM.

 

I would like to store data in EEPROM or, preferebly in FLASH. Micro-controller has 256kB flash. How can I save data there?  There is flash API (flash.h and flash.c) in lm4f/driverlib/ though I am not sure even at which address range I can write/erase data?

 

Can anybody point out to a working  example?

 

thanks for help!

 

 

Share this post


Link to post
Share on other sites

There is a small EEPROM you can use.  While flash is technically reprogrammable, you must also doctor the linker scripts used to build the firmware to avoid using the segments of flash you need, and that's not really possible with Energia.  The EEPROM functions should be available via driverlib for your purposes though.  It's not a whole lot, maybe 2KB on the TM4C123 I think?

Share this post


Link to post
Share on other sites

Well, I've came back to flash option with still using Energia. I need to know from which address (segment) I can safely erase/write? So, I made a little investigation by implementing a simple memory printout (PrintFlash) aka hexdump utility as following (note, that in TM4C123 the flashrom is accessible from 0x0 to 0x3FFFF directly pointed by blk_adr):

void PrintFlash() {
  uint32_t i, j, blk_adr;
  tFlashProtection fx;
 
  Serial.println("\nPrinting FLASH permission map.");
   
  for(i = 0; i < 255; ++i) {
    blk_adr = i * 1024;
    //
    fx = FlashProtectGet(blk_adr);
    
    Serial.print("@");
    Serial.print(blk_adr, HEX);
    Serial.print("\t");
    switch(fx) {
      case(FlashReadWrite):
        Serial.println("Flash can be read and written!");
        printHexBytes((byte*)blk_adr, 1024);
        break;
      case(FlashReadOnly):
        Serial.println("Flash can only be read!");
        printHexBytes((byte*)blk_adr, 1024);
        break;
      case(FlashExecuteOnly):
        Serial.println("Flash can only be executed!");
      default:
        Serial.println("Unknown tFlashProtection value!");
    }
  }
}

void printHexBytes(byte *adr, uint32_t n) {
  uint32_t i, j, k;
  const int deflen = 16;
  char c;
  char str[deflen];
 
  //Serial.println("");
  for(i = 0; i < n;) {
    //Serial.print("\t");
    Serial.print((uint32_t)&adr[i], HEX);
    Serial.print("\t");
    for(j = i, k = 0; j < (i + deflen); ++j, ++k) {
      c = (char)adr[j];
      if(c < 16)
        Serial.print("  ");
      else
        Serial.print(" ");
      Serial.print(adr[j], HEX);
      if(c >= 32 && c <= 126)
        str[k] = c;
      else
        str[k] = '.';
    }
    i += deflen;
    Serial.print("\t");
    for(j = 0; j < deflen; ++j) {
      Serial.print(str[j]);
    }
    Serial.print("\n");
  }
}

I've printed out whole 256K space. Just be sure to have >9.6K serial speed to avoid a long long waiting time. An important point for me is to find the end of the flash memory used by system, something like:

...
2FD0      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0    ................
2FE0      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0    ................
2FF0      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0    ................
@3000    Flash can be read and written!
3000      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0    ................
3010      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0    ................
3020      0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0    ................
3030      0  0  0  0  0  0  0  0 18  8  0 20 FF FF FF FF    ........... ....
3040     FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF    ................
3050     FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF    ................
3060     FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
...

Unsurprisingly, the magic series of FF starts from the address 0x303C which is the same as the length of the of the binary sketch produced by Energia as seen at the end of successful compilation:

...
Binary sketch size: 12 348 bytes (of a 262 144 byte maximum)

My binary sketch will certainly not exceed 15-20 kBytes. So, I hope that flash memory within the space of 20..256k can be used by my data logger. That is very encouraging and will let me store lots of data including even a 4-byte timestamp in milliseconds. I will use a statically defined memory offset pointing to the first flash segment which my code can safely use.

 

The only question is, how fast is the erase/write operation for, say, 1kB block? Though it might be not that critical for me because my data logger is called by the timer interrupt and there are plenty of idle cpu cycles in the loop(). I will check it soon...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×