This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cannot init heap using scatter file and C++ startup (Cortex-M4)

Hello,

I need help with heap initialization using scatter file and C++ startup.

MCU is STM32F407VGT6 (Cortex-M4).

Compiler is ARM Compiler 6.7, C++14.

The problem is that all variables which I create dinamically on the heap have wrong addresses. My HEAP locates in CCM (starts from 0x10000000) but those variables have address from 0x08000000. And it is a FLASH memory! And I don't understand how it is happened. While initialization of stack performs in correct way... Below are my C++ startup and scatter file.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef STARTUP_HPP
#define STARTUP_HPP
#include <common/core.hpp>
#include <registers/Scb.hpp>
#include <registers/Rcc.hpp>
#define ATTR_DEFAULT_HANDLER __attribute__((weak, alias ("_ZN5mylib3mcu10interrupts14defaultHandlerEv")))
int main();
extern int Image$$STACK$$ZI$$Limit;
int &__initial_sp = Image$$STACK$$ZI$$Limit;
extern "C"
{
__attribute__((naked, used))
void __user_setup_stackheap()
{
asm(
"LDR sp, =__initial_sp\n"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
FLASH 0x08000000 0x00100000
{
ER_IROM1 +0 0x00100000
{
*.o (interrupts, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
}
SRAM 0x20000000 0x00020000
{
ZI +0 ZEROPAD
{
.ANY (+ZI, +RW)
}
}
CCM 0x10000000 0x00010000
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

As you see - these files use the same logic like in standart startup_stm32f407xx.s.But standart file works and my - no...

I also want to note that if I eneble MICROLIB in settings of Keil, add ARM_LIB_STACK and ARM_LIB_HEAP to scatter file, my implementation begins to work correctly.

But I want to do my startup without MICROLIB.

If you know where I am wrong in my code, please help.

Best regards, Andrey.

0