A very interesting topic for me, since I’m also searching for better diagnosis solutions to analyse the stack usage and especially hard faults.
Currently only the address at which the error happened will be output (this sometimes only works on a LCD, the message sometimes doesn’t reach the MIOS Terminal - this could be solved in future by changing the stack pointer to a safe location, and to run only the important MIOS32 functions anymore (handling MIDI + special terminal commands)
Back to topic: each thread has it’s own stack, which is configured with xTaskCreate.
Example:
xTaskCreate(TASK_MIDI, (signed portCHAR *)"MIDI", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_MIDI, NULL);
xTaskCreate(TASK_Period1mS, (signed portCHAR *)"Period1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD1MS, NULL);
xTaskCreate(TASK_Period1mS_LowPrio, (signed portCHAR *)"Period1mS_LP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD1MS_LOW_PRIO, NULL);
xTaskCreate(TASK_Pattern, (signed portCHAR *)"Pattern", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PATTERN, &xPatternHandle);
[/code]
here the stack size of each thread is the default value (configMINIMAL_STACK_SIZE) which is configured with MIOS32_MINIMAL_STACK_SIZE)
I also wrote some more informations about this parameter:
[code]
// Stack size for FreeRTOS tasks as defined by the programming model
// Note that each task maintains it's own stack!
// If you want to define a different stack size for your application tasks
// (-\> xTaskCreate() function), keep in mind that it has to be divided by 4,
// since the stack width of ARM is 32bit.
// The FreeRTOS define "configMINIMAL\_STACK\_SIZE" is (MIOS32\_MINIMAL\_STACK\_SIZE/4)
// it can be used in applications as well, e.g.
// xTaskCreate(TASK\_Period1mS, (signed portCHAR \*)"Period1mS", configMINIMAL\_STACK\_SIZE, NULL, PRIORITY\_TASK\_PERIOD1MS, NULL);
#define MIOS32\_MINIMAL\_STACK\_SIZE 1100
This also means, that you could run a thread will a higher stack size, and all other threads with the default stack size to reduce the memory consumption:
// run MIDI task with stack size 1500
xTaskCreate(TASK_MIDI, (signed portCHAR *)"MIDI", 1500/4, NULL, PRIORITY_TASK_MIDI, NULL);
[/code]
Another possibility would be to increase the heap.
It's 10k (10*1024) by default, to use 14k instead write:
[code]
// reserved memory for FreeRTOS pvPortMalloc function
#define MIOS32\_HEAP\_SIZE 14\*1024
into your mios32_config.h file. Could you please show me your vTaskList() setup? It would be interesting for me as well - an adapted handler for MIOS32 could be added to modules/freertos_utils/freertos_utils.c, currently it only outputs the runtime stats. In order to find out, how many bytes a thread consumes, just increase the stack size of the particular thread, increase the heap, determine the stack consumption, optimized the configuration. Some more hints (we are almost out of topic now, but I guess that this is interesting to know): With following lines you can determine the stack address in the current function:
{
int x;
MIOS32_MIDI_SendDebugMessage("Stack: 0x%08x\n", (unsigned)&x);
}
[/code]
and will following code you can display the stack (e.g. to display the watermark bytes):
[code]
{
u8 \*stackAddress = (u8 \*)0x20082460; // e.g. determined with umm\_info(1, NULL)
u32 stackSize = MIOS32\_MINIMAL\_STACK\_SIZE;
MIOS32\_MIDI\_SendDebugHexDump(stackAddress, stackSize);
}
Last but not least: I think that I should implement a less costly version of MIOS32_MIDI_SendDebugMessage - e.g. MIOS32_MIDI_SendDebugString - which doesn’t consume so much stack by itself, and which allows to output a string with any length
Best Regards, Thorsten.