Hello, I’m working on a project on Arduino Due, I’d like to save/write data on Flash, in order to avoid the installation of external eeprom.
I’ve installed the library DueFlashStorage.
I’m using the software Logiclab (IEC PLC language). The code is written on flash from the address 0xC0000.
On DueFlashstorage.h the starting default address is the first byte of Flash1, that is 0xC0000.
I’m able to read the bytes using the function: DueFlashStorage.read, and I find exactly the builded code.
After the last code used address, I read FF on each location.
My purpose is to take just 1 Kb for storing data at the end of Flash1, in order to avoid risk of code conflict.
I performed the following test:
-
I modified the line from #define FLASH_START ((byte*)IFLASH1_ADDR) to #define FLASH_START ((byte*)(IFLASH1_ADDR+offset)). When I load the Sketch, Arduino goes in stop. I tried with a lot of offset values out of code area, but nothing, the sketch is not executed.
-
I returned back leaving FLASH_START line without offset. Arduino goes in RUN. I tried to write a free address by the function: DueFlashStorage.write. When I do it Arduino goes in stop.
-
I tried to set IFLASH0_ADDR on FLASH_START line…but nothing… Arduino goes in stop.
It seems a problem of flash locking/unlocking…but I don’t know how to solve it.
Can you help me?
When you receive the error message : Flash page locked, a workaround that was found is to unlock with Bossac:
In the IDE window, go to File / Preferences, then click in the url at the bottom of preferences:
c:\Users....\AppData\Local\Arduino15\preferences.txt
Then go to: packages>arduino>hardware>sam>1.6.x>platform.txt
Copy and past platform.txt into a new blank IDE window (without setup() and loop()
At the end of the file, you will find:
-e -w -v -b change this by:
-e -w -v -u -b
For the meaning of -u (unlock all Flash pages), see:
http://www.shumatech.com/web/products/bossa
Then copy the entire new file in platform.txt, save and close all IDE windows.
Open a new IDE window with the minimal sketch (setup() and loop()), all Flash pages should be unlocked now.
Apart from this, IMO you don't have to worry a risk of conflict in Flash.
Thank you ard_newbie for your indications.
I did it, but the problem is already present, but I did some additional test and maybe I can better describe what's happening.
I wrote a value on a flash address by dueflashstorage.write function enabled by a push button: Arduino stops.
When I reset arduino, the loop restart and I found the correct value I wrote on the same address!!!
So it seems that I'm able to write...the problem is that after writing, something else stops Arduino...
IMO the issue is not to be found with DueFlashStorage, but the code you have with the button pressed. Maybe an issue with debouncing.
Did you try the example skecthes that come with the library ? did you have issues with them ?
I can exclude problems of button debouncing, because I activated the write function in other ways (always...by timer...etc)...But The problem is always present.
I followed the example, but i had to adapt It to Logiclab development tool...I'm quite sure to have done the right things...maybe can be a problem caused by some instruction.
The problem is that i don't have a c code to share here and to let you help me.
The only thing I can share is a builded file .lst generated by Logiclab. Can be useful for you?