This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Getting RAM and Flash data corruption in runtime.

Hi Team,

we are using the Nrf52840 board for our development. We are facing one issue with RAM Structure Corruption.

We have one Global structure in our code, in that one of the variable is corrupting which is linking with other RAM Variable , it is not part of structure.

Eg:

typedef struct
{ 

uint8_t BLE_MAC_ID[6];
uint8_t sbSysFlags[4]; // 32 bit variable system wide flags
uint16_t FLA_Reserve9;

uint16_t Sb_Err_Value;
uint16_t Reserve;

uint16_t kpda_kpin_crc[2];
uint16_t ksys_kbox_kold_crc[3];
uint16_t FLA_Reserve10;

}FLA_FS_sysStruct_t;

FLA_FS_sysStruct_t m_Sb_Secure_data ={0};

bool Crc_check_flag = 0;

when ever the "Crc_check_flag" got updated in runtime  "m_Sb_Secure_data.Sb_Err_Value" also updating automatically. but there is link between these two variables, both are indepnedent each other, but both are declared and updated in same .c file, but no linkage between these two. How to detect what is the root cause for this detection.Is there any way to identify the stack and RAM overflows. 

1. Suppose if want to put the one specific structure in Specific RAM location and no other parts of the code should not disturb this location or data.

2. Similar way for flash as well, if we block one flash sector(0x5e000)  for application usage, how to avoid this one by other code parts to overwrite.

It is very urgent for me, if any one having some solution it is very helpful to us.

Regards,

Srinivas.V

Parents
  • Alignment might be an issue, depending on how you are accessing the structure, though I don't see an immediate cause. Have a look at this (compiled in IAR):

    typedef struct
    { 
      uint8_t BLE_MAC_ID[6];
      uint8_t sbSysFlags[4]; // 32 bit variable system wide flags
      uint16_t FLA_Reserve9;
      uint16_t Sb_Err_Value;
      uint16_t Reserve;
      uint16_t kpda_kpin_crc[2];
      uint16_t ksys_kbox_kold_crc[3];
      uint16_t FLA_Reserve10;
    }FLA_FS_sysStruct_t;
    
    FLA_FS_sysStruct_t m_Sb_Secure_data ={0};
    STATIC_ASSERT(sizeof (m_Sb_Secure_data) == 28);                     <== pass
    STATIC_ASSERT(offsetof(FLA_FS_sysStruct_t, sbSysFlags) == 6);       <== pass
    STATIC_ASSERT(offsetof(FLA_FS_sysStruct_t, sbSysFlags) & 0x3 == 0); <== fail
    
    bool Crc_check_flag = 0;
    STATIC_ASSERT(sizeof (Crc_check_flag) == 1);                        <== pass

    sbSysFlags is an array of 4 bytes, but the comment suggests sbSysFlags might be treated as a 32-bit variable; any 32-bit write to m_Sb_Secure_data.sbSysFlags will fail as it is not correctly 4-byte aligned. The struct order must be changed if that is the case, or padded by using a union.

    Please post in a reply the lines of code which write to Crc_check_flag and m_Sb_Secure_data so we can help further

    Edit: To set a data breakpoint in IAR right-click on the variable definition and Set Data Breakpoint. Then right-click on the data breakpoint red blob to edit properties if needed

Reply
  • Alignment might be an issue, depending on how you are accessing the structure, though I don't see an immediate cause. Have a look at this (compiled in IAR):

    typedef struct
    { 
      uint8_t BLE_MAC_ID[6];
      uint8_t sbSysFlags[4]; // 32 bit variable system wide flags
      uint16_t FLA_Reserve9;
      uint16_t Sb_Err_Value;
      uint16_t Reserve;
      uint16_t kpda_kpin_crc[2];
      uint16_t ksys_kbox_kold_crc[3];
      uint16_t FLA_Reserve10;
    }FLA_FS_sysStruct_t;
    
    FLA_FS_sysStruct_t m_Sb_Secure_data ={0};
    STATIC_ASSERT(sizeof (m_Sb_Secure_data) == 28);                     <== pass
    STATIC_ASSERT(offsetof(FLA_FS_sysStruct_t, sbSysFlags) == 6);       <== pass
    STATIC_ASSERT(offsetof(FLA_FS_sysStruct_t, sbSysFlags) & 0x3 == 0); <== fail
    
    bool Crc_check_flag = 0;
    STATIC_ASSERT(sizeof (Crc_check_flag) == 1);                        <== pass

    sbSysFlags is an array of 4 bytes, but the comment suggests sbSysFlags might be treated as a 32-bit variable; any 32-bit write to m_Sb_Secure_data.sbSysFlags will fail as it is not correctly 4-byte aligned. The struct order must be changed if that is the case, or padded by using a union.

    Please post in a reply the lines of code which write to Crc_check_flag and m_Sb_Secure_data so we can help further

    Edit: To set a data breakpoint in IAR right-click on the variable definition and Set Data Breakpoint. Then right-click on the data breakpoint red blob to edit properties if needed

Children
No Data
Related