2023-10-31 06:27 PM
Hi,
Currently I am using STM32L4R9 discovery board, which has 16-Mbit (2MB) PSRAM. I have been able to allocate static memory inside PSRAM by using following code and also by changing linker script file (.ld). I have attached my edited linker script with this post.
int __attribute__((section (".psram_data"))) psram_buffer[50000];
for(int i=0; i<50000; i++)
{
psram_memory[i] = i;
}
But, how can I dynamically allocate memory by using malloc() / calloc() inside PSRAM. If possible, please share some example code with me.
Thank you.
Solved! Go to Solution.
2023-11-01 10:53 AM
Hello,
In your linker file try the following:
MEMORY
{
....
....
PSRAM_HEAP (xrw) : ORIGIN = <put the PSRAM start address>, LENGTH = <put the heap region size>
}
..
..
._user_heap :
{
. = ALIGN(8);
PROVIDE ( s_heap = . );
. = . + Heap_Size;
. = ALIGN(8);
PROVIDE ( e_heap = . );
} >PSRAM_HEAP
B.R.
2023-11-01 06:39 AM
Reserve a block of memory in PSRAM, then allocate subblocks.
You can take inspiration from one of the allocators present in FreeRTOS for example.
2023-11-01 09:02 AM
2023-11-01 10:53 AM
Hello,
In your linker file try the following:
MEMORY
{
....
....
PSRAM_HEAP (xrw) : ORIGIN = <put the PSRAM start address>, LENGTH = <put the heap region size>
}
..
..
._user_heap :
{
. = ALIGN(8);
PROVIDE ( s_heap = . );
. = . + Heap_Size;
. = ALIGN(8);
PROVIDE ( e_heap = . );
} >PSRAM_HEAP
B.R.
2023-11-01 11:31 AM
That might work if not for the horrific _sbrk implementation you have..
2023-11-01 09:36 PM
Thanks. I will try this.
2023-11-01 09:37 PM
Okay. I will have a look on that. Thanks