AN11008 flash storage code hard faults

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

AN11008 flash storage code hard faults

817件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JSalisbury on Fri Aug 26 10:08:50 MST 2011
Hi,
I am starting to use the code supplied with AN11008 and have noticed some hard faults, they seem to occour about line 782 of flash_nvol.c It seems as if the pointer provided to *TmpVarRec is somtimes outside the memory space and values such as 0x5xxxxxxx have been seen is the line *TmpVarRec=*VarRec safe, as there is an array in the variable record?

for (Byte = 0; Byte < 256; Byte++) Buffer[Byte] = 0xFF;

    // get offset of temporary variable record in 256 byte segment
    TmpVarRec = (VARIABLE_RECORD *)(Buffer + (Offset % 256));
    // copy variable record
    *TmpVarRec = *VarRec;
for (Byte = 0; Byte < MAX_VARIABLE_SIZE; Byte++)
        {
        TmpVarRec->Data[Byte] = VarRec->Data[Byte];
        }
     

Should it be more like the code below?

for (Byte = 0; Byte < 256; Byte++) Buffer[Byte] = 0xFF;

    // get offset of temporary variable record in 256 byte segment
    TmpVarRec = (VARIABLE_RECORD *)(Buffer + (Offset % 256));
    // copy variable record
    //*TmpVarRec = *VarRec;
    TmpVarRec->Checksum = VarRec->Checksum;
    TmpVarRec->Flags = VarRec->Flags;
    TmpVarRec->Id = VarRec->Id;
 



Thanks
0 件の賞賛
返信
1 返信

689件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Wed Jan 18 07:11:56 MST 2012
Hello,

*TmpVarRec = *VarRec; copies the content of the VarRec pointer to the address of the TmpVarRec pointer, because they are both of the VARIABLE_RECORD * type. All the bytes of the structure are copied. This makes the following line redundant, but it works fine.
  for (Byte = 0; Byte < MAX_VARIABLE_SIZE; Byte++) TmpVarRec->Data[Byte] = VarRec->Data[Byte];
SECTOR_RECORD structure size = 48
VARIABLE_RECORD structure size = 16

With one call to NVOL_SetVariableRecord, a flash block of 256 is written. The 256 bytes will exactly accomodate 1sector+ 13 variable records, or 16 variable records. With modified structure sizes the TmpVarRec pointer could write outside the Buffer array. This happens if Offset > (256 - the size of the VARIABLE_RECORD structure). Therefore the question, did you modify the structure sizes?
0 件の賞賛
返信