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.

RTOS/CC2541: CC2541 SNV failed to save

Part Number: CC2541


Tool/software: TI-RTOS

Now I find a problem. The user data is saved to SNV, and the debugging finds that the data read out is all 0, and the data is not saved to SNV.

Using the osal_snv_write() and osal_snv_read() functions, access the ID 0x80.

The test code is as follows. This function is also called after osal_snv_init() :

void cc2541_MAC2snv_test(void)

{

    uint8 nv_ret; 

    uint8 nv_data_read[128] =0;

    uint8 nv_data_write[128] = 0; 

 

    uint8 ownAddress[B_ADDR_LEN];  

 

    ownAddress[0]=*(unsigned char *)(0x780E); // 直接指向指针内容  

    ownAddress[1]=*(unsigned char *)(0x780F);  

    ownAddress[2]=*(unsigned char *)(0x7810);  

    ownAddress[3]=XREG(0x7811);                // define 函数直接读出数据  

    ownAddress[4]=XREG(0x7812);  

    ownAddress[5]=XREG(0x7813);               

       osal_memset(nv_data_write, 0, sizeof(nv_data_write)); //清空缓冲区后,作为接收缓冲区

 

        nv_data_write[0]=ownAddress[0];

    nv_data_write[1]=ownAddress[1];

    nv_data_write[2]=ownAddress[2];

    nv_data_write[3]=ownAddress[3];

    nv_data_write[4]=ownAddress[4];

    nv_data_write[5]=ownAddress[5];

        nv_ret = osal_snv_write(0x80, 128, nv_data_write);

    if(nv_ret!= NV_OPER_FAILED)

       {

      nv_ret = osal_snv_read(0x80, 128, nv_data_read);

    }

}

  • Hi Hank,

    I tested SNV with this function, that I call from SimpleBLEPeripheral_Init(..),

    uint8 dataToWrite[22] = "This is a test string";
    uint8 dataToRead[22] =  "Nothing has been read";
    
    void snvTestFunction()
    {
      HalLcdWriteString( "Reading SNV",  HAL_LCD_LINE_1 );
    
      if (SUCCESS != osal_snv_read(0x80, sizeof(dataToRead), dataToRead))
      {
        HalLcdWriteString( "No record first",  HAL_LCD_LINE_2 );
        osal_snv_write(0x80, sizeof(dataToWrite), dataToWrite);
        
        HalLcdWriteString( "Reading SNV x2",  HAL_LCD_LINE_1 );
        if (SUCCESS != osal_snv_read(0x80, sizeof(dataToRead), dataToRead))
        {
        }
      }
      
      HalLcdWriteString(dataToRead, HAL_LCD_LINE_3 );
      
      while(1);
    
    }

    It seems to be working as intended. This is how SNV records can be initialized. First try to read, then write in some default. On next boot you will be reading from flash.

    I also tried your function and it seemed to also work as expected. Possibly you should allocate the buffers outside the function to save stack space, and initialize with = {0} instead of = 0, but otherwise.

    Best regards,
    Aslak