FreeRTOSConfig.h parameters editing

Working libraries, libraries being ported and related hardware
edogaldo
Posts: 283
Joined: Fri Jun 03, 2016 8:19 am

Re: FreeRTOSConfig.h parameters editing

Post by edogaldo » Sat Nov 04, 2017 2:37 pm

I was just playing with Pak's sketch using the standard freertos configuration and I got this behaviour.
Maybe Pak changed something more (i.e. some config parameter or choose an upload method that for example does not drive the Maple VCP) and I was trying to find what..

paksoft
Posts: 13
Joined: Sun Apr 10, 2016 3:16 am

Re: FreeRTOSConfig.h parameters editing

Post by paksoft » Mon Nov 06, 2017 1:37 am

I found the issue was due to the allocated stack size.
If I set:

Code: Select all

xTaskCreate( vTaskFunction, "Task 1", 1000, (void*)pcTextForTask1, 1, NULL );
xTaskCreate( vTaskFunction, "Task 2", 1000, (void*)pcTextForTask2, 2, NULL );

the code breaks and Windows can't even recognize the Maple Serial USB.
If instead I set:

Code: Select all

xTaskCreate( vTaskFunction, "Task 1", 100, (void*)pcTextForTask1, 1, NULL );
xTaskCreate( vTaskFunction, "Task 2", 100, (void*)pcTextForTask2, 2, NULL );

the code is working fine.

So it seems a memory allocation conflict issue..

Just wondering why this does not happen also to you as we are using almost the same mcu (I'm using a Maple mini in truth).

Another question: which upload method are you using?
I'm using the maple bootloader 2.0
Hello edogaldo,
Actually, I messed up the code with example from the book, I'm really sorry about that.
I've tried to test your code

Code: Select all

xTaskCreate( vTaskFunction, "Task 1", 1000, (void*)pcTextForTask1, 1, NULL );
xTaskCreate( vTaskFunction, "Task 2", 1000, (void*)pcTextForTask2, 2, NULL );
Yes, you are right, Arduino IDE compiles successfully but Windows cannot recognize the board after uploading the sketch.

By the way, do you know how to check whether the stack size is full or not. Arduino IDE shows no changes when I tried to test sketches with stack size sets to both 100 and 1000.
Sketch uses 17,052 bytes (26%) of program storage space. Maximum is 65,536 bytes.
Global variables use 11,288 bytes of dynamic memory.
pak

User avatar
Pito
Posts: 1625
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: FreeRTOSConfig.h parameters editing

Post by Pito » Mon Nov 06, 2017 1:47 pm

Global variables use 11,288 bytes of dynamic memory.
The task's stacks come to the Heap, you will not see its size there in the message (those 11kB are global vars only).
Double-check what your freertos Heap size is like:

Code: Select all

configTOTAL_HEAP_SIZE

Code: Select all

#define configMINIMAL_STACK_SIZE	( ( unsigned short ) 120 )
#define configTOTAL_HEAP_SIZE		( ( size_t ) ( 8 * 1024 ) )
Pukao Hats Cleaning Services Ltd.

victor_pv
Posts: 1735
Joined: Mon Apr 27, 2015 12:12 pm

Re: FreeRTOSConfig.h parameters editing

Post by victor_pv » Mon Nov 06, 2017 3:37 pm

FreeRTOS includes functions to track and report how full your stack gets:
http://www.freertos.org/uxTaskGetStackH ... rMark.html


I have used in the past to confirm if I had stack overflow in a task that was failing, ended up being something else, but thanks to this code I adjusted the stack of each task according to actual usage rather than estimates.
Note that the highwater mark is not how much stack is used, but how much is unused.

I had 1 task running every N ms sending the highwtermark for each of the other tasks in the serial/usb port.

Also on v9 you can use statics for pretty much everything. You can allocate your tasks stack as static variables, that way you get it reported during compilation:
http://www.freertos.org/xTaskCreateStatic.html

There are several more settings related to stack, there is config to enable stack overflow detection, and I believe that one also fills up the stack with control charaters before it start running tasks.

Adding to Pito's post, the FreeRTOS heap is used for all FreeRTOS objects, like semaphores, mutex, stacks... so those 8KB may run low quick depending what you do.

paksoft
Posts: 13
Joined: Sun Apr 10, 2016 3:16 am

Re: FreeRTOSConfig.h parameters editing

Post by paksoft » Wed Nov 08, 2017 2:13 pm

Hello Pito,
Thanks for suggestion.

Code: Select all

#define configMINIMAL_STACK_SIZE	( ( unsigned short ) 120 )
#define configTOTAL_HEAP_SIZE		( ( size_t ) ( 8 * 1024 ) )
Yes, exactly the same in FreeRTOSConfig.h.
What is the optimal value for configTOTAL_HEAP_SIZE. Is it possible for you to explain more?

Hello Victor_pv,
I've tried the example shown @ http://www.freertos.org/uxTaskGetStackH ... rMark.html.
What is the minimum value for return value of uxTaskGetStackHighWaterMark( NULL ) ?
Also on v9 you can use statics for pretty much everything. You can allocate your tasks stack as static variables, that way you get it reported during compilation:
http://www.freertos.org/xTaskCreateStatic.html
I really don't have any idea to try that example shown @ http://www.freertos.org/xTaskCreateStatic.html.
Do you mind to share sample example of xTaskCreateStatic usage?
Thanks for advice.
pak

User avatar
Pito
Posts: 1625
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: FreeRTOSConfig.h parameters editing

Post by Pito » Wed Nov 08, 2017 4:54 pm

The optimum size for the Heap?? Hmm.
Your SRAM (BPill=20kB) includes several segments, like
. initialised global vars (.data)
. uninitialised global vars (.bss)
. Heap
. stack (of the OS itself)..
So it has to fit... :)
Pukao Hats Cleaning Services Ltd.

Post Reply