Go Down

Topic: how to write and read arduino due internal flash memory? (Read 11383 times) previous topic - next topic


I need to store data in arduino due after the power down.
what i need is, to take an IR code from a remote and store in the arduino DUE internal flash memory.
i can't find any reference anywhere to how to do that, all say to write to EEPROM but on arduino DUE there is not EEPROM.


Hello riddik00,
I use the following library:

You can save/retrieve data from the internal Flash of Due. You will not lost the data even when power is down. The only way to lost the data is when you reprogram Due.

Caveat: You can 'brick' your Arduino Due if lack of power during writing/retrieving on flash. Regards,



Dear Palliser,

I am trying to use the DueFlashStorage. I am fairly new to arduino, so had few questions on this library.
1.  I am using this with ethernet shield and Due. My code is currently 32,120 (6%) of storage space. This will go up. Do you know how to change the offset of the flash page in this lib so it is not conflicting with the program itself?
2. If I use the native usb port to program, after the first time if I reprogram, IDE shows error saying flash is locked. have you come across this issue? it works ok with programming port though.

I would appreciate any inputs on this. kind regards,


1. Don't do that. The library already has that offset built in.
2. Then use the port which works.
"The problem is in the code you didn't post."



Thanks for the comment. The library already has an offset: True, but that (according to SebNil, the author) is a fixed offset. It worked for him, and it may work for me, but on his blog page, he has replied to someone that it is user's responsibility to calculate offset based on the code. So I just wanted to know how to do that in case needed.

And yes, I am using the port that works for now. This does require a second processor (for future designs if we go that way). It would be nice to keep the design simple hence I was wondering what causes the flash lock on the native programming port.


There some predefined constants that are already defined.  The Due has two banks of flash memory that I *think* are 256K each.  There are constants defined called IFLASH0_ADDR and IFLASH1_ADDR, and a few others.

Those are the base address of the two banks of flash memory.  To calculate the write address, assuming you want to put your stuff at the very back (opposite end of program memory) of the flash address space, then you would calculate it like this:

Code: [Select]
byte *writeAddr = (byte *)(IFLASH1_ADDR + IFLASH1_SIZE - sizeof(whatever_structure_you_want_store));

However, the best idea is probably to put it at the beginning of the first page that will give you the space you need.  In which case you would do something like this:

Code: [Select]
u_int pages = sizeof(whatever_you_want_stored) / IFLASH1_PAGE_SIZE;
if (sizeof(whatever_you_want_stored) % IFLASH1_PAGE_SIZE > 0) pages++;
byte *writeAddr = (byte *)(IFLASH1_ADDR + IFLASH1_SIZE - IFLASH1_PAGE_SIZE * pages);

These are absolute addresses.  After looking at his library it looks like address 0 is probably the same as IFLASH1_ADDR.  That being the case, you would use this for the writeAddr definition:

Code: [Select]
byte *writeAddr = (byte *)(IFLASH1_SIZE - IFLASH1_PAGE_SIZE * pages);



this sounds like a great library. recently did this on the NXP LPC2468 and it works like a charm. however, the brick part scares me. what if the user is a moron and decides to power down while the thing is writing? and how long does the write of, say, 100 bytes, cost anyhow? on the NXP it was done in under 200 ms.. also i'm curious as to how exactly the bricking would work?


Apologies for reviving the zombie thread.
But the answer to this last question is: use a supercapacitor to hold charge for a moment after power has been pulled. My 3D printer does this. During the unfortunate event of a short power cut, it will store its position/status into eeeprom and resume work as if nothing happened. It can only handle very short power cut periods say 1 second but yeah.

I like to spend a lot of time & money on finding ways to save time & money.

Go Up