Edit online

栈大小配置

栈设置

Luban-Lite 栈需要增大或者减小可以通过 ps 命令来判断:
aic /> ps
thread           pri  status      sp     stack size max used left tick  error
---------------- ---  ------- ---------- ----------  ------  ---------- ---
serial            25  suspend 0x00000344 0x00000400    84%   0x00000009 O
touch             25  suspend 0x00000294 0x00001000    16%   0x00000002 OK
thread            20  suspend 0x000002b0 0x00001000    69%   0x00000013 OK
thread            20  suspend 0x00000288 0x00008000    02%   0x00000013 OK
LVGL              20  ready   0x00000258 0x00008000    16%   0x00000006 OK
tshell            20  running 0x000005ac 0x00002000    18%   0x00000004 OK
usbh_hub0          0  suspend 0x00000384 0x00001000    37%   0x00000002 OK
mmcsd_detect      22  suspend 0x000002d8 0x00002000    13%   0x00000006 OK
alarmsvc          10  suspend 0x0000028c 0x00000800    31%   0x00000005 OK
tidle0            31  ready   0x00000240 0x00000800    30%   0x00000008 OK

serial 线程使用率 84%,需要适当增大

中断栈

Luban-Lite 中断服务程序运行在独立的栈中,大小可以在 menuconfig 配置界面中修改:
Board options  --->
    Mem Options  --->
        (4096) Interrupt stack siz      // 大小为 4k

RT-Thread 线程栈

Kernel 为 RT-Thread 时,几个典型线程的栈空间大小的配置:

  • main 线程栈大小
    Rt-Thread options  --->
        RT-Thread Components  --->
            (2048) Set main thread stack size  // 大小为 2k
  • idle 线程栈大小

    Rt-Thread options  --->
        RT-Thread Kernel  --->
            (2048) The stack size of idle thread                // 大小为 2k
            (4) Alignment size for CPU architecture data access // CONFIG_RT_ALIGN_SIZE
    重要:

    在使用系统 printf 打印浮点时,要求线程堆栈为 8 字节对齐。此时 CONFIG_RT_ALIGN_SIZE 需要设置为 8,同时线程栈大小也是 8 的整数倍。

  • shell 线程栈大小

    Rt-Thread options  --->
        RT-Thread Components  --->
            MSH: command shell  --->
                (4096) The stack size for thread  // 大小为 4k

Baremetal 用户栈

裸机环境时只有一个用户栈,栈大小如下配置:
Baremetal options  --->
    (8192) Main loop stack                    // AIC_NORMALSTACK_SIZE, 大小为 8k
重要:

在使用系统 printf 打印浮点时,要求线程堆栈为 8 字节对齐。此时 AIC_NORMALSTACK_SIZE 需要设置为 8 的整数倍。