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.

CC2530: Writing to NV memory

Part Number: CC2530

Hi,

I am trying to write and array to NV memory 

#define ZCD_NV_SITE_CFG 0x0401
#define ZCD_NV_SITE_CFG_LTH 8

uint8 nullAddr[8] = {0xB9, 0x00, 0x00, 0x14, 0x38, 0x12, 0x80, 0x99};

status = osal_nv_item_init( ZCD_NV_SITE_CFG, ZCD_NV_SITE_CFG_LTH, NULL );

if ( status == ZSUCCESS ) 
{
status = osal_nv_write( ZCD_NV_SITE_CFG, 0, ZCD_NV_SITE_CFG_LTH, nullAddr);
}

The error occurs in osal_nv_write 

HalFlashRead(srcPg, (srcOff - OSAL_NV_HDR_SIZE), (uint8 *)(&hdr), OSAL_NV_HDR_SIZE);
if ( hdr.len < (ndx + len) )
{
return NV_OPER_FAILED;
}

where there seems to be a test done on the size of the data that can be written as defined in this structur

typedef struct
{
uint16 id;
uint16 len; // Enforce Flash-WORD size on len.
uint16 chk; // Byte-wise checksum of the 'len' data bytes of the item.
uint16 stat; // Item status.
} osalNvHdr_t;

Currently the lenght seems to be set to 4 and if I reduce the size of my array to write ZCD_NV_SITE_CFG_LTH to 4,

the works successfully. 

However I cannot find where the length in the osalNvHdr_t; structure is set and what are the parameters around it

I have found osal_nv_write functions called with larger array amounts of data

Could you tell me if its possible to set the array length larger and, if so, how to do it 

Thank You

Regards

Peter Simpson

  • Try to replace

    status = osal_nv_item_init( ZCD_NV_SITE_CFG, ZCD_NV_SITE_CFG_LTH, NULL);

    with

    status = osal_nv_item_init( ZCD_NV_SITE_CFG, ZCD_NV_SITE_CFG_LTH, nullAddr );

  • Hi,

    Thank you for your reply.

    I have made the change suggested

    status = osal_nv_item_init( ZCD_NV_SITE_CFG, ZCD_NV_SITE_CFG_LTH, nullAddr );

    But I still get the same failure at

    HalFlashRead(srcPg, (srcOff - OSAL_NV_HDR_SIZE), (uint8 *)(&hdr), OSAL_NV_HDR_SIZE);
    if ( hdr.len < (ndx + len) )
    {
    return NV_OPER_FAILED;
    }

    when 

    #define ZCD_NV_SITE_CFG_LTH 8

    Thank You

    Regards

    Peter Simpson

  • I test with similar code and it works fine. Can you post your complete code?
  • Hi,
    I have inserted the code below - the function is called at the beginning of the


    #define ZCD_NV_SITE_CFG 0x0401
    #define ZCD_NV_SITE_CFG_LTH 8


    void load_Addresses(void);

    void osalInitTasks( void )
    {
    uint8 taskID = 0;

    tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
    osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));

    macTaskInit( taskID++ );
    nwk_init( taskID++ );
    Hal_Init( taskID++ );
    #if defined( MT_TASK )
    MT_TaskInit( taskID++ );
    #endif
    APS_Init( taskID++ );
    #if defined ( ZIGBEE_FRAGMENTATION )
    APSF_Init( taskID++ );
    #endif
    ZDApp_Init( taskID++ );
    #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
    ZDNwkMgr_Init( taskID++ );
    #endif
    App_Init( taskID );
    }


    void App_Init( uint8 task_id )
    {
    load_Addresses();

    ..
    ..
    ..
    ..
    }

    void load_Addresses(void)
    {
    uint8 status;
    uint8 nullAddr1[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

    status = osal_nv_item_init( ZCD_NV_SITE_CFG, sizeof(nullAddr1), nullAddr1 );

    if ( status == ZSUCCESS ) // Id already existed, no action taken
    {
    status = osal_nv_write( ZCD_NV_SITE_CFG, 0, sizeof(nullAddr1), nullAddr1);
    }
    }
    regards
    Peter Simpson
  • If you don't call osal_nv_item_init and use osal_nv_write directly, does it work?