Pages: 1 [2]   Go Down
Author Topic: Free Flash memory remaining?  (Read 418 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What I have in mind is simple, can I test the flash memory from within a sketch?  The answer seems to be no.  I'm already writing to the flash outside of the sketch, so saying that it can't be done is useful.  And if I really want to, I can test the flash with an ISP and see what's left.  In fact, I had to reload the bootloader yesterday on one chip.  So it can be done from outside a sketch.

The code I have now is constantly checking what is available in RAM, pushing to FLASH or EEPROM, and as a last resort the SD card.  The slow I/O of the SD card is causing other issues, but eventually we could work around those issues.

So can it be done?  Its a high level question that if the answer is yes, I only need a point in the right direction.  If the answer is no, then fine.  Eventually, I'll figure out a way.

Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6654
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can certainly READ the flash memory from within a sketch.  So you could theoretically start from the known end of flash and scan pages until you find one that isn't full of 0xFF (pages full of 0xFF at the end of flash are presumably "unused.")

I still don't see how you expect to "push to flash", though.

You could look at serial flash/eeprom, which is physically easy to connect to the AVR (slightly easier than an SD card), and MUCH easier to write to than an SD card (no filesystem; just a straight memory array.)  Not anywhere near as large as an SD card, but you should be able to get about 1MB for reasonable cost (actually, ridiculously cheap...): http://www.digikey.com/product-detail/en/S25FL208K0RMFI041/1274-1051-ND/3862736 is one example
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25876
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem with writing to flash from a running program is that you either have to
a) make the whole of flash memory the boot sector and suffer the inevitable  consequence of overwriting your program if when you screw-up, or
b) rewrite (and considerably expand) the existing bootloader to act as bootloader and flash writing agent for the running program.

None of this is impossible or particularly difficult, but given the limited number of erase/write cycles on flash, the other suggestions are more than worthwhile exploring.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33432
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can only write to flash if the code is running in the the last segment of the memory. This is where the boot loader lives, so in theory you could rewrite the boot loader to allow you to write to flash.
However the boot loade takes up all that memory space so you will need to program the arduino another way after you replace the boot loader . It then ceases to be an arduino.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25876
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You can only write to flash if the code is running in the the last segment of the memory
IIRC, You can also lift the restrictions on using LPM and SPM in the application area by blowing the SELFPRGEN fuse, or by using the lock protection bits (there's a subtle distinction between the methods, but I forget what it is right now), but I agree, by that point, you're not in Kansas anymore.
Making the mechanism possible is very simple, but making it safe and reliable is tricky.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

New Zealand
Offline Offline
Full Member
***
Karma: 6
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need to consult the datasheet heavily to do what you are attempting. This paragraph from the datasheet confirms some of the previous answers:
Quote
ATmega88PA, ATmega168PA and ATmega328P support a real Read-While-Write Self-Programming
mechanism. There is a separate Boot Loader Section, and the SPM instruction can
only execute from there. In ATmega48PA, there is no Read-While-Write support and no separate
Boot Loader Section. The SPM instruction can execute from the entire Flash.

So: on an Atmega328 you can ONLY write to flash from within the bootloader section.
The largest boot loader section you can have is 2048 bytes. (also confirmed in the datasheet)

My suggestion would be: Write your own "Boot Loader" that reads from serial and writes to flash, similar to the arduino bootloader, and also allow to read from flash via serial. Then program this onto a secondary atmega328 processor, and and use your arduino to read and write the flash (via serial) in the secondary processor.

Keep in mind that the flash memory only have a 10,000 write cycle endurance.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25876
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Keep in mind that the flash memory only have a 10,000 write cycle endurance
. . .and that the wear affects the whole page.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: 1 [2]   Go Up
Jump to: