Writing the program to the FLASH

I am attempting to write a program update to the FLASH from my program. I have it successfully downloaded into a 1MB array, then when I attempt to copy it to FLASH using NAFlashWrite() it says that it worked, but when I reboot I just get the 9-1-1 error.

  1. I am using NAAppOffsetInFlash to determine the start sector (7).
  2. I am using NAFlashGetSectorSizes() to determine how much to write. (10 sectors)
  3. I use NAFlashErase() before writing.
  4. NAFlashWrite() is really slow (5 seconds a sector) - is this an indication of a problem?

Anyone who has done this before have any ideas?

-Erik

For those interested, I got it to work. It turns out that the attribute ((packed)) doesn’t work very well.

-Erik

Erik (All interested),

Per the ARM - Architecture Reference Manual (pg. A2-26, 2001, Issue E) can be UNPREDICTABLE and should therefore be avoided.

*** From the aforementioned document:

The architecturally defined behavior of a load/store instruction which generates an unaligned access is one of the following:

  • It is UNPREDICTABLE
  • It ignores the low-order address bits that make the access unaligned. This means it effectively uses teh formula (address AND 0xFFFFFFFE) for a halfword access, and uses the formula (address AND 0xFFFFFFFC) for a word access.
  • It ignores the low-order address bits that make the access unaligned for the memory access itself, but then uses those low-order bits to control a rotation of the loaded data. (This behavior applies only to the LDR and SWP instructions).

Which of these three options applies to a load/store instruction depends on which instruction it is, and is documented on the instruction pages.

*** End

Essentially, avoid packing structures like the plague. The common reason for packing that I have come across is when implementing a protocol. In such a case it would be best to leave the structure unpacked and manually create the outgoing buffer in its packed form (the reverse would be necessary for incoming buffers).

Cameron

That is exactly what I did. :wink: