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.

CC2650: Flash.h FlashSectorErase Function

Part Number: CC2650


Hello!

I am trying to use the flash driverlib to erase the 128 KB flash memory of the CC2650F128. To my understanding, this must be done one page (and each page is 4 KB, starting at address 0x00001000) at a time.

I attempt to do this below:

#define FLASH_BASE      0x0
#define FLASH_PAGE_SIZE 0x00001000

int main(){
    uint8_t i=0;
    for(i; i<32; i++){
        int j = FlashSectorErase(FLASH_BASE + i*FLASH_PAGE_SIZE);
        System_printf("Page Number Erased: %i\n", i);
        System_flush();
    }
    return 0;
}

But am given warning statement "expression has no effect" once I build the project.

The error I get when debugging is "FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH" meaning that there is an "Invalid argument".

Any ideas on how to move forward?

Thank you,

Kevin

  • Have you looked into the NVS driver? 

  • I have, but I would like to work with the flash driverlib as the flash functions do not require a handle like the NVS.

    For example, the NVS driver requires an index which was not clear to me: NVS_open(int index, NVS_Params *params) among a few other things... overall the flash driverlib seems more straight forward.

  • I think this question would better help me: is there anywhere in CCS that tells me where exactly in memory my project/compiled program is written?

    I believe the original issue I was having was that I'd try to erase the program that I was running, as something like:

        int j = FlashSectorErase(20*FLASH_PAGE_SIZE);
        System_printf("Function Return Value: %i\n", j);
        System_flush();

    returns a succes. I assume this is because nothing vital to the program was stored at this location in memory.

    Thanks again for the help and I apologize for the confusion!

  • Note that the NVS driver ensures that the flash can be accessed safely. I strongly recommend you to use the the NVS driver. You can take a look at this example: http://dev.ti.com/tirex/explore/node?node=AM1YBgEfpNskXy2TK188JA__krol.2c__LATEST to see how the NVS driver can be used. 

  • Do you have any idea what the first argument of the the following function should be for the board I am using? (I am using CC2650STK)

    From line 81 of nvsinternal.c:

    nvsHandle = NVS_open(Board_NVSINTERNAL, &nvsParams);

    "Board_NVSINTERNAL" is defined in the Board.h file for the CC2640R2, the board for which this example is provided, but not for the CC2650STK from what I see.

    There is also a file "CC2640R2_LAUNCHXL_fxns" which is part of the project you linked, is this unique to the CC2640R2 and crucial to building this project?

    It is also unclear as to how I would write to an arbitrary location of flash memory (would I edit the NVS params?)...

    If you could clear this up I would greatly appreciate it!

    Thank you!

  • Hi Kevin,

    Have you had a look at the API documentation for the driver? There is no real difference in terms of arguments between this driver and any other driver shipped with the SDK:

    (NVS.h)

    /*!
    * @brief Get an NVS block for reading and writing.
    *
    * @pre NVS_init() was called.
    *
    * @param index Index in the NVS_config table of the block
    * to manage.
    *
    * @param params Pointer to a parameter block. If NULL, default
    * parameter values will be used.

    extern NVS_Handle NVS_open(int index, NVS_Params *params);

     

    This means that you need to check in your board file for the "NVS_config" structure and see how the driver is configured.


    Also, it is not clear from what SDK version you base your findings. As you reference "CC2640R2_LAUNCHXL_fxns", I would assume you are not using the correct SDK as this is a rather "new" addition to the CC2640R2 SDK which do not support CC2650.

    Either way, you can not erase the complete flash with the NVS driver or the example code you tested above. Basically, you can not put a program in flash and tell it to erase itself. The only possible way to do this would be to create a RAM function from which you perform the mass erase using the DriverLib ROM APIs. 

    May I ask what your application is that require this mass erase behavior?

  • I apologize, I don't think I was clear....

    The application I am working on is a custom bootloader that will receive an application over-the-air and write it to flash memory.

    Both the bootloader and the application will reside in flash memory. Only the application is to be erased.

    From what I understand this should be okay as these functions do not allow access to flash memory when called, but will execute in RAM.

    Also, I checked my board file for the "NVS_config" structure but it was not there. Is this because the NVS.h library is a preliminary one?

  • Hi Kevin,

    While the "Flash" API would execute from ROM, your function logic is still left in flash. Now this could be perfectly fine in a bootloader application but in these situations you typically never erase the whole flash as this would mean you also remove the bootloader. 

    It could be that the NVS structure as not present in your board file per default, I would need to know more about the example you are basing of. In your case, you would not like to use the NVS driver as I would guess you do not want the bootloader dependent on TI-RTOS.

    While you did not give any feedback on which SDKs you had downloaded,I would recommend you might look into the newer SDKs (such as the CC13x0 SDK) as some of the examples features the "BIM" project. This is a simple bootloader implementation that you might be able to draw inspiration from. While the example is for another device, the principal and driverlib API would remain the same.

  • Thank you very much! I will look into it and hopefully work things out!