Skip to content

Commit d8966e9

Browse files
authored
Merge pull request #2 from jan019/update-linker-scripts-for-fill-sensor
Change linker script memory layout to accomodate emulated EEPROM for laser
2 parents 0673c37 + 81d9f96 commit d8966e9

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

variants/STM32G0xx/G070RBT/ldscript.ld

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,51 @@ _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
4141
_Min_Heap_Size = 0x400 ; /* required amount of heap */
4242
_Min_Stack_Size = 0x800 ; /* required amount of stack */
4343

44-
/* Define the size of the ID storage and the flash size */
45-
ID_AND_HW_VERSION_STORAGE_SIZE = 0x800; /* 2 KB */
46-
FLASH_SIZE = LD_MAX_SIZE - LD_FLASH_OFFSET - ID_AND_HW_VERSION_STORAGE_SIZE;
44+
/* ----------------- Device / layout constants ----------------- */
45+
FLASH_BASE_ADDR = 0x08000000;
4746

47+
/* Flash page size on STM32G070 = 2 KB (0x800) */
48+
FLASH_PAGE_SIZE = 0x800;
49+
50+
/* Ccustom ID and HW version area size: one page (2 KB) */
51+
ID_AND_HW_VERSION_STORAGE_SIZE = 0x800; /* 2 KB */
52+
53+
/* Arduino EEPROM emulation: reserve one page (2 KB) */
54+
EEPROM_EMU_SIZE = 0x800; /* 2 KB */
55+
56+
/* Total flash available to the linker (e.g., 128K on STM32G070RB) is LD_MAX_SIZE
57+
Application starts at FLASH_BASE_ADDR + LD_FLASH_OFFSET */
58+
/* "LINKER:--defsym=LD_FLASH_OFFSET=0"
59+
"LINKER:--defsym=LD_MAX_SIZE=131072"
60+
"LINKER:--defsym=LD_MAX_DATA_SIZE=36864" */
61+
FLASH_APP_ORIGIN = FLASH_BASE_ADDR + LD_FLASH_OFFSET;
62+
63+
/* Application flash length = total - offset - ID - EEPROM emu */
64+
FLASH_APP_SIZE = LD_MAX_SIZE - LD_FLASH_OFFSET
65+
- ID_AND_HW_VERSION_STORAGE_SIZE
66+
- EEPROM_EMU_SIZE;
67+
68+
/* ID section sits right after the app */
69+
/* with current setup the value of this is 0x0801F000*/
70+
ID_AND_HW_VERSION_STORAGE_ORIGIN = FLASH_APP_ORIGIN + FLASH_APP_SIZE;
71+
72+
/* EEPROM emu occupies the very end of flash */
73+
/* with current setup the value of this is 0x0801F800*/
74+
EEPROM_EMU_ORIGIN = ID_AND_HW_VERSION_STORAGE_ORIGIN + ID_AND_HW_VERSION_STORAGE_SIZE;
75+
76+
/* LD_MAX_SIZE in hexa is 0x08020000*/
4877
/* Memories definition */
4978
MEMORY
5079
{
5180
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
52-
FLASH (rx) : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = FLASH_SIZE
81+
FLASH (rx) : ORIGIN = FLASH_APP_ORIGIN, LENGTH = FLASH_APP_SIZE
82+
83+
/* 2 KB page reserved for ID/HW version (just before EEPROM emu) */
84+
ID_AND_HW_VERSION_STORAGE (rw) : ORIGIN = ID_AND_HW_VERSION_STORAGE_ORIGIN,
85+
LENGTH = ID_AND_HW_VERSION_STORAGE_SIZE
5386

54-
/* Reserve the last 2 KB for the ID */
55-
ID_AND_HW_VERSION_STORAGE (rw) : ORIGIN = 0x8000000 + FLASH_SIZE, LENGTH = ID_AND_HW_VERSION_STORAGE_SIZE
87+
/* Last 4 KB reserved for Arduino EEPROM emulation */
88+
EEPROM_EMU (r) : ORIGIN = EEPROM_EMU_ORIGIN, LENGTH = EEPROM_EMU_SIZE
5689
}
5790

5891
/* Sections */

0 commit comments

Comments
 (0)