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.

NV RESTORE ISSUE for CC2538

Other Parts Discussed in Thread: TIMAC

Hi TI,

I was confused about the NV memory, I found the NV is not in the certain place of flash, and I don't now how to check the certain NV is stored right or wrong.

because I just save one NV, and the NV ID is 0x0402 like below:

#define WTM_IN_TIMAC_OR_ZSTACK_MODE    0x0401
#define WTM_SENSOR_ID       0x0402

osal_nv_item_init(WTM_SENSOR_ID, 1, NULL);
    osal_nv_read(WTM_SENSOR_ID, 0, 1, &sensor_id);

some time after reset, the value will go to 0xFF, I don't know why? because before this I set to 0x01.

my version is statck v1.2.2a

and I also don't know below two questions:

1:

#ifdef NV_RESTORE
  osal_nv_init(NULL);/*this function excute time is 21.85ms*/

#endif

if I don't call this function, if I want to save the consuming current in the startup time, whether it is ok or not?

2: due to reduce the consuming current in the startup time, our project has conbine the TIMAC and Zstack firmware.

and if sometime the project run the TIMAC, we don't call zgInit(); /*consume 51ms*/, and if run the ZSTACK code, it will call zgInit(); function. it will influence the NV ID of WTM_SENSOR_ID's value or not?

thank you

  • If you try to following code, does it work correctly?

    #define nv_test_id 0x0401

    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);
  • It is ok because before read we write the value to the ID. but sometime not all the time it will go to 0xFF because we only read at the startup time.
  • Do you see this issue when you do debug?
  • it can not find at the debugger state, because after the reset, the mcu will not sync with the debugger when I used the system_reset. but if I just reset the code, it can not change.
  • I might not understand your problem well. Can you elaborate again?
  • /******************************************************************************
    * @fn main
    *
    * @brief First function called after startup.
    *
    * @param None
    *
    * @return Don't care
    */
    int main( void )
    {
    // Turn off interrupts
    osal_int_disable( INTS_ALL );/*before this 2.2ms*/


    // Initialization for board related stuff such as LEDs
    HAL_BOARD_INIT();/*this function is 550us*/


    // Initialize board I/O

    InitBoard( OB_COLD );/*very short time, it can not measure from Oscilloscope*/


    // Initialze HAL drivers

    HalDriverInit();/*200us*/

    //GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_PIN_0);
    //GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_0, GPIO_PIN_0);

    // Initialize NV System
    #ifdef NV_RESTORE
    //osal_nv_init(NULL);/*this function excute time is 21.85ms*/

    #endif

    osal_nv_item_init(WTM_IN_TIMAC_OR_ZSTACK_MODE, 1, NULL);

    osal_nv_read(WTM_IN_TIMAC_OR_ZSTACK_MODE, 0, 1, &Timac_Zstack_mode);


    if(Timac_Zstack_mode==0xFFU)
    {
    Timac_Zstack_mode=0U;
    osal_nv_item_init(WTM_IN_TIMAC_OR_ZSTACK_MODE, 1, NULL);
    osal_nv_write(WTM_IN_TIMAC_OR_ZSTACK_MODE, 0, 1, &Timac_Zstack_mode);
    }
    // Initialize the MAC
    if(Timac_Zstack_mode==0U)
    {
    MAC_Init();/*some time it is very long time like more than 25ms, normal tempertature is 540us*/

    }
    else
    {
    ZMacInit();//22ms before /*can not open this because in high temperature test the init time is 80ms*/
    }
    /*50ms*/





    // Determine the extended address
    zmain_ext_addr();

    #if defined ZCL_KEY_ESTABLISH
    // Initialize the Certicom certificate information.
    zmain_cert_init();
    #endif

    // Initialize basic NV items
    if(Timac_Zstack_mode!=0U)
    {
    zgInit();//consume 51ms/***********************************************//*will not save the NV items when go into the ISP and exit*//*if masked this, the zstack tx/rx not ok*/
    }

    #ifndef NONWK
    // Since the AF isn't a task, call it's initialization routine
    afInit();
    #endif

    if(Timac_Zstack_mode==0U)
    {
    //tasksArr = tasksArr_Timac;
    tasksCnt = tasksCnt_Timac;
    }
    else
    {
    //tasksArr = tasksArr_Zstack;
    tasksCnt = tasksCnt_zstack;
    }


    /*50ms*/
    // Initialize the operating system
    osal_init_system();
    /*50ms*/

    #if 1
    if(Timac_Zstack_mode==0U)
    {


    MAC_READ_CHIP_IEEE_ADDR(msa_ExtAddr);

    network_init_check();



    /* Restore the network settings of the Device */
    MAC_NvDeviceRestore(&msa_ExtAddr,
    &msa_PanId,
    &msa_AssociateReq.coordAddress.addr.shortAddr,
    &msa_DevShortAddr,
    #ifdef FEATURE_MAC_SECURITY
    &msa_NumOfSecuredDevices,
    &msa_deviceTable,
    &msa_keyTable);
    #else
    NULL,
    NULL,
    NULL);
    #endif

    }



    #endif

    osal_nv_item_init(WTM_SENSOR_ID, 1, NULL);
    osal_nv_read(WTM_SENSOR_ID, 0, 1, &sensor_id);

    #if 1
    #ifdef OTA_CLIENT
    #ifdef TIMAC
    /* Setup Keyboard callback */
    HalKeyConfig(MSA_KEY_INT_ENABLED, MSA_Main_KeyCallback);
    /* Start polling if callback function is setup*/
    osal_set_event(Hal_TaskID, HAL_KEY_EVENT);// it need this if MSA_KEY_INT_ENABLED==TRUE//FOR TEST
    #endif
    #endif
    #ifdef OTA_CLIENT
    #ifdef NV_RESTORE
    //osal_set_event(MSA_TaskId, MSA_NV_RESTORE_EVENT);
    #endif
    #endif
    #endif
    // Allow interrupts
    osal_int_enable( INTS_ALL );//for test

    SysTickSetup();

    // Final board initialization
    InitBoard( OB_READY );

    /* Display the device info on the LCD */
    #ifdef LCD_SUPPORTED
    //zmain_dev_info();
    //zmain_lcd_init();
    #endif

    //#ifdef WDT_IN_PM1
    #ifndef WATCHDOG_DEBUG_DISABLE

    /* If WDT is used, this is a good place to enable it. */

    if(Timac_Zstack_mode==0U)
    {

    WatchDogEnable( WATCHDOG_INTERVAL_32768 );
    //osal_set_event( ZDAppTaskID, LOADCONTROL_WDT_CLEAR );
    }

    #endif
    //#endif




    osal_start_system(); // No Return from here

    return 0; // Shouldn't get here.
    } // main()


    this is my main function and some time read NV ID WTM_SENSOR_ID:

    osal_nv_item_init(WTM_SENSOR_ID, 1, NULL);
    osal_nv_read(WTM_SENSOR_ID, 0, 1, &sensor_id);

    or

    osal_nv_item_init(WTM_IN_TIMAC_OR_ZSTACK_MODE, 1, NULL);

    osal_nv_read(WTM_IN_TIMAC_OR_ZSTACK_MODE, 0, 1, &Timac_Zstack_mode);

    the value of sensor_id and Timac_Zstack_mode will be 0xFF, I means sometime not every time.
    It seems the flash is erased and it is go into the UNIT state.

    BR,
  • I don't think it's good to do NV read/write in main(). I suggest you to do this in application init.
  • Dear YiKai,

    thank you for your reply. because in normal mode we used TIMAC initialization for our system, and for the OTA we used the ZStack initialization, so we just can used the NV read/write in the main() for the initialization control.

  • I test the following red codes in main function and it works fine too.

    #define nv_test_id 0x0401
    uint8 test_write= 0x78;
    uint8 test_read=0x0;

    int main( void )
    {
      // Turn off interrupts
      osal_int_disable( INTS_ALL );

      // Initialization for board related stuff such as LEDs
      HAL_BOARD_INIT();

      // Initialize board I/O
      InitBoard( OB_COLD );

      // Initialze HAL drivers
      HalDriverInit();

      // Initialize NV System
      osal_nv_init( NULL );

      //YK test NV
     
      osal_nv_item_init(nv_test_id, 1, NULL);
      osal_nv_read(nv_test_id, 0, 1, &test_read);
      osal_nv_write(nv_test_id, 0, 1, &test_write);
      osal_nv_read(nv_test_id, 0, 1, &test_read);

      // Initialize the MAC
      ZMacInit();