Hello. I use stm32f429, I write on keil, I do the initial setup via CubeMX. I need immediately after the initialization of SDRAM to transfer a bunch of my program there.

Found such code on the Internet

void dummy_function1(void) { __asm { EXPORT __heap_base __heap_base EQU 0xD0400000 EXPORT __heap_limit __heap_limit EQU 0x400000 } } 

But the compiler does not compile it, displaying such errors

../Src/main.c(227): error: # 3061: unrecognized instruction opcode EXPORT __heap_base ../Src/main.c(228): error: # 3061: unrecognized instruction opcode __heap_base EQU 0xD0400000
../Src/main.c(229): error: # 3061: unrecognized instruction opcode EXPORT __heap_limit ../Src/main.c(230): error: # 3061: unrecognized instruction opcode __heap_limit EQU 0x400000

Can you please tell me how to change the position of the heap?

    1 answer 1

    According to your assembly code - most likely meant EXTERN , not EXPORT . And the variables __heap_base and __heap_limit declared in the linker script. See if they really are that way.

    In general, if this code works, then it should be placed at the very beginning of the program (that is, in ResetHandler , before the main call). Only then can something happen for you. After the entire data memory (heap, stack, bss) is initialized, it is unlikely that you will be able to change it. But, judging by your previous question, you are using freeRTOS , and, most likely, the memory manager of this operating system: pvPortMalloc and vPortFree . This system takes as a heap a large array of static memory, and further allocates pieces from this array when you use the mechanism for allocating and freeing memory.

    Try exploring freeRTOS_CONFIG.h and find the size and location of its heap. In the found macros, instead of integers, specify your function, which would return the correct heap location. But keep in mind that you need to either not use the heap before moving it, or take care of copying the entire heap to a new place, updating all the pointers to it.


    UPD. And if you are not wise, then I would immediately in the linker script prescribe that the heap should be located in SDRAM and would not use it before I initialized the FMC.

    • If I set up FMC in main, and do not call dynamic memory allocation functions (malloc for example) before setting up FMC, then the heap is not used (if we assume that the initialization code was written completely by me)? - kvazik
    • Initialization code - do you mean setting FMC or initializing bss in ResetHandler ? If you did not touch the start code, you cannot be completely sure of this. I think you'd better explore the code in ResetHandler , which is located at startup_stm32fXXXX.s . There you will find the exact answer to your question. It is unlikely, but still if the heap is used there, then you have to place the FMC setup code in ResetHandler . - maestro
    • How tasks functions in freeRTOS. Rather, from where they take the memory to work. A normal function stores all of its variables on the stack. Does freeRTOS create its own stack version and everything is there? Or, when calling a taxi, does it overwrite itself on the main stack? - kvazik
    • @kvazik, freeRTOS creates its own stack for each task. But from what memory I don’t know. Obviously, this memory also needs to be transferred to SDRAM. - maestro