AnsweredAssumed Answered

Trouble reading from the flash.

Question asked by dinrail on Nov 12, 2013
Latest reply on Nov 14, 2013 by dinrail

if I read the flash with the following codes in main(), it works

 

char key[64];

 


flashAddress = ( unsigned long *)EE_KEY;

    pArray =( unsigned long *)key;

    for (i = 0; i < 16; i = i+4)

    {


*pArray++ = *flashAddress++;

    }

 

but since I read the flash in different part of the program, so I'd like to use a more general routine to read it, so I use a function ReadFromFlash

 

void ReadFromFlash(unsigned long *pArray, unsigned long ulStartAddress, unsigned int uiSize)

{

    volatile unsigned long *myflashAddress;

    unsigned long * mypArray;

    unsigned int i = 0;

 

    myflashAddress = ( unsigned long      *)ulStartAddress;

    mypArray=( unsigned long      *)pArray;

    for (i = 0; i < uiSize; i = i+4)

    {

        *mypArray++ = *myflashAddress++;

    }

}

 

and try to read the same block using 

 

ReadFromFlash((unsigned long*) key, (unsigned long)EE_KEY,16);

 

but the program hangs

 

So I placed a break point at *mypArray++ = *myflashAddress++; inside ReadFromFlash

 

and reset and run the program again, when the program stopped at the break point, if I hit F5 to resume, the program will hang at line 140 of C:\Keil\Analog\common\startup_ADuCM360.s. but if I hit F10 (step over) four times, the program will run without any glitch.

 

if I change char key[64]; to unsigned long key[64]; it works fine, too (please note that I am only reading 16 bytes)

 

Any idea on what can cause this? (the same codes work fine when placed in main())

Outcomes