Page 1 of 1

EEPROM

Posted: Thu Apr 23, 2020 9:16 am
by mauriziostm32
Hi guys

I'm using Roger Clark's core... I''m familiarizing with the included EEPROM library... In the beginning was just only dark... but fortunately I found this PDF from ST that clarify a lot, it is " Implementing EEPROM emulation" AN2594 :

https://www.st.com/resource/en/applicat ... ronics.pdf
I guess the library is built around this document...

I tried to search more in the old https://stm32duinoforum.com/ but links are missing for now...
I have some points that are not entirely clear... so I go in order of importance...
  • 1) in the example I saw that the Page size is configurable... right now it is set at 1kB... it give me 256 storable virtual addresses (16 bit taken by the virtual address and 16 bit taken by the data I'm storing)
The questions about point 1:
I don't need so many values... does make sense to have a smaller page of 64 storable values (64 x 32 / 8 byte) ? or the MCU architecture is done in a way that also if you have a smaller page, that 1 kB is however not usable in other way.... ?
Does the fact of having 1KB reserved for a page benefit the Wear leveling algorithm so the virtual addresses can be written every time in different physical addresses in the MCU Flash?

If I didn't get it wrong the library will use actually 2 KB (2 pages) to have 256 cells of 16 bit each... in order to move the virtual addresses (0 to 255) and their data... deleting and rewriting... when the data need to be modified... 10.000 of writing capability is more than enough for 20 years in my case...
  • 2) in the example everything is written in Hex... I tried to use Decimals for addresses and value stored and it seems to work
Is there a reason to not use decimals? Maybe is because you can write bigger numbers using less characters in Hex? I mean I'm using VIRTUAL addresses, I'm not writing in one specific memory allocation of the MCU... so decimal could be ok?

  • 3) Empty (not written) virtual addresses return 130 dec (82 hex)…
Can I use this value reliably to check if a virtual address reserved for a variable has been previously written? Apart from 0 (cell written) and 130 there are not other status used by the library right?

Thanks

Maurizio

Re: EEPROM

Posted: Thu Apr 23, 2020 12:09 pm
by mrburnette
The initial port of EEPROM library was posted here:
https://forum.arduino.cc/index.php?topi ... msg2066363

Page size is set here:
https://github.com/rogerclarkmelbourne/ ... M/EEPROM.h

Code: Select all

#ifndef EEPROM_PAGE_SIZE
	#if defined (MCU_STM32F103RB)
		#define EEPROM_PAGE_SIZE	(uint16)0x400  /* Page size = 1KByte */
	#elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD)
		#define EEPROM_PAGE_SIZE	(uint16)0x800  /* Page size = 2KByte */
	#else
		#error	"No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
	#endif
#endif

Code: Select all

#ifndef EEPROM_START_ADDRESS
	#if defined (MCU_STM32F103RB)
		#define EEPROM_START_ADDRESS	((uint32)(0x8000000 + 128 * 1024 - 2 * EEPROM_PAGE_SIZE))
	#elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE)
		#define EEPROM_START_ADDRESS	((uint32)(0x8000000 + 512 * 1024 - 2 * EEPROM_PAGE_SIZE))
	#elif defined (MCU_STM32F103RD)
		#define EEPROM_START_ADDRESS	((uint32)(0x8000000 + 384 * 1024 - 2 * EEPROM_PAGE_SIZE))
	#else
		#error	"No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
	#endif
#endif

For the most part, EEPROM is as described in Arduino:
https://www.arduino.cc/en/Reference/EEPROM

Here is a soapbox post from "pjrc" :
https://forum.arduino.cc/index.php?topi ... msg2488455

The PDF you referred to does not reflect how the Roger's core implementation works. Consult the code:
https://github.com/rogerclarkmelbourne/ ... ies/EEPROM
The questions about point 1:
I don't need so many values... does make sense to have a smaller page of 64 storable values (64 x 32 / 8 byte) ? or the MCU architecture is done in a way that also if you have a smaller page, that 1 kB is however not usable in other way.... ?
Not configurable in Arduino'ish implementation. Go to I2C external (real) EEPROM if you need all of your uC flash.
https://www.hobbytronics.co.uk/arduino-external-eeprom

Sorry I do not remember more, but it was a long time ago...

Ray

Re: EEPROM

Posted: Thu Apr 23, 2020 12:33 pm
by mauriziostm32
Hi Mrburnette

Thanks for your reply... I've learnt a lot from you, reading your answers in Stm32duinoforum and Arduino..
Yes, I've already checked the library in Roger GitHub... but I was confused, because it seems form the Example Sketch that it is possible to configure the page size..


EEPROM.PageBase0 = 0x801F000;

EEPROM.PageBase1 = 0x801F800;

EEPROM.PageSize = 0x400;


Code: Select all

void loop()

{

	uint16 Status;

	uint16 Data;


….

		else if (cmd == '1')

		{

			EEPROM.PageBase0 = 0x801F000;

			EEPROM.PageBase1 = 0x801F800;

			EEPROM.PageSize  = 0x400;

			DisplayConfig();

		}
I will dig deeper

Thanks again

Maurizio

Re: EEPROM

Posted: Thu Apr 23, 2020 2:45 pm
by mrburnette
Ah, I think the confusion is because the EEPROM program should really be 2 separate programs...
The program requires the Operator to select the physical uC model: RB, ZE, RE which is really a technology decision.

Code: Select all

const char HELP_MSG[] = "Press :\r\n" \
			" 0 display configuration\r\n" \
			" 1 set configuration to 0x801F000 / 0x801F800 / 0x400 (RB MCU)\r\n" \
			" 2 set configuration to 0x801F000 / 0x801F800 / 0x800 (ZE/RE MCU)\r\n" \


From the Community, be sure to read through the entire post:
https://community.st.com/s/question/0D5 ... -page-size

Ray

Re: EEPROM

Posted: Fri Apr 24, 2020 8:12 am
by mauriziostm32
mrburnette wrote:
Thu Apr 23, 2020 2:45 pm
Ah, I think the confusion is because the EEPROM program should really be 2 separate programs...
The program requires the Operator to select the physical uC model: RB, ZE, RE which is really a technology decision.

Code: Select all

const char HELP_MSG[] = "Press :\r\n" \
			" 0 display configuration\r\n" \
			" 1 set configuration to 0x801F000 / 0x801F800 / 0x400 (RB MCU)\r\n" \
			" 2 set configuration to 0x801F000 / 0x801F800 / 0x800 (ZE/RE MCU)\r\n" \


From the Community, be sure to read through the entire post:
https://community.st.com/s/question/0D5 ... -page-size

Ray
Hi Ray

Thanks, I've got the reading and now it is clear! ;)