2023-01-07 11:55 PM
When creating a new project in the STM32CubeIDE for a STM32F103C8 (64k flash, 20k ram), the generated linker-script contains:
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + (LENGTH(RAM) / 2); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K
}
This places the stack (_estack) at 0x20005000 = 0x20000000 + 20k. When checking the memory at (_estack - 1) via the debugger, it can't be read. So while startup the STM32 immediately goes into a hard fault.
In fact, the last readable address is 0x200027ff, which suggests, that the address is actually in words rather than bytes : 0x20000000 + 10k = 0x20002800.
Changing the line to
_estack = ORIGIN(RAM) + (LENGTH(RAM) / 2); /* end of "RAM" Ram type memory */
places the stack at 0x20002800 and fixes the problem.
This can be reproduced with a "blue pill".
Solved! Go to Solution.
2023-01-08 02:44 AM
Please close - this is embarrassing - the board actually contains a STM32F103C6 with only 10k SRAM.
2023-01-07 11:57 PM
Correction: The original line is of course
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
2023-01-08 02:44 AM
Please close - this is embarrassing - the board actually contains a STM32F103C6 with only 10k SRAM.