0

We start a new software, and we think about using the MPU. We ar based our new software on FreeRTOS (with the MPU port).

We understand correctly all the segmentation about the intertask communication with the MPU. What we have difficulties, is what to do with dynamic allocation protection. By default, all the ram should be protect in user mode. Is there any documentation online that explain how we should handle the dynamic allocation ?

We would like to protect the memory as much since we will design a big software > 500K compiled code.

Regards

Jonathan

artless noise
  • 21,212
  • 6
  • 68
  • 105
Jonathan
  • 69
  • 1
  • 6

1 Answers1

0

Basically FreeRTOS offers 4 different memory allocation strategies, implemented in the heap_1.c, heap_2.c ... files in the portable/MemMang directory.

heap_1.c offers a simple alloc only implementation
heap_2.c offers a simple alloc/free implementation

The other 2 implement more advanced strategies of alloc/free. FreeRTOS will need that you at least choose one of them, because it needs this interface to do it's own resource allocation (tasks, mutexes, semaphores, etc.). For MCU that provide a memory protection unit FreeRTOS also has appropriate support.

Note that using the MPU will force you to allocate the memory using a minimum chunk size (e.g. 1KB). This can be very expensive, if you need to allocate a lot of small objects (e.g. using a std::list<int> or std::map<int,int> with many elements). You might consider to provide your own specialized allocators for such cases.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • How can be the specialized allocator for the std::xxx ? You take a bloc of memory, protect it to have an exclusive access to it and do your own allocator ? – Jonathan Nov 12 '13 at 14:40
  • @Jonathan May be [this answer](http://stackoverflow.com/a/13299384/1413395) is helpful regarding allocator refinement (I guess you're using a GCC toolchain). The other way is just to avoid such constructs in general (e.g. use a `std::vector` instead of a list if it's possible). – πάντα ῥεῖ Nov 12 '13 at 15:30
  • The std::vector will use also the allocator no ? – Jonathan Nov 13 '13 at 12:58
  • @Jonathan Yes `std::vector` also uses the allocator, but it allocates a contiguous chunk of memory to store it's contained items, while `std::list` in contrast allocates a new chunk for each item stored in it. An allocator refinement could overcome this by managing a previously allocated memory region itself in a more efficient manner, regarding which minimum memory chunk can be allocated from the low-level memory management interface. – πάντα ῥεῖ Nov 13 '13 at 13:57