You have to init the memory used for the stack:

Have a look in the normal tasking init , and you will see the call out to
init the stack, that you neeed to call.

Also Assuming ARM it has to be 8 byte aligned. So you need attributes on
your variable called stack to set the alignment.

David
-----Original Message-----
From: Fotis Panagiotopoulos [mailto:f.j.pa...@gmail.com]
Sent: Saturday, February 06, 2021 6:08 AM
To: dev@nuttx.apache.org
Subject: Task with statically allocated stack

Hi,

I am trying to create a new task using a statically allocated stack.

Here is my code:

static struct task_tcb_s tcb;
static uint8_t stack[CONFIG_NETWORK_THREAD_STACKSIZE]

void start_my_thread()
{
     memset(&tcb, 0, sizeof(struct task_tcb_s));
     tcb.cmn.flags = TCB_FLAG_TTYPE_TASK;

     int ret = nxtask_init(&tcb, "Network", CONFIG_NETWORK_THREAD_PRIORITY,
stack, CONFIG_NETWORK_THREAD_STACKSIZE, network_th, NULL);
     if (ret < 0)
     {
          //error handling...
     }

     nxtask_activate(&tcb.cmn);
}


This new thread seems to be working OK (I haven't done any extensive
testing yet), but running ps in nsh yields:

    5  80 FIFO     Task    --- Ready              00000000 008156 008156
100.0%! Network

The stack is always reported as 100% full. I tried increasing it to
excessive numbers but it still.
I believe that I have configured something wrong? Or this is not the
correct way to init a task with a static stack?

Reply via email to