PDS not Storing proper data in Bitcloud 3.2 in SamR21

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

We are using PDS_WriteUserData() and PDS_ReadUserData() functions to store data in NVM. When the devices boots first time after programming it is able to write data in Flash using PDS_WriteUserData() and we can read data after reset or POR.

 

But when we try to change the data on same location later on the PDS_WriteUserData() gives success and on using PDS_ReadUserData() we get the data which we just wrote, but on reset when we read the data is the default values not the new updated values from last update.

 

Config for PDS:---

#define APP_USE_PDS 1

#define PDS_ENABLE_WEAR_LEVELING 0

 

Rest are as there default values.

 

 

 

Last Edited: Fri. Oct 16, 2015 - 12:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I'm not sure about user data, but depending on a data, it might be better to use advanced PDS capabilities. Here is an example of counting power cycles:

static uint32_t appOnCounter;

PDS_DECLARE_FILE(APP_ON_COUNTER_MEM_ID, sizeof(uint32_t), &appOnCounter, NO_FILE_MARKS);

PROGMEM_DECLARE(PDS_MemId_t appMemoryIdsTable[]) =
{
  APP_ON_COUNTER_MEM_ID,
};

PDS_DECLARE_DIR(PDS_DirDescr_t appMemoryDirDescr) =
{
  .list       = appMemoryIdsTable,
  .filesCount = ARRAY_SIZE(appMemoryIdsTable),
  .memoryId   = APP_MEMORY_MEM_ID
};

static void appIncreaseCounter(void)
{
  if (PDS_IsAbleToRestore(APP_ON_COUNTER_MEM_ID))
    PDS_Restore(APP_ON_COUNTER_MEM_ID);
  else
    appOnCounter = 0;

  appOnCounter++;
  PDS_Store(APP_ON_COUNTER_MEM_ID);
}

You end up with a lot of code upfront, but you save in a long run if you have more different variables to store. This way may also reduce wear on the flash.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alexru,

 

I tried using PDS the way you explained in exampe. but it's on restart I'm getting false for PDS_IsAbleToRestore(). This is my code for PDS:--

 

PDS_DECLARE_FILE(APP_CS_PARAM_UPDATED_ID, sizeof(csParamUpdated), &csParamUpdated, NO_FILE_MARKS);
PDS_DECLARE_FILE(APP_DEVICE_SLEEP_TIME_ID, sizeof(sleepTime), &sleepTime, NO_FILE_MARKS);
PDS_DECLARE_FILE(APP_CS_CHANNAL_MASK_ID, sizeof(deviceChannelMask), &deviceChannelMask, NO_FILE_MARKS);
PDS_DECLARE_FILE(APP_CS_UID_ID, sizeof(deviceMacId), &deviceMacId, NO_FILE_MARKS);
PDS_DECLARE_FILE(APP_CS_EXT_PANID_ID, sizeof(devicePanId), &devicePanId, NO_FILE_MARKS);

PROGMEM_DECLARE(PDS_MemId_t appMemoryIdsTable[]) =
{
    APP_CS_PARAM_UPDATED_ID,
    APP_DEVICE_SLEEP_TIME_ID,
    APP_CS_CHANNAL_MASK_ID,
    APP_CS_UID_ID,
    APP_CS_EXT_PANID_ID,
};

PDS_DECLARE_DIR(PDS_DirDescr_t appMemoryDirDescr) =
{
  .list       = appMemoryIdsTable,
  .filesCount = ARRAY_SIZE(appMemoryIdsTable),
  .memoryId   = APP_SENSOR_CONFIG_STORE_ID
};

 

All the File ID and Dir Id are defined in App File and Dir ID in PDS_MemIdsTable_t in stdPdsMemIds.h

 

I tried uisng it 2 ways, but for both I get PDS_IsAbleToRestore() as false.

 

First:--

    if (PDS_IsAbleToRestore(APP_SENSOR_CONFIG_STORE_ID))

    {
        PDS_Restore(APP_SENSOR_CONFIG_STORE_ID);

    }

    else

    {

        csParamUpdated    = 0x01;
        sleepTime            = devConfig->sleepTime;
        deviceMacId        = devConfig->deviceMacId;
        devicePanId        = devConfig->devicePanId;
        deviceChannelMask    = devConfig->deviceChannelMask;

 

        PDS_BlockingStore(APP_SENSOR_CONFIG_STORE_ID);
        HAL_WarmReset();
    }

 

Second:--

 

    if (PDS_IsAbleToRestore(APP_CS_UID_ID) && PDS_IsAbleToRestore(APP_CS_EXT_PANID_ID) && PDS_IsAbleToRestore(APP_CS_CHANNAL_MASK_ID) && PDS_IsAbleToRestore(APP_CS_PARAM_UPDATED_ID) && PDS_IsAbleToRestore(APP_DEVICE_SLEEP_TIME_ID))
    {
        PDS_Restore(APP_CS_UID_ID);
        PDS_Restore(APP_CS_EXT_PANID_ID);
        PDS_Restore(APP_CS_CHANNAL_MASK_ID);
        PDS_Restore(APP_CS_PARAM_UPDATED_ID);
        PDS_Restore(APP_DEVICE_SLEEP_TIME_ID);
    }
    else
    {
        csParamUpdated    = 0x01;
        sleepTime            = devConfig->sleepTime;
        deviceMacId        = devConfig->deviceMacId;
        devicePanId        = devConfig->devicePanId;
        deviceChannelMask    = devConfig->deviceChannelMask;

 

        PDS_BlockingStore(APP_CS_UID_ID);
        PDS_BlockingStore(APP_CS_EXT_PANID_ID);
        PDS_BlockingStore(APP_CS_CHANNAL_MASK_ID);
        PDS_BlockingStore(APP_CS_PARAM_UPDATED_ID);
        PDS_BlockingStore(APP_DEVICE_SLEEP_TIME_ID);
        HAL_WarmReset();
    }

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I think you need to have wear leveling enabled. The code I've shown is taken from a real working project.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alexru,

 

I tried using wear leveling enabled. After I write using PDS_Store() (.. since PDS_BlockingStore not defined) and verify data using PDS_IsAbleToRestore() and then restore the data using PDS_Restore() I get the correct data, but after I do HAL_WarmReset() and read again PDS_IsAbleToRestore() gives me false.

 

Below are my Config for HAL, can it be a problem as I put EEPROM_EMULATION = FALSE? But preivously my first PDS_write was working, but PDS_Store doesn't work after reset.

 

  # EEPROM is based on flash emulation
  EEPROM = TRUE
  #EEPROM = FALSE

  #EEPROM_EMULATION = TRUE
  EEPROM_EMULATION = FALSE

  # Use program memory access interface.
  INTERNAL_FLASH_ACCESS = TRUE
  #INTERNAL_FLASH_ACCESS = FALSE

Last Edited: Fri. Apr 17, 2015 - 09:31 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

There is no EEPROM in R21, so yes, you need to use emulation.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.