Changing Emulated EEPROM location and Size

Working libraries, libraries being ported and related hardware
Post Reply
matimatil
Posts: 4
Joined: Wed Sep 16, 2020 10:31 pm

Changing Emulated EEPROM location and Size

Post by matimatil »

Hello!
I have a project using a Bluepill in which I want to use about 10Kb to emulate an EEPROM, I have about 60% of flash in use, so the plan is to have it next to that (while inspecting the used flash up to now by the program I should be able to insert this EEPROM starting from 0x0800A000). I also want the data to be writable in chunks of 1Kb without disturbing whats written on the other chunks (For example, write from 0x0800A000 to 0x0800A400, without changing 0x0800A400 to 0x0800A800, and so on). From what I understand this should be possible since the sector size of the STM32F103 is 1Kb.

In my code I have the following code to test where the data is being written to (i then check if that is the case by reading the flash manually using the STM32CubeProgrammer software):

Code: Select all

void setup() {
  eeprom_buffered_write_byte(0, 250);
  eeprom_buffered_write_byte(1, 250);
  eeprom_buffer_flush();
This is being written to address 0x0801FC00 (near the end of the 128kb of flash available, even though I am compiling for the STM32F103c8 with 64kb).

I have created a file named build_opt.h with the following:

Code: Select all

-FLASH_BASE_ADDRESS=0x0800A000
But that did nothing, everything is still being written in 0x0801FC00

It's my first time using build_opt, i don't know if I am doing something wrong or if I am missing another define that I should overwrite.
Also, if I happen to resolve that, i don't know how to make the EEPROM buffer a fix size (1Kb in this case), and choose programatically where that should be located in flash.
matimatil
Posts: 4
Joined: Wed Sep 16, 2020 10:31 pm

Re: Changing Emulated EEPROM location and Size

Post by matimatil »

Nevermind, I ended up rewritting part of the EEPROM library, making the eeprom_buffer a fixed 1kb size and allowing the functions eeprom_buffer_fill() and eeprom_buffer_flush() to take an address of the absolute memory location you want to write. It's a bit dangerous but not so different to how the original works, as long as you don't write over your own code on flash.

For this a used a define "EMULATED_EEPROM_START" with the address of a chunk of flash I knew was already free and past my executable code, and a PAGE_SIZE of 1024. I then passed eeprom_buffer_flush(EMULATED_EEPROM_START + thePageYouWantToWrite * PAGE_SIZE). The same for eeprom_buffer_fill.

I understand this is not the original way maybe because of protection, but now I have the option to use all the remaining flash as a place to store user presets.
Post Reply

Return to “Libraries & Hardware”