BriscoeTech / Arduino-FreeRTOS-SAMD21

A port of FreeRTOS that runs on Arduino Samd21 boards
63 stars 19 forks source link

Application managed heap #5

Closed nanosonde closed 5 years ago

nanosonde commented 5 years ago

"If you figure out how to use heap_2, let me know!"

Have you already considered this config option? https://www.freertos.org/a00110.html#configAPPLICATION_ALLOCATED_HEAP

You just have to set this to 1 and provide a global uint8_t array in the application code: uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];

From the docs: "If heap_1.c, heap_2.c or heap_4.c is used, and configAPPLICATION_ALLOCATED_HEAP is set to 1, then the application writer must provide a uint8_t array with the exact name and dimension as shown below. The array will be used as the FreeRTOS heap. How the array is placed at a specific memory location is dependent on the compiler being used - refer to your compiler's documentation. "

BriscoeTech commented 5 years ago

Hello nanosonde!

Thanks you so much for posting this, was able to get it setup and working well based on your explanation :-)

After doing some testing, I decided ultimately not to implement heap_2 into this repository. What I didn't think about was that there are multiple arduino classes out there, like neopixels and oleds, where I cannot get them to work if they are declared and initialized on a tasks stack, but work properly if they are created on the global heap and used/initialized by the tasks. This turns into a issue since if we have to declare a fixed array size for the rtos heap (ideally all the ram), but are also eating up unknown amounts of heap for these global classes. Its hard to predict how much you need for the global classes and it turned into me guessing and checking how much I could or couldn't use for the rtos heap. A great learning experience to say the least!

I did find a nice library someone wrote called Arduino-MemoryFree, which lets you measure the heap before the rtos is started. I added this to Basic_RTOS_Example2.

Thanks again!