This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541 flash memory

Other Parts Discussed in Thread: CC2541

Hi,

I am trying to store some data from one of the sensors interfaced with CC2541 on the flash memory. I am not sure how much memory space is remaining in the flash memory though.
In the .map file, at the end, it says that I have 14643 bytes remaining.

112 333 bytes of CODE memory (+ 14 643 range fill )
35 bytes of DATA memory (+ 77 absolute )
6 887 bytes of XDATA memory
194 bytes of IDATA memory
8 bits of BIT memory
569 bytes of CONST memory

However, I am using CC2541 with 256KB flash memory and if we do the maths, ((256*1024) - 112333 - 35 - 6887 - 194 - 1 - 569), we get 142125 bytes.
Can someone please explain where am I going wrong?

Also, this data, "END OF CROSS REFERENCE" seems to differ with the "MODULE SUMMARY". Not being able to understand why this is.

126 842 bytes of CODE memory
35 bytes of DATA memory
6 887 bytes of XDATA memory
194 bytes of IDATA memory
8 bits of BIT memory
569 bytes of CONST memory

  • Hi,

    Since you get the + XX range fill, it seems like you are using a linker file that limits you to ~half the flash. Are you using OAD or something?

    How do you plan to log this to the flash? You would need to either use the SNV interface (not recommended for this type of thing), or HalFlashWrite + HalFlashRead. However, if you use the latter commands, you must also - in the linker file - reserve some space for your log.

    Best regards,
    Aslak
  • Hi Aslak,

    Yes, I am OAD in the application.
    I was hoping to use HalFlashWrite + HalFlashRead but logging doesn't quite make sense to me if only ~14KB of storage is available. So, can you please confirm if that is the case?
  • Yes, if you use OAD, the flash is split into 2 halves, each containing a full run-time image. So you will only have whatever is left over for both halves.

    BR,
    Aslak
  • Hi Aslak,

    Thank you for the confirmation. I am trying to use the HalFlashRead/Write api, but I am not being able to understand what changes are to be made in the linker file. How do I know what memory location is available to write the data in?

    Also, in the post,   https://e2e.ti.com/support/wireless_connectivity/f/538/p/276601/1214414#1214414 you mention that the flash area, reserved for OAD can be used to store data. I understand that this space will be erased / overwritten while performing the OAD update. How do I understand what part of flash memory is reserved for this, and what changes are to be made to which linker file to be able to store data in the flash memory? 

    Thanks a lot!

  • Hi,

    Look at the OAD guide - it explains how to change the linker file etc so that you take some space from ImgA and give it to ImgB.

    If you want to reserve some space in the OAD linker files, it's actually pretty simple. You will notice that ImgA's linker file doesn't include the space above 0x7E7FF, meaning bank 7, 0xE800-0xFFFF, or 3 pages, which are SNV1+2 and the page with the lock-bits.

    You would have to change both the liker files in order to reserve even more space. The easiest is perhaps to just keep stealing from Bank 7 in ImgA, and then give back half the stolen images to ImgA's Bank 4, and remove a like amount of pages from ImgB's Bank 4.

    Until you have taken away an entire bank, you only need to modify the -D_BANKn_BEG/END= defines. You also need to modify oad_target.h to change where the images start/stop, and their size. Otherwise OAD will download into the wrong area, and will also perform CRC checks over the wrong area.

    There's also some information in this post  , but I'm not sure it applies to you, as the const area is not shared between OAD images.

    Best regards,
    Aslak

  • Hi,

    I am now being able to write to the flash, but still facing some problems. Below is the code for reference. 

    #define GET_FLASH_PAGE(bank, addr) ((((unsigned int)addr >> 11) & 0xF) + 16 * bank)
    
    #define GET_FLASH_PAGE_OFFSET(addr) ((unsigned int)addr & 0x7FF)  
    
    #define GET_FLASH_WRITE_ADDR(bank, addr)  ((GET_FLASH_PAGE(bank, addr) << 9) + (GET_FLASH_PAGE_OFFSET(addr) >>2))
    
    #define FLASHSIZE 255
    
    
      int32 addr = 0x68000;
      uint8 writebuffer[FLASHSIZE];
      uint8 readbuffer[FLASHSIZE];
      uint8 i = 0;
      
      for (i=0; i<FLASHSIZE; i++)
        writebuffer[i] = 0xaa;
      HalFlashErase (GET_FLASH_PAGE(6, addr));
      HalFlashWrite (GET_FLASH_WRITE_ADDR(6,addr),writebuffer, sizeof(writebuffer));
      HalFlashRead (GET_FLASH_PAGE(6,addr), GET_FLASH_PAGE_OFFSET (addr), readbuffer, sizeof(readbuffer) );
      addr =addr + sizeof(readbuffer) ;
    
      for (i=0; i<FLASHSIZE; i++)
        writebuffer[i] = 0xbb;
      //  HalFlashErase (GET_FLASH_PAGE(6, addr));
      HalFlashWrite (GET_FLASH_WRITE_ADDR(6,addr),writebuffer, sizeof(writebuffer));
      HalFlashRead (GET_FLASH_PAGE(6,addr), GET_FLASH_PAGE_OFFSET (addr), readbuffer, sizeof(readbuffer) );
    
    

    Here, I am facing problem with the reading of data. In line 15, if I don't use HalFlashErase, the HalFlashRead at line 15 does not store "0xbb" in readbuffer. However, if I do use HalFlashErase, the previously stored data at 0x68000, "0xaa" gets erased. I need to be able to store a few KBs of data. If I increase the "FLASHSIZE" to anything greater than 255, the program does not break at the breakpoints and I am not being able to monitor through this. So, I am updating the writebuffer multiple times and write that to flash.
    How do I proceed?


    Thanks!

  • Hi,

    As described in the other E2E thread, you need to:

    #pragma location="MY_ADDRESS_SPACE"
    __no_init uint8 _myFlashBuf[16 * 2048UL];
    #pragma required=_myFlashBuf
    
    __root uint32 myBufAddr; // Just for debug, really. Root is so it's not removed by compile/link even though it's not really needed as a separate variable.
    
    ...
    
    myBufAddr = (uint32)_myFlashBuf;
    
      HalFlashWrite(GET_FLASH_WRITE_ADDR(6, myBufAddr),
                  myTestArray,
                  (sizeof(myTestArray) >> 2) + (sizeof(myTestArray)&0x3?1:0));

    Where the address does _not_ have any information about page. This must be known by you beforehand.

    In addition, you must define an area in the linker file called (here) MY_ADDRESS_SPACE

    BR,
    Aslak

  • Thanks Aslak! I was testing this on "BloodPressure" profile and this works perfectly. I now need to perform the same on a profile with OAD.

    Just one last thing - what are the changes to be made to the oad-target.h and the BIM file?

    In the XCL file, I have made the following changes

    Image A :
    Original:
    -D_BANK4_BEG=0x4B000 // Last 10 pages of Bank 4.
    -D_BANK4_END=0x4FFFF
    //**********REMOVED 0X800 AT THE BEGINNING

    Changed:
    -D_BANK4_BEG=0x4B801
    -D_BANK4_END=0x4FFFF


    Image B:
    Original:
    -D_BANK4_BEG=0x48000
    -D_BANK4_END=0x4AFFF // First 6 pages of Bank 4.

    Changed:
    -D_BANK4_BEG=0x48000
    -D_BANK4_END=0x4A7FF
    //****REMOVED 0X800 AT THE END


    Added to Image B XCL:
    -D_MYADD_BEG=0x4A800
    -D_MYADD_END=0x4B800