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 r/w/allocate - cannot find how to store some configuration data

Other Parts Discussed in Thread: CC2541, CC2540

Hi all,

First off, yes - I've read through the forum to look for help, but not finding anything that helps....

I'm trying to write a few words of configuration data to the flash memory area on a CC2541 (using the TI stack 1.4).  I've found the OSAL_snv routines and also the Halflash routines, but no real understanding of how to use them.  What is needed is a few memory locations to load some initial configuration information for each board - hold that in flash - and not overwrite 'other' data.  It seems that the best way to complete this task would be to use the osal_snv_write  /  read commands, but I've been unsuccessful in finding a memory area to put this data. 

Previous postings have talked about the BLE NV Itemswhich are 'usable' (but it looks like 0x00 - 0x7F are already specified). 

When I look at the memory map using the debugger, I cannot find 'locations' used in the system vs. erased flash areas (which should be specified as 0xff).  How do I:

allocate or specify a series of locations in the flash area

how do i initialized or setup the correct page information

and finally reads and writes - where these areas will not be cleared by a power reset.

  • What about OSAL_NV API?
  • ok - I see that there is an include file, but no 'c' source code. Source should be required - or does it reside in 'another' file? Also, very sparse on how to use. I assume that you would setup item_init and then use in reads/writes?
  • I see no reason for the guessing, you have it well documented in OSAL_OPI.pdf (under documentation folder).

    However, lack of .c bothers me the most.

    Insert some osal_nv call in high level code and see if it compiles or not.

  • Thanks, Igor! Yes, reviewing the documentation should be the first step.

    Best wishes
  • Hi Igor,

    Tried the insert, but as suspected, there is no '.c' file. Searched the system, but didn't find one. Am I missing something? Yep, the API doc is pretty good (although I would have liked an example or two) - if it worked (or does work) that would go along way in resolving.
  • The OSAL SNV .C file Igor suggested does exist. Its somewhere in your installation directory under Components/hal/include. You need to read the SNV API. There is document that you downloaded with the BLE stack that goes over the API.  SNV means SIMPLE NV memory. Its an smaller version of the regular NV API that TI provided for other stacks like the Z stack. There are only 2 functions; read and write. 2K of memory is automatically allocated for you.

  • Hi,

    osal_snv is easy to handle and should be enough, however, if you are about to use osal_nv API, here's some example of how to use it:

    /* Non Volatile memory item ID */
    #define DEV_NV_ID  0x0401 /* This address was chosen from available addresses range listed in OSAL_API.pdf */
    
    /* Some structure to be stored in NV memory */
    typedef struct{
      uint8 param_a;
      uint8 param_b;
      uint8 param_c;
    }some_nv_t;
    
    some_nv_t dev_nv_write, dev_nv_read;
    uint8 tmpStat;
    
    /* Insert some code which writes to dev_nv_write fields */
    /* Insert some code which inits dev_nv_read fields to a known value */
    
    /* Item init */
    tmpStat = osal_nv_item_init(DEV_NV_ID, sizeof(some_nv_t), NULL);
    if(tmpStat != NV_OPER_FAILED) {
      /* Write to NV */
      tmpStat = osal_nv_write(DEV_NV_ID, 0, sizeof(some_nv_t), &dev_nv_write);
      if(tmpStat != NV_OPER_FAILED) {
        /* Read from NV */
        tmpStat = osal_nv_read(DEV_NV_ID, 0, sizeof(some_nv_t), &dev_nv_read);
        if(tmpStat != NV_OPER_FAILED) {
          /* smile */
        } else {
          /* don't be sad and handle the error */
        }
      } else {
        /* what a shame, device refused to write to NV */
      }
    } else {
      /* operation failed */
    }
    

  • Thanks Igor for the code segment. However, there is no code base for osal_nv. There is one for osal_snv - but it is different. The SNV code does not appear to control memory allocation (but I'll take another look).

    Aside from that, in looking at the API doc, it shows address in the range of 0x401 - 0xFFF as application areas. The osal_snv_read routine uses an uint8 as the read address - not compatible (actually the compiler truncates the value). So something is very wrong here (aside from the fact that the API doc is really for the osal_nv version and not the snv version that the project has).

    Still in the dark here (shouldn't this be a simple issue?)
  • Daniel Paley27 said:
    However, there is no code base for osal_nv

    So you didn't manage to locate osal_nv.c?

  • nope - found the .h, but no osal_nv.c - Did a full dish search from a new install of the s/w - nothing.
  • Great :(

    Try under the following path:

    ...\stack installation folder\\\Components\osal\mcu\cc2540

    if you find it there, go back to IAR IDE with an open workspace, in project tree locate OSAL folder,

    right click on it ->Add->add file-> add it

    Include OSAL_Nv.h in high level file, then add a call to, let's say,

    osal_nv_init(), finally rebuild and compile the whole project 

  • File does not exist (in that dir or any other). too bad, as the doc's look like what I need.
  • Yep - I know that path. Only file there is the osal_snv.c - I would LOVE to use the Nv file - as it has documentation.
  • The osal snv documentation might be a chapter in the overall osal doc since its so short. I'll check tomorrow.

    What do you man by "memory allocation"? Are you referring to dynamic memory allocation (malloc functions)? Or reserving and erasing flash regions?

  • the latter - reserving a section of flash (as in reserve linker space) - so that nothing else is expecting to use this area.
  • Hi all,

    Frankly speaking, I'm a bit disappointed by ble 1.4.0 stack documentation, especially OSAL_API, since it clearly

    provides an API for osal_nv. Seen it only today at the office (I have no ble stacks installed on my home PC).

    Any-who:

    Section 11 of the same OSAL_API.pdf describes SNV (Simple Non-Volatile Memory) API.

    You are a bit limited with space for your own items to be stored (127 bytes only), with addresses ranging from 0x80 to 0xFE.

    Using the read and write API is pretty straight forward:

    1. osal_snv_write(item_id, item_len, p_my_item);
    2. osal_snv_read(item_id, item_len, p_my_item); 

    Hope it helps

  • You automatically get 2K of flash reserved for you by the API. This API is meant for SMALL pieces of data to be backed up SPARINGLY. Igor is correct is saying you only get 127 unique IDs/addresses to use, but I strongly encourage you not to use that many. You can store multiple bytes to these addresses ie

    #define ARRY_NV_ID  0x81

    int arry[MAX_SIZE] = {1, 2, 3};

    osal_snv_write(ARRY_NV_ID, sizeof(int)*MAX_SIZE, arry);

    If you need more intensive use of flash, you will need to learn the HAL flash API and reserve flash space manually in the IAR linker file.

    Attached is the OSL API guide since you are having difficulties finding it.OSAL API.pdf

  • ok That's got it.  It's seems to work (i.e. keep's memory when the device is without power).  I just wish there was a bit better documentation in this area.

    thanks for the information and help