2018-09-20 08:54 AM
I am new to the STM32. I am starting a project that requires just one byte of EEPROM.
I am using the STM32F072RBT6 on a Nucleo board.
I have been successful in getting the eeprom emulation code from the stm32cubef0 examples incorporated into code that compiles for the STM32F072RB using the eeprom.h and eeprom.c files included with the example under the STM32F091RC Applications folder.
My confusion is about how or where the Page 0 and Page 1 in this example are being allocated in FLASH, such that it is not overwriting code.
From my understanding of the example, Page 0 and Page 1 start at the beginning of FLASH (below is from the eeprom.h file):
/* Base address of the Flash sectors */
#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08000000) /* Base @ of Page 0, 2 Kbytes */
#define ADDR_FLASH_PAGE_1 ((uint32_t)0x08000800) /* Base @ of Page 1, 2 Kbytes */
According the linker file (STM32F091RCTx_FLASH.ld) that came with the example for the F091RC, there did not seem to be any provision made for the EEPROM data on these pages:
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
When I compiled my code for the F09 or F07 in Atollic TrueStudio, I checked the linker files, and they are the same.
From what I have researched, it seems to be that the linker script should be altered to account for this allocation. However, the Application note for the EEPROM emulation on the STM32F0 (AN4061) does not mention anything about this allocation. Neither does the README.txt that comes with the example code. Also, I cannot find any comments in the code related to this.
This makes me think that is is somehow being taken care of, but I cannot find out how or where.
Any assistance is appreciated.
2018-09-20 09:17 AM
Typically there are defines, and you make a hole in the memory described to the linker (script or scatter file) to accommodate them.
On an F0 where the sectors/pages are of uniform size, put them at the END of the FLASH, and shrink the size given to the linker.
Don't put them at 0x08000000, the chip needs the vector table there to start properly, and it's not something you can change.
On the F4 parts you have to basically split the memory seen by the linker because the blocks toward the front are smaller (4x 16K , 1x 64K) and those at the end are larger (128K), the large blocks take a LONG time to erase, and will STALL THE CPU longer.
2018-09-20 09:34 AM
@Community member - Thanks for the quick response!
What you say makes sense. I can make that work...
Can you explain how it is that the EEPROM emulation example from STM for the F0 uses Pages 0 & 1 without causing issues of overwriting the code that was flashed starting at the beginning of flash memory?
2018-09-20 09:51 AM
I don't use the emulation layer, but doesn't look like usable values as described.