Allocate FLASH memory for user data which then can be written to and read from (uVision Keil)
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:
- Allocate 2K of flash memory to hold specific constants in Flash.
- Initialize this memory with initial constants (i.e. uint32_t)
- Be able to read and write to this specific memory location during program run time.
This is what I have tried already:
- Method 1
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- Method 2
; *************************************************************
; *** 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.
