Alberto
>>I don't understand the code
The code is run from SRAM; notice that fnRAM_code() is called rather than the reference routine.
In fact I actually use this:
static unsigned short fnFlashRoutine[] = { // to avoid potential compiler in-lining of the routine (removing position independency) the machine code is used directly
0x2180, // MOVS r1,#0x80 load the value 0x80 (command complete interrupt flag) to register r1
0x7001, // STRB r1,[r0,#0x00] write r1 (0x80) to the passed pointer location (r0)
0x7801, // LDRB r1,[r0,#0x00] read back from the same location to r1
0x0609, // LSLS r1,r1,#24 shift the register content by 24 bits to the left so that the command complete interrupt flag is at bit 31
0xd5fc, // BPL -4 if the command complete interrupt flag bit is '0' (register content is not negative value) branch back to read its value again
0x4770 // BX lr return from sub-routine
};
because it avoids any risk of different compiler and optimisations from causing it to fail (for whatever reason) and assures that the amount of bytes located in RAM remain identical in each case.
There is another question recently with the same (random) LOCK UP behavior:
inconsistent 'LOCKUP' reset when programming Flash Memory
My only explanation is that there are interrupts causing this to happen....
>> error checking back in flash but it doenst go any better.
It won't change this behavior but I was pointing out that the library code that you are basing your work on is not as optimal as it could be.
Regards
Mark