This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

stack overflow when first thread is started

Hi

I have just ported my code that was working without a RTOS to CMSIS RTOS and its loaded onto my cortex m3 arm and my code gets through by board initialization but as I get a stack overflow when the RTOS tries to start the first task.

I have configured 0x8200 bytes for my stack, 7 tasks, 2000 bytes for the default thread and 800 bytes for the other 6 threads. The thread viewer shows two additional threads, timer and idle.
My stack is located in the esram and is using all available bytes there.

I really do not have any idea what I have done wrong in allocating memory for the stack or in configuring the RTOS. I feel I missed something in the setup.

I was thinking about backing off the 7 threads and just try to start 1 and see if that overflows.

Is it possible to relocate my stack to my DDR memory space at 0xA0000000 so I can make the available stack size bigger? I don't know if throwing more memory at it will really solve this problem.

Does anyone have any ideas about what might be wrong or how I might go about debugging this overflow issue?

Parents
  • I started to debug the createTask function and found that it calls rt_alloc_mem (os_stack_mem, thread_def->size) and during the allocation of memory I get a hard fault when it tries to "insert list element" by writing to a mem pool pointer p.

    /* Insert new list element into the memory list */ p = (MEMP *)(((U32)p_new) + sizeof(MEMP));

    this is the store instruction that faults: STR r1,[r0,#0x00] r1 = 0x40093b2c r0 - 0xA0049c18 where r1 = p* r0 = p_new* MEMP is a memory pool data structure

    This memory pool is os_stack_size = 0xE98 and created during KernelInitialize() by a call to rt_init_mem() and osTimerThread (stacksize = 0xC8)is created ok and taking some memory from this stack memory pool.

    So at least one thread was created and there is a lot of stack memory left for my thread.

    when createThread is called with my thread it goes through the same processing but throws a hard fault at the line above. I cannot see any of the variables so I do not know what is causing this.

    The RTOS is not compiled debug I assume.

    This does not make sense to me right now. Why a hard fault?

Reply
  • I started to debug the createTask function and found that it calls rt_alloc_mem (os_stack_mem, thread_def->size) and during the allocation of memory I get a hard fault when it tries to "insert list element" by writing to a mem pool pointer p.

    /* Insert new list element into the memory list */ p = (MEMP *)(((U32)p_new) + sizeof(MEMP));

    this is the store instruction that faults: STR r1,[r0,#0x00] r1 = 0x40093b2c r0 - 0xA0049c18 where r1 = p* r0 = p_new* MEMP is a memory pool data structure

    This memory pool is os_stack_size = 0xE98 and created during KernelInitialize() by a call to rt_init_mem() and osTimerThread (stacksize = 0xC8)is created ok and taking some memory from this stack memory pool.

    So at least one thread was created and there is a lot of stack memory left for my thread.

    when createThread is called with my thread it goes through the same processing but throws a hard fault at the line above. I cannot see any of the variables so I do not know what is causing this.

    The RTOS is not compiled debug I assume.

    This does not make sense to me right now. Why a hard fault?

Children
  • Here is some additional information I found. I did not have the "if (!osKernelRunning)" when I ran. Apparently I was calling osKernelInitialize twice. It is called automatically before my main task runs which I did not realize.

    I can successfully create my timer task.

    So that was my problem it seems. Don't call KernelInitialize twice