Your int a is an automatic variable, meaning that it is placed on the stack.
Which stack?
Well, if vStartTask() is called from main(), the initial stack will be in use. You can find its address in the linker file (xxx.ld).
In some projects, the initial stack will be re-used (for other purposes) once the scheduler is running.
You can avoid that by placing static (or global) variables:
int main()
{
static int a;
}
The above variable will be placed in the data segment.
Or Use space in 'configTOTAL_HEAP_SIZE’
No, only when you use pvPortMalloc() to allocate an int.
I think this is a task function, so this variable is allocated on the task stack. Each task has its own stack-
If you create a task using xTaskCreate, the task stack is allocated using pvPortMalloc.
If you create a task using xTaskCreateStatic, you supply the task stack.
So, to conclude, this variable is always placed in the task stack which may have been allocated on the heap (i.e. in configTOTAL_HEAP_SIZE) at the time of task creation if the task was created using xTaskCreate.
You must have created the task using the xTaskCreate() API which allocates the task stack on the heap i.e. the ucHeap array (the size of which is defined by the configTOTAL_HEAP_SIZE macro) and because this variable takes space within the task stack which lies in the ucHeap array, the address lies in its range.
If you do not want this variable to take space on the heap then you must create the task using xTaskCreateStatic(), where you can provide the memory for the stack yourself, see here for example.