2024-08-10 07:02 AM
I have an idea which I am trying to implement, but have not been successful so far. The project I am working on is using STM32G071K8 microcontroller. The project is implemented in uVision Keil.
Requirements:
This is what I have tried already:
I edited the original scatter (.sct) file by reducing the 64K of flash down to 62K and creating a user flash area of 2K at the end of it (Page 31).
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x0000F800 { ; Main flash region reduced by 2KB
ER_IROM1 0x08000000 0x0000F800 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
}
LR_IROM2 0x0800F800 0x00000800 { ; User flash region (last 2KB of 64KB)
user_flash.o (+RO) ; Object file containing user-defined section
}
}
RW_IRAM1 0x20000000 0x00009000 { ; RW data
.ANY (+RW +ZI)
}
after this in the main program I tried to initialize this memory region with zeros.
__attribute__((section("user_flash"))) const unsigned char user_flash[2048] = {0};
However, I am receiving errors which even after looking into I do not have a good explanation as how to fix it:
error: user_flash changed binding to STB_GLOBAL
error: symbol 'user_flash' is already defined
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x0000F800 { ; load region size_region
ER_IROM1 0x08000000 0x0000F800 { ; load address = execution address, size reduced by 2KB
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
USER_FLASH 0x0800F800 0x00000800 { ; User Flash region at the last 2KB of 64KB flash
user_flash.o (+RO) ; Object file containing zero-initialized section
}
RW_IRAM1 0x20000000 0x00009000 { ; RW data
.ANY (+RW +ZI)
}
}
However this method also does not seem to work also giving the exact same error.
What is the correct way to achieve this? I appreciate your help in advance.
2024-08-10 11:38 AM - edited 2024-08-10 11:59 AM
UPDATE:
I have successfully created and added 2K execution region.
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x0000F800 { ; load region size_region (64KB total)
ER_IROM1 0x08000000 0x0000F800 { ; main execution region, reduced by 2KB
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
ER_PARAMETER_FLASH 0x0800F800 0x00000800 { ; 2KB region for parameters
*(.parameter_section)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00009000 { ; RW data
.ANY (+RW +ZI)
}
}
I then created 'parameter_struct' with some initial vlaues.
__attribute__((section("parameter_section"))) const struct {
uint32_t id;
uint32_t value;
uint32_t status;
} parameter_struct = {1, 2, 3};
Looking at the .map file i can see that this memory region indeed was created:
Execution Region ER_PARAMETER_FLASH (Exec base: 0x0800f800, Load base: 0x08001a90, Size: 0x00000000, Max: 0x00000800, ABSOLUTE)
However, the linker seems to remove these bytes:
Removing main.o(parameter_section), (12 bytes).
This happens regardless if I reference it in the main code or I don't.
So then I proceed with a linker 'Misc controls' section in which I instructed that parameter section should not be removed:
--keep=main.o(parameter_section)
I can see it then that the parameter section is not written to this flash memory region instead it appears to be the last entry in ER_IROM1 with wrong exec and load addresses:
Exec Addr Load Addr Size Type Attr Idx E Section Name Object
0x08001a90 0x08001a90 0x0000000c Data RO 86 parameter_section main.o
In addition, the error that I keep on getting in build output window is:
.\Objects\ICFW70102.sct(15): warning: L6314W: No section matches pattern *(.parameter_section).
Am I not initializing this memory region correctly with my struct or is there something else that might not be right?
Please try to help me as this is of great importance for me. Much appreciated in advance.
2024-08-11 07:47 AM - edited 2024-08-12 08:03 AM
Have a look at AN4296 "Using CCM SRAM with Keil [...]" which includes a step-by-step example of customizing a (keil) scatter file to place annotated functions into a custom execution region.
Side issue 1: According to section 7.3 of the armlink manual version 5.06, I suspect the syntax is *(parameter_section) not *(.parameter_section).
Side issue 2: According to section 7.3 of same doc, I don't think your use of .ANY(+RO) in the new section does what you want at all.
I suggest you purchase a wide assortment of snacks (both sweet and savory) and then spend some quality time with the manual.