This week I pushed my basic FreeRTOS port onto a release branch on GIT (yay) as functionality is good. It’s very simple. It has 3 apps related to USB, FPGA and TCP/IP.

The USB CDC app task maintains the state of the driver and creates another task whose job is checking the status of certain global variables and printing messages to the COM port accordingly. The second app is merely one task which transmits a bit-stream to the FPGA through bit-banging after which the task is deleted and never runs again. The third app is also one task which runs forever. It is a simple HTTP web-page.

I also learned much about memory in FreeRTOS. I ran into a problem when I was adding the third app (HTTP) which was basically one more task. I wasn’t really concerned about optimizing memory use as I just wanted everything to run fine first, not to mention 512kb of RAM is plenty. Therefore memory being a problem wasn’t my first conclusion. But I will not talk about that rollercoaster, instead just the part where I conclude it’s the memory.

The part: In FreeRTOS each task is allocated a stack onto the FreeRTOS heap. I did some math and found that my tasks in total were using around ~13kb at the time. ISRs called from tasks also take up 512 bytes. Queues, scheduler.. everything was using a bit of memory and it was slowly racking up to +20kb. When I reduce the amount of stack the new task was taking up everything ran fine again…

I discover​ that you can modify the total heap size for FreeRTOS. I discover that it was set to 20kb. I yell on the inside. I increase the heap size. Happy ever after.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.