Store Params in Flash ATMEGA328P

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everybody

I'm new using ATMEGA devices (ATMEGA328P), and I have a question. I want to use the flash as EEPROM to store infomation. I mean, I 'm using EEPROM also, but now is full, and I need to store more information.

I have seen that there are functions to read and write flash , but I only can use this function in the boot Section.

How can I use the flash to store program information?

Thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sit down with a cup of tea.

Write down your storage requirements. e.g. max size
Write down which storage is changed frequently and how often.
Write down the amount of storage that is changed infrequently.
Write down the 'current size' of your application binary.

Post the results.
Everything is possible. We can advise a suitable strategy.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How much data do you need to write, and how often?

Trying to make you aware that the flash wears down faster than the EEPROM, and that the flash is written in pages (changing one byte adds one to the "wear count" of the complete page) whereas the EEPROM is accessed by bytes.

If this will be a problem, then consider e.g. an external EEPROM.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Before the change, my program has this size:

Program Memory Usage: 18968 bytes 57,9 % Full
Data Memory Usage : 1156 bytes 56,4 % Full
EEPROM Memory Usage : 467 bytes 45,6 % Full

Now I have a array that is stored in EEPROM:

"char user[50][7]"

I want to increase to "char user[200][7]"

Actually, I'm storing the information of users in EEPROM, but if I increase this information to 200 users, I must use flash.

This information musn't change frequently, only with a new user

Thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have a spare 10kB of flash memory. e.g. 18k app + 10k data + 4k boot.

It is quite practical to store your data in flash but it gets a bit fiddly. e.g. wear levelling, updating a flash sector, ...

Quite honestly, an external I2C eeprom is the easiest way to do things. e.g. 24C256 (or smaller)

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We can't change the PCB, this is the reason for I want to write the information in flash.

Then, how can I use the flash to store program information?

Thank so much

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Then, how can I use the flash to store program information?


SPM

Usually SPm is used to implement bootloaders so if you search either just "SPM" or "SPM bootloader" you should find masses of prior traffic.

the key thing about SPM is that it must execute in the BLS (another good search term).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then, when I have to update any code, do I have to jump to the boot to call SPM function and return to my application code?

Now I have 2 different projects with bootloader and application, with two hex. How can I do?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

We can't change the PCB

Put this on a note, and put that note in the "lessons learned" box:

Do not finalize the hardware until you know the software requirements, and which requirements they in turn put on the hardware.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's an improvement of an existing product, and I don't want to change de hardware

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Then, when I have to update any code, do I have to jump to the boot to call SPM function and return to my application code?

Now I have 2 different projects with bootloader and application, with two hex. How can I do?


I'm not talking about a bootloader. I'm talking about some "helper routines" added onto the app itself that do SPM. The only requirement is that for their SPm to work the routines that do it must be positioned in the BLS. But this is still part of the app, not a separate bootloader (unless you really want the facility to reprogram the entire flash including the app code and not just the data?)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't have to change the board, just make a daughter board with the spi EEPROM and plug it onto the isp connector.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jccordill wrote:
You don't have to change the board, just make a daughter board with the spi EEPROM and plug it onto the isp connector.

JC


Why?
I'd use the Flash.
If it's only written to infrequently then, IMO, it's a better solution that adding a daughter board to the putative SIP connector.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Quote:

Then, when I have to update any code, do I have to jump to the boot to call SPM function and return to my application code?

Now I have 2 different projects with bootloader and application, with two hex. How can I do?


I'm not talking about a bootloader. I'm talking about some "helper routines" added onto the app itself that do SPM. The only requirement is that for their SPm to work the routines that do it must be positioned in the BLS. But this is still part of the app, not a separate bootloader (unless you really want the facility to reprogram the entire flash including the app code and not just the data?)

In the bootloader, I have a routine to reprogram the app code.

I have two project, one for the boot, and the other for the application. How can I jump to a function in the boot and return at the same point of program?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have the bootloader export its flash_page reprogram routine via a jump table or agreed/fixed entry point or similar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Have the bootloader export its flash_page reprogram routine via a jump table or agreed/fixed entry point or similar.

@clawson or @depunto,
This is exactly what I want to do as well. Can you describe this method in more detail?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

depunto wrote:
I want to increase to "char user[200][7]"

Actually, I'm storing the information of users in EEPROM, but if I increase this information to 200 users, I must use flash.

This information musn't change frequently, only with a new user

In that case, wear on the flash is not an issue.
You would only need to update a page at most 20 times.
Coding would be easier if you used char user[200][8] and aligned it on a page boundary.
The flash used would increase from 1400 to 1600 bytes and no user's data would cross a page boundary.

Iluvatar is the better part of Valar.