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.

how to write data in the NV flash

Hi

       there is a ZED which have some attributes will be writed by other device。

       I want to save some attributes data to NV flash when appropriatly,

       and i need to read back when the device reset 。

        first step i define a ID in ZComDef.h

        #define ZONE_CIEADDRESS_AND_ENROLL_INFO            0x0401

       i  put those code in the App initial function to read back when the device reset:

       if(osal_nv_item_init( ZONE_CIEADDRESS_AND_ENROLL_INFO, Z_EXTADDR_LEN +1, NULL) == ZSUCCESS)//测试成功
  {
     uint8 *buf;
     uint8 i;
     buf = NULL;
     osal_nv_write(ZONE_CIEADDRESS_AND_ENROLL_INFO, 0, sizeof  aExtendedAddress,aExtendedAddress);
      
     if (osal_nv_read(ZONE_CIEADDRESS_AND_ENROLL_INFO, 0, sizeof buf, buf)==SUCCESS)
     {
       for(i=0;i<Z_EXTADDR_LEN-1;buf++)
       {
          zclWarningDevice_IAS_CIE_Address[i++]=*buf;
       }
          zclWarningDevice_ZoneState =*buf;

     }
   }

        

    but  when i debug ,i find that  it have not success in osal_nv_item_init

 

    what is the problem!!!

       

  • I suggest you try to test write and read a uint16 variable to nv first.

     uint16 test_write= 0x1234;

     uint16 test_read=0x0;

     osal_nv_item_init(nv_test_id, 1, NULL);

     osal_nv_write(nv_test_id, 0, 1, &test_write);

     osal_nv_read(nv_test_id, 0, 1, &test_read);

    Check if test_read is equal to test_write after osal_nv_write(nv_rejoin_id, 0, 1, &test_write); and osal_nv_read(nv_test_id, 0, 1, &test_read);

  • Yeah,but why you use different ID between write and read

    osal_nv_item_init(nv_test_id, 1, NULL);
    osal_nv_write(nv_rejoin_id, 0, 1, &test_write);
    osal_nv_read(nv_test_id, 0, 1, &test_read);
  • It is my typo. It is osal_nv_write(nv_test_id, 0, 1, &test_write)
  • i will have a try!
    i have use a UART to printf out the result, but it was send Garbled sometimes, i can't check if write OK or not
    could you please share me the method to close the zstack uart debug MSG, i just want to put out the MSG of Mine


    anyways ,i saw those words in TI white paper, do you know what is the good time of nv write and read?

    It is best to execute these functions at times when they do not conflict with other timing-critical operations.
    For example, a good time to write NV items would be when the receiver is turned off.
  • 1. Those message might be sent by MT commands and you can disable MT_xxx related define in project c/c++ preprocessing options.
    2. I would suggest to create a new event for NV read/write.
  • i testd the NV write and read test as below:

     put those code in the app initial function, it will do the test when the device power on

     uint8 test_write= 0x12;

     uint8 test_read=0x0;

     osal_nv_item_init(ZONE_CIEADDRESS_AND_ENROLL_INFO, 1, NULL);

     osal_nv_write(ZONE_CIEADDRESS_AND_ENROLL_INFO, 0, 1, &test_write);

     osal_nv_read(ZONE_CIEADDRESS_AND_ENROLL_INFO, 0, 1, &test_read);
     
     HalUARTWrite(0,&test_read, sizeof test_read );

    1.  i closed all the MT_xxx related define as beblow:

    xMT_TASK
    xMT_APP_FUNC
    xMT_SYS_FUNC
    xMT_ZDO_FUNC
    xLCD_SUPPORTED=DEBUG

        but after rebuild the project , there is always garbled ...

  • I would suggest you to set breakpoint to debug this nv issue.
  • if we disabled all MT_XXX related define,
    what can we do with this function in XXX_BasicResetCB();

    just disable it ??? is it matter with restart the device??????

    // restart device
    MT_SysCommandProcessing( aProcessCmd );
  • MT_xxx is for sending or receiving MT command through UART or SPI. If you don't use it, you can disable it. I still suggest you set breakpoint to check your NV issue first.
  • Hi chen, write and read test was ok by set breakpoint checking.

    but when i do the device to factory reset, the flash seems have not delete~~~it was always here ~~~~
  • This NV item is created by your application so you have to clear by yourself when doing factory reset.
  • it is OK, i set osal_nv_delete( nv_test_ID, length); when doing factory reset。

    this web was change,i can't insert the image~~~that is a pity!!!