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

STM32F103 RTX Using External Memory for Stack and Heap

How do I setup Keil uVision to use external memory for stack and heap functionality?

From what I have gather reading various posts on the forum the order of processor execution is:

Startup.s -> __main -> __rt_entry -> C main()

From what I understand I would have to modify this by adding processor and FSMC bus initialization:

Startup.s -> Call SystemInit_ExtMemCtl -> __main -> __rt_entry -> C main()

Does Keil provide any example code for this in their directories, c:\Keil, which is the default installation path?

Has anyone done this successfully for this target?

  • I never tried to do this - I let the linker choose for me. Either way, I think you need to have a look at the linker and utilities guide of the RealView toolchain.

  • Yes thats very much possible.

    You would have to implement __user_initial_stackheap and pass the correct values.

    Allocate Heap and Stack on the external memory using AREA or other equivalent on the external memory and then pass the starting address and size to the above routine.

    the implementation could look like this..

    __user_initial_stackheap

    IMPORT __heap_base IMPORT Heap_Mem IMPORT __heap_limit

    LDR R0, = Heap_Mem LDR R1, =(Stack_Mem + Stack_Size) LDR R2, = (Heap_Mem + Heap_Size) LDR R3, = Stack_Mem BX LR

    this code fragment should go into the "assembly" init file. Ensure that external memory (FSMC) is initialized before calling __main. The latest initialization files do come with External memory initialization routines.

    ; Dummy SystemInit_ExtMemCtl function
    SystemInit_ExtMemCtl PROC EXPORT SystemInit_ExtMemCtl [WEAK] BX LR ENDP

    ; Reset handler routine
    Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main

    LDR R0, = SystemInit_ExtMemCtl ; initialize external memory controller BLX R0

    LDR R1, = __initial_sp ; restore original stack pointer MSR MSP, R1

    LDR R0, =__main BX R0 ENDP

    Useful links...

    infocenter.arm.com/.../index.jsp
    http://www.keil.com/support/man/docs/armlib/armlib_cihhdahf.htm