I'm using LPC1788 IAP to write to Flash and I'm a little confused on what's going on. I'm trying to write 8 bytes of data to Flash memory with 2 tehniques:

1) With one which is logical to me and it doesn't work

for(i=0; i<8; i++) {
    iap_copy_to_flash(&serial_no[i], OFFSET_SERIAL+i, 1);

2) With one which is not logical to me and it works

 iap_copy_to_flash((BYTE*)serial_no, OFFSET_SERIAL, 8);

OFFSET SERIAL is 0x00040000 and serial_no[8] is array of BYTES

Why first won't work and second works?

I'm only getting problem when writing array to Flash sector, when writing BYTE, WORD, DWORD variables everything is okay.

Here is iap_copy_to_flash function http://pastebin.com/gNBkVWef and copy_ram_to_flash function http://pastebin.com/uVptXD2D. I will be very thankful if someone explains to me what is wrong with my thinking. Thanks.

  • \$\begingroup\$ You have forgotten to include the definition of serial_no, so we don't know what exactly your piece of code is doing... \$\endgroup\$ – Laszlo Valko Jun 18 '15 at 7:36
  • \$\begingroup\$ Its array of 8 BYTES. \$\endgroup\$ – user76920 Jun 18 '15 at 7:37
  • \$\begingroup\$ Then try serial_no + i instead of &serial_no[i]. \$\endgroup\$ – Laszlo Valko Jun 18 '15 at 9:36

Look in the documentation for those IAP functions. LPC17xx does not allow byte writes to flash, and I am not sure whether DWORD writes are alowed either.

The flash memory itself is wider than one byte (actually 64 bits IIRC) - so you cannot write a single byte without touching others.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy