What would happen if the stack size is not enough for the task?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What would happen if the stack size is not enough for the task?

492 Views
cencongsu
Contributor I


I face a problem:The program suddenly run into _int_kernel_isr() and I have no clue why it would happen.

Then I want to locate the code which creates the error, I check the PSP value to find out the PC address before run into the _int_kernel_isr(), now I can locate the error code, but I still don't know why it would happen.

After long time of struggle with the code, I try to increase the stack size of a task I created, and this problem solved.

So, my question is, how the stack size we assigned impact the task? How it work internally? If the stack size is not enough, why the system  would cause a HardFault exception?

0 Kudos
1 Reply

296 Views
soledad
NXP Employee
NXP Employee

Hello,

The memory assigned in the stack is not the only memory used by the task. There is another amount of bytes used to handle the task. This memory is used for some structures depending on what components are used by the task.

MQX stack usage and works with them looks like this: 
MQX run on supervisor mode. Supervisor mode stack and irq stack are set to BOOT_STACK area (size is 0x100) 
– this value depend on MQX startup sequence complexity 
– for example code which init MQX (scheduler, memory) and install/init device driver run with this stack 
– depend on real implementation and developer must know what he does when he changes something in BSP 
    (like in init_hardware, bsp_enable_card functions). 
Each task has own stack which are set in MQX task template list. 
IRQ stack is set by MQX, too – default value is set in BSP_DEFAULT_INTERRUPT_STACK_SIZE. 
When MQX runs, uses self defined stacks. 
Stacks size defines in linker file for supervisor and irq mode are important for startup only (BOOT_STACK) 

I hope this helps,


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos