Page 1 of 2
ChibiOS/RT and external RAM
Posted: Sun Apr 14, 2013 11:15 am
by Tectu
Morning folks,
I'd need some external RAM in a project at some point. How does ChibiOS/RT work with external RAM?
Using an STM32, I'd add it to the Bank 1 of the FSMC interface. I guess I'd have to add a new section in the linker script then, or how does this work in cooperation with ChibiOS/RT? Will it be possible to use chHeapAlloc() and it will also use the external memory or do I always have to read and write to the external memory manually by myself?
~ Tectu
Re: ChibiOS/RT and external RAM
Posted: Sun Apr 14, 2013 12:48 pm
by Giovanni
You may create another heap in the extra RAM.
Giovanni
Re: ChibiOS/RT and external RAM
Posted: Sun Apr 14, 2013 2:37 pm
by Tectu
Is there a documentation showing how one does that or may you give a quick step-by-step guide? When I got my external RAM working, I'll create some tutorial in the community section of the wiki.
~ Tectu
Re: ChibiOS/RT and external RAM
Posted: Sun Apr 14, 2013 3:02 pm
by Giovanni
It is the documentation of the function chHeapInit().
Giovanni
Re: ChibiOS/RT and external RAM
Posted: Sun Apr 14, 2013 4:49 pm
by Tectu
Okay, this seems to be straight forward. I hope that I can still ask in case of I don't get it working

By the way, is it possible to make a contious pool from the internal and the external memory so you always work with the default heap? If it's possible, I guess it's still not a good idea because of performance and latency issues?
~ Tectu
Re: ChibiOS/RT and external RAM
Posted: Sun Apr 14, 2013 5:25 pm
by Tectu
One more question: When using external SDRAM, you always have to work with pages. I guess this is no problem at all since the OS will abstract this, right?
~ Tectu
Re: ChibiOS/RT and external RAM
Posted: Sun Apr 14, 2013 6:22 pm
by Giovanni
The OS simply does not care about the RAM type and organization, only performance could be affected.
Giovanni
Re: ChibiOS/RT and external RAM
Posted: Sat May 04, 2013 5:42 pm
by Tectu
Okay, finally found time to catch this and now I already need some more help, of course

The reference manual of the STM32F407 says that the FSMC segment for external SRAM starts at
0x6000 0000 (yes, the RAM is connected to the first bank (NE1)). However, I'm a bit confused by the second argument of the chHeapInit() routine. As far as I understand, the second parameter is a pointer to the base address of where the memory beginns, no? Why is this a void pointer?
I tried like this:
Code: Select all
static struct memory_heap *ext_heap; // this will be our heap pointer
static int ext_heap_base = 0x60000000; // this is the base address
static size_t ext_heap_size = 10240; // this is the size of the new heap
chHeapInit(ext_heap, (void*)&ext_heap_base, ext_heap_size); /* 10k heap on external RAM */
Am I doing it right?

~ Tectu
Re: ChibiOS/RT and external RAM
Posted: Sat May 04, 2013 6:36 pm
by Giovanni
No, you are passing the address of ext_heap_base.
static struct memory_heap ext_heap
chHeapInit(&ext_heap, (void*)0x60000000, 10240);
Giovanni
Re: ChibiOS/RT and external RAM
Posted: Sat May 04, 2013 7:38 pm
by Tectu
Giovanni wrote:static struct memory_heap ext_heap
chHeapInit(&ext_heap, (void*)0x60000000, 10240);
Are you sure that this is the way to go (first argument) ?
Code: Select all
main.c:36:2: error: incompatible type for argument 1 of 'chHeapAlloc'
/home/tectu/projects/resources/chibios/os/kernel/include/chheap.h:82:9: note: expected 'struct MemoryHeap *' but argument is of type 'struct memory_heap'
That error looks somehow odd... When I use
MemoryMap instead of
memory_map, it complaints about incomplete type.
~ Tectu