kengineer Posted April 4, 2017 Report Posted April 4, 2017 (edited) The xTaskCreate function is called in ugfx from the GOS layer when creating a thread. This function will be called to create the GTIMER thread with a default intended stack size of 2048 bytes. However, the usStackDepth as defined by FreeRTOS is: // usStackDepth - the stack size DEFINED IN WORDS. Which will be dependent on the platform and port base type size. On my current 32 bit Cortex-M0+ platform, passing a stack size of 2048 will actually allocate 8192 bytes on the FreeRTOS heap! I was wondering why ugfx was gobbling up so much memory in this thread. I have reduced this by defining the GTIMER_THREAD_WORKAREA_SIZE symbol as 512, however, just something to keep in mind as I'm sure this wasn't intended. Edited April 4, 2017 by kengineer grammar corrections
inmarket Posted April 4, 2017 Report Posted April 4, 2017 I suggest that in the gfxCreateThread function we should divide by sizeof (WORD) before passing it to xCreateThread. That will keep the meaning of the stack size passed to gfxCreateThread consistent accross platforms. If we do so, is WORD a defined FreeRTOS type or should we use sizeof (int) or something else? Thanks for finding this!
Joel Bodenmann Posted April 5, 2017 Report Posted April 5, 2017 Unfortunately it seems like FreeRTOS doesn't provide a way to query/retrieve the word size - but I might be wrong. Using sizeof(int) appears "wrong" to me because it's purely the choice of the compiler how wide an int is. Using the same processor/target with two different compilers might yield two different sizeof(int) values. I agree that most compilers probably show consistent behavior here but we currently have a list of 74 compilers that are supported by µGFX (and a subset which is actively tested). Therefore, having a solution that works with just most compilers seems inadequate to me. Unless of course FreeRTOS uses sizeof(int) itself internally to determine the word size. Does anybody know? Thank you for bringing this to our attention. Much appreciated!
kengineer Posted April 5, 2017 Author Report Posted April 5, 2017 (edited) I believe it may be defined by the FreeRTOS type StackType_t which is defined in the individual port of FreeRTOS. Looks like they get sizeof and multiply it by the stack depth passed when they malloc tasks for creation. This is defined is the tasks.c which is the generic (not platform specific) set of functions: //(tasks.c prvAllocateTCBAndStack function) /* Allocate space for the stack used by the task being created. The base of the stack memory stored in the TCB so the task can be deleted later if required. */ pxNewTCB->pxStack = ( StackType_t * ) pvPortMallocAligned( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ), puxStackBuffer ); In the port for my platform, this is defined and typedef'd as follows: #define portSTACK_TYPE uint32_t typedef portSTACK_TYPE StackType_t; Since each FreeRTOS port adjusts this type for the destination platform/compiler, I would think that using sizeof(StackType_t) would be sufficient. Edited April 5, 2017 by kengineer Added more details
inmarket Posted April 6, 2017 Report Posted April 6, 2017 This has now been updated in the master repository. As I don't use FreeRTOS myself can you please check that I got it right? Thanks for finding this and your assistance in solving it.
Joel Bodenmann Posted April 6, 2017 Report Posted April 6, 2017 Looks good to me - Would appreciate it if @kengineer would give it a look anyway as well: https://git.ugfx.io/uGFX/uGFX/commit/23ceb054fcf9a6d7e29359b197e268ba03f1ce3c
kengineer Posted April 6, 2017 Author Report Posted April 6, 2017 I will pull the changes and test them on my platform ASAP.
kengineer Posted April 10, 2017 Author Report Posted April 10, 2017 Confirmed that this works on my platform.
Joel Bodenmann Posted April 10, 2017 Report Posted April 10, 2017 Great! Thanks for your help on this.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now