(I've moved this question from my original thread and decided to open a new one...)
I'm using a K64 on custom board and KBOOT (but it happened also when putting the app on address zero, without Kboot). When writing to a new defined section in the text segment of the flash a hard fault is caused.
My code snippet is as follows:
include...
#ifdef __cplusplus
extern "C" {
#endif
uint16_t __attribute__((section (".MyappFlag"))) appFlag = 0xBEEF;\\after this line is executed all is well and appFlag is changed to BEEF. I see it with breakpoints.
int main(void) {
appFlag = 1; \\after this line is executed the hard fault occurs.
BOARD_BootClockRUN();
Board_Init_UART();
Board_InitLEDs();
Board_Inputs();
Board_Outputs();
the linker file which cause it is as follows:
MEMORY
{
m_interrupts (RX) : ORIGIN = 0x0000A000, LENGTH = 0x00000400
m_text (RX) : ORIGIN = 0x0000A400, LENGTH = 0x000FFBF0 - 0xA400 - 0x100
appFlag (RX) : ORIGIN = 0xFFAF0, LENGTH = 0x100 \* 0xFFAF0 = FFBF0 - 100. But doesn't matter what is the size of the flag, and I tried various addresses. always hard fault*/
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00030000
}
/* Define output sections */
SECTIONS
{
.my_section :
{
. = ALIGN(4);
KEEP(*(.MyappFlag)) /* keep my variable even if not referenced */
. = ALIGN(4);
} > appFlag
when writing the linker in that way (accessing the RAM and not the ROM-writing the appFlag to m_data_2) it works fine, but then the bin file size is huge (I guess because 0x20020000 =~512MB):
MEMORY
{
m_interrupts (RX) : ORIGIN = 0x0000A000, LENGTH = 0x00000400
m_text (RX) : ORIGIN = 0x0000A400, LENGTH = 0x00075C00
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00030000
}
/* placing appFlag section at given address:*/
.my_section 0x20020000 :
{
. = ALIGN(4);
KEEP(*(.MyappFlag)) /* keep my variable even if not referenced */
. = ALIGN(4);
} > m_data_2
Code size:
arm-none-eabi-size --format=berkeley -x --totals "BCA2.elf"
text data bss dec hex filename
0x164f0 0x8d0 0x1344 98564 18104 BCA2.elf
0x164f0 0x8d0 0x1344 98564 18104 (TOTALS)
Any ideas?