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.

Saving Data to internal Flash CC1310

Other Parts Discussed in Thread: CC2650, CC1310

Hi, 

I am trying to save the date from a sensor to the internal flash. Are there any APIs to facilitate this operation? On another post for the CC2650, it was suggested that we had two options to achieve this:

1. 'ti/driver/flash.h'

2. 'ti/driver/nvs.h' (TI-RTOS 2.16 only)

Could you please elaborate further on the usage specifically for CC1310. Are there any examples that I could learn from? I do not understand how to use the NVS_init() and NVS_open functions. They throw up build errors when I tried to use the NVS driver.

Thanks,

Venky

  • Hi

    There are functions in C:\ti\tirtos_cc13xx_cc26xx_2_16_00_08\products\cc13xxware_2_03_01_16780\driverlib that can be used to erase or write to flash.

    Below is some code I used in a test where I wanted to store a 128 bytes long packet in flash:

    /* Flash defines */
    #define SECTOR_SIZE                4096
    #define SECTOR_TO_ERASE            14
    #define SECTOR_TO_ERASE_START_ADDR (FLASHMEM_BASE + (SECTOR_TO_ERASE * SECTOR_SIZE))
    
    /* The area in flash where the payload will be placed. SECTOR_SIZE * SECTOR_TO_ERASE */
    __no_init const char flashDataAddr[SECTOR_SIZE] @ 0xE000; 
    
    void writeToFlash(void)
    {
        int32_t result;
                  
        /* Disable the cache */
        VIMSModeSet(VIMS_BASE, VIMS_MODE_DISABLED);
        while(VIMSModeGet(VIMS_BASE) != VIMS_MODE_DISABLED);
                  
        /* Make sure that sector isn't write protected. */
        result = FlashProtectionGet(SECTOR_TO_ERASE_START_ADDR);
        if(result == FLASH_WRITE_PROTECT)
        {
            while (1);
        }
                    
        /* Disable all interrupts when accessing the flash */
        CPUcpsid();
    
        /* Erase a flash Page */
        result = FlashSectorErase(SECTOR_TO_ERASE_START_ADDR);
            
        if(result != FAPI_STATUS_SUCCESS)
        {
            while (1);
        }
                        
        /* Program 128 bytes in chunks of 8 bytes */
        for(uint8_t i = 0; i < 128; i += 8)
        {
            /* Write to flash */
            result = FlashProgram(&packet[i], SECTOR_TO_ERASE_START_ADDR + i, 8);
            
            if(result != FAPI_STATUS_SUCCESS)
            {
                while (1);
            }
        } 
    
        CPUcpsie();   
    
        /* Re-enable the cache */
        VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
    }
    

    Siri

  • Hi Siri,

    Thank you for your reply. I received a preliminary version of the NVS documentation from Todd. I have resolved the issue using the APIs provided by the NVS driver.

    Thanks,
    Venky
  •  I find that CC1310 can't reset to continue run and after write Data to internal Flash .I save data as your method. do you have this problem?please check my code.

    below my code:

    #define ID_Flash_Addr 0x1f000

    void writeToFlash(void)
    {
    int32_t result;
    uint8_t packet[8]={0,};
    /* Disable the cache */
    VIMSModeSet(VIMS_BASE, VIMS_MODE_DISABLED);
    while(VIMSModeGet(VIMS_BASE) != VIMS_MODE_DISABLED);

    /* Make sure that sector isn't write protected. */
    result = FlashProtectionGet(ID_Flash_Addr);
    if(result == FLASH_WRITE_PROTECT)
    {
    while (1);
    }

    /* Disable all interrupts when accessing the flash */
    CPUcpsid();

    /* Erase a flash Page */
    result = FlashSectorErase(ID_Flash_Addr);

    if(result != FAPI_STATUS_SUCCESS)
    {
    while (1);
    }

    /* Program 128 bytes in chunks of 8 bytes */

    /* Write to flash */
    result = FlashProgram(packet, ID_Flash_Addr, 8);

    if(result != FAPI_STATUS_SUCCESS)
    {
    while (1);
    }

    CPUcpsie();

    /* Re-enable the cache */
    VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
    }


    void ReadFlash(uint32_t wAddr,uint8_t *bBuf,uint8_t bLen)
    {
    uint8_t *Flash_Ptr = (uint8_t *) wAddr;
    while(bLen--)
    *(bBuf++)=*(Flash_Ptr++);
    }

    6786.flash_CC1350_LAUNCHXL_TI_CC1350F128.zip

     

     

  • I find the problems in my project .
    "#defineID_Flash_Addr 0x1f000" is wrong. I viewed the map.

    .ccfg 0 0001ffa8 00000058
    0001ffa8 00000058 ccfg.obj (.ccfg:retain)
    maybe i modify the .ccfg parameter .
    can you agree my idea
  • Hi Siri,

    I also need to save some variables in the CC1310 flash memory.

    Do you have any example of how to do that using the NVS (<ti/drivers/NVS.h>)?

    Thank you in advance!
  • we ended up adding our own eeprom to our board and controlling ourselves as it was having strange things happen in saving, etc.  sorry to break the news.

  • Siri said:

    Hi

    There are functions in C:\ti\tirtos_cc13xx_cc26xx_2_16_00_08\products\cc13xxware_2_03_01_16780\driverlib that can be used to erase or write to flash.

    Below is some code I used in a test where I wanted to store a 128 bytes long packet in flash:

    /* Flash defines */
    #define SECTOR_SIZE                4096
    #define SECTOR_TO_ERASE            14
    #define SECTOR_TO_ERASE_START_ADDR (FLASHMEM_BASE + (SECTOR_TO_ERASE * SECTOR_SIZE))
    
    /* The area in flash where the payload will be placed. SECTOR_SIZE * SECTOR_TO_ERASE */
    __no_init const char flashDataAddr[SECTOR_SIZE] @ 0xE000; 
    
    void writeToFlash(void)
    {
        int32_t result;
                  
        /* Disable the cache */
        VIMSModeSet(VIMS_BASE, VIMS_MODE_DISABLED);
        while(VIMSModeGet(VIMS_BASE) != VIMS_MODE_DISABLED);
                  
        /* Make sure that sector isn't write protected. */
        result = FlashProtectionGet(SECTOR_TO_ERASE_START_ADDR);
        if(result == FLASH_WRITE_PROTECT)
        {
            while (1);
        }
                    
        /* Disable all interrupts when accessing the flash */
        CPUcpsid();
    
        /* Erase a flash Page */
        result = FlashSectorErase(SECTOR_TO_ERASE_START_ADDR);
            
        if(result != FAPI_STATUS_SUCCESS)
        {
            while (1);
        }
                        
        /* Program 128 bytes in chunks of 8 bytes */
        for(uint8_t i = 0; i < 128; i += 8)
        {
            /* Write to flash */
            result = FlashProgram(&packet[i], SECTOR_TO_ERASE_START_ADDR + i, 8);
            
            if(result != FAPI_STATUS_SUCCESS)
            {
                while (1);
            }
        } 
    
        CPUcpsie();   
    
        /* Re-enable the cache */
        VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
    }
    

    Siri

    Hi Siri,

    I tried to run your example in a CC1310.

    But I am getting erros in the line: __no_init const char flashDataAddr[SECTOR_SIZE] @ 0x1E000;

    Can you help me?

  • Hi,

    The I hope the above  implementation for IAR ..

    You could use the below code instead of that.

    #pragma NOINIT(flashDataAddr)
    #pragma location = 0xE000
    char flashDataAddr[SECTOR_SIZE];

     

    Regards

    Zee