1

I'm using PIC18F67K40 microcontroller in my project. It has 1kB EEPROM memory and 128kB program memory (flash).

For now I'm using EEPROM to store my settings.

Application is "growing" and I realized that at some point 1kB will be not enough. Some of settings are arrays of pretty big structures. I realize, that flash memory has 100k 10k write cycles and that I can buy external EEPROM, but I don't want to change anything in hardware and memory in this product will never reach 2k writes for sure.

My quesion is:

How can I switch from EEPROM storage to flash storage?

  1. Do I have to recalculate some CRC after program memory changes?
  2. Do I have to define somewhere in project settings, that I'm using some flash memory for storage?
  3. Is there anything what I have to do in order to use flash memory like this?
Kamil
  • 13,363
  • 24
  • 88
  • 183

2 Answers2

2

100k writes is only the endurance of the data EEPROM not of the flash memory (only 10k writes). You could expand the endurance with a EEPROM emulation. There is a really nice library from Microchip for EEPROM emulation in flash memory.
Have a look here: EEPROM emulation

Mike
  • 4,041
  • 6
  • 20
  • 37
  • Thank you for your reply and correction about write cycles in flash. I want to know how to do it in low level without making some mess (answer for these 3 questions). Using a library will not satisfy me. – Kamil Jun 11 '19 at 23:19
0

I did this for a client a couple of years ago. I can't post the code for NDA and copyright reasons, but the basic trick was to use something called RTSP (Run Time Self Programming). RTSP may be going obsolete now, but whatever replaces it may work in a similar way.

Essentially the flash looks like a series of pages which can be written word at a time, but erased page at a time. What you will need to do is write some code that can unlock and erase a page then write to it. Once you have done this the page can be read as ordinary memory.

You don't need to change the settings. However make sure that the page you use is well clear of the program code.

If you want a CRC (usually a good move) you'll have to calculate it yourself.

R Billing
  • 11
  • 2
  • So PIC microcontroller has no crc check before it runs the program? I remember that old Nokia phones with Atmel microcontroller had such feature. It was software bootloader feature or what? – Kamil Jun 27 '19 at 09:22