2010-09-24 08:35 AM
External RAM for Stack Heap Keil uVision
2011-05-17 05:08 AM
I haven't done it with external memory, but have done a lot of pre-c boot loader stuff, and assembler.
You'd typically attack this by changing the boot vector SP/PC in startup.s to point to your own start up code and internal stack, and then change the value of SP to the external application stack once the memory has been set up. Or simply add your specific code into the regular startup code prior to jumping to __main I'd personally just code the external memory initialization in-line, in assembler, so that it didn't need to use subroutines, or external library code. The secondary issue would be why put the stack into external memory? The point of using internal memory in a cache-less CPU is that the memory is tightly coupled and runs single-cycle at 72 MHz? The *last* thing you want to park in external memory is the stack, and high-bandwidth data/code. ;__Vectors DCD __initial_sp ; Top of Stack __Vectors DCD 0x2000FFF0 ; Top of Stack (Point to top of RAM, C sets it's own) DCD Reset_Handler ; Reset Handler .. Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main .. ; Add code to initialize hardware, clocks, memory, etc in to minimally functional state. The app can reconfigure these to optimal settings later. .. LDR SP, =__initial_sp .. LDR R0, =__main BX R0 ENDP2011-05-17 05:08 AM
The only reason that I want to use external memory is because I am using a library for the file system that needs to dynamically allocate space. The amount of space it needs to allocate is more that I have in internal memory.
Since I have an external SRAM chip with 8MB of memory I want to be able to use it. Is it possible to place the heap in extenal memory and leave stack in internal memory? There is not much instriction on this except: STM32F10x_StdPeriph_Lib_V3.3.0\Project\STM32F10x_StdPeriph_Examples\FSMC\SRAM_DataMemory However, this project isn't functioning correclty.2011-05-17 05:08 AM
Well you should be able to separate the heap and stack. Beyond defining where the stack starts the C compiler/code usually has no interaction with where it is located once running. The only exceptions would be if you had an RTOS for example, which would switch between multiple task stacks, or if you were actively ''stack checking'' for a collision with the heap.
Having the stack on internal memory would mean that local variables within a subroutine would be in ''fast'' memory. Stacks are used to provide simple/lazy/elastic ''dynamic'' memory allocation in embedded systems. If the stack is getting stupidly large it probably means you have no real control of the application, and it is apt to explode when conditions stray outside usual norms. ie doing recursive descent on a directory tree, with deeper than anticipated depth, or if a file system error causes a cycle/loop in the tree. For large allocations you would really need to use the heap, and some real dynamic memory management. In the embedded world you'd need to watch for fragmentation and leakage issues very carefully. One method to attack the fragmentation would be to have a fixed pool of memory blocks of various sizes (small, sector, cluster, etc). Still you'd need a clear understanding of your actual utilization and patterns. Or you could make you own ''data'' stack and keep it separate from the execution stack. Now, for a file system application, unless there is a compelling reason to hold an entire file in contiguous memory, I would use the larger/slower memory to cache sectors from the media in a much more defined/controlled manner.2011-05-17 05:08 AM
Thank you clive1, I've been able to do this successfully.
I modified the startup.s file to do this. I left the stack on processor's internal memory. The external memory is now initialized before the RTOS (RL-RTX) is called. I have attached my startup_stm32f10x_hd.s file just in case someone else is running into this issue. Since I am using Keil uVision 4.03, there is potentially another way to do this by changing the project options to add external memory, but this does not work well, so I did not change these settings. In my project I placed the heap at starting address 0x68100000.2011-05-17 05:08 AM
I am also trying to use External RAM as heap and internal RAM as stack. By using the SRAM_Data demo I couldnt able to make external ram work. Then I try to use your .s file, but during compilation I got the error 'HW_init is not defined'.Is HW_init a library function or it is a function defined by you?If it is your function where did you define it and can you also send HW_init function code. I guess that function is like SRAM_Init, but when I use SRAM_Init instead of your HW_init I got hardfault handler exception. Can you explain where is HW_init function, and where did you define it?
Best regards.
2011-05-17 05:08 AM
Hi;
Firstly thank you for your response. I tried to use the .s file
C:\Keil\ARM\Examples\ST\STM32F10xFWLib\Examples\FSMC\SRAM_DataMemory\stm32f10x_vector.s
And I was able to use ext ram in case I didnt use RL-ARM, I think the problem occurs when I use realtime os, do you have any idea how to init extram when using RL-ARM, or it is possible to use RL-ARM with external ram.
Best regards
2011-05-17 05:08 AM
I think we might reasonably presume it is a simple routine he wrote in C, to initialize the memory controller to the settings required for his external SRAM part.
You could presumably also replace that call with some in-line code to program the FSMC, like that used in the example: C:\Keil\ARM\Examples\ST\STM32F10xFWLib\Examples\FSMC\SRAM_DataMemory\stm32f10x_vector.s2011-05-17 05:08 AM
Cut'n'paste the External SRAM initialization code from the cited example into the start up (boot code) for your RTOS.
Either insert it in-line, or put it in it's own subroutine, and call it in the code flow between the reset handler entry point, and the initialization of the RTOS itself. Should be a pretty simple thing to do.