Operating System CLI
1 Overview
This document introduces the CLI commands provided for inspecting the operating system state.
2 Code Path
Demo path: components\bk_cli\cli_os.c components\bk_cli\cli_mem.c
3 CLI Command Reference
The demo depends on the following configuration options:
NAME |
Description |
File |
value |
|---|---|---|---|
CONFIG_FREERTOS |
enable FreeRTOS support |
|
y |
CONFIG_FREERTOS_V10 |
use FreeRTOS v10 |
|
y |
CONFIG_CUSTOMIZE_HEAP_SIZE |
custom FreeRTOS heap size (bytes) |
|
217088 |
Supported CLI commands:
Command |
Param |
Description |
|---|---|---|
tasklist |
none |
display the current task list |
cpuload |
none |
display per-task CPU usage |
backtrace |
none |
display stack information and call chains |
osinfo |
none |
show tasklist, cpuload, and backtrace |
assert |
none |
trigger an intentional assert |
memstack |
none |
display stack usage of the current tasks |
memshow |
none |
display current heap usage |
memdump {addr} {length} |
{addr}: start |
dump data of the specified length from the specified address |
{length}: length |
||
ostop |
{1|5|10} |
report CPU usage over the specified period |
ostop_end |
none |
stop reporting CPU usage |
4 Demonstration
Display task list
Command: tasklist
[10:43:38.934]Send→◇ap_cmd tasklist
□
[10:43:38.938]Receive←◆tasklist
>>>>dump task list begin.
task state pri water no
cli X 5 539 19
IDLE R 0 328 3
Tmr Svc B 5 688 4
wpas_thread B 4 677 13
tcp/ip B 7 423 6
media_app_threa B 3 955 15
storage_task_th B 5 951 17
<<<<dump task list end.
Display CPU load
Command: cpuload
[10:48:26.552]Send→◇ap_cmd cpuload
□
[10:48:26.555]Receive←◆cpuload
>>>>dump task runtime begin.
cli 6 <1%
IDLE 447273 99%
wpas_thread 7 <1%
Tmr Svc 0 <1%
tcp/ip 0 <1%
storage_task_th 0 <1%
media_major_thr 1 <1%
core_thread 54 <1%
kmsgbk 8 <1%
event 1 <1%
tempd 1 <1%
ble 38 <1%
syswq 0 <1%
media_app_threa 0 <1%
<<<<dump task runtime end.
Display task stack information
Command: backtrace (prints task name, stack address range, current SP, overflow flag, and call chain)
[11:00:56.436]Send→◇ap_cmd backtrace
□
[11:00:56.440]Receive←◆backtrace
>>>>dump task backtrace begin.
task stack_addr top size overflow backtrace
IDLE [0x20001c6c ~ 0x2000226c] 0x2000218c 1536 0 1bc88 1bc50 1bafc c8d36 1800 1be1e
cli [0x30030390 ~ 0x30031390] 0x3003127c 4096 0 1000 1a964 1c3e4 45132 2057e 1f252 a5a4
tcp/ip [0x30025640 ~ 0x30025e40] 0x30025cdc 2048 0 1e37a 1e374 1bafc 125b74 1880 3e2e4 ...
...
<<<<dump task backtrace end.
Display overall OS information
Command: osinfo (includes backtrace, task list, and CPU load)
[10:49:26.817]Send→◇ap_cmd osinfo
□
[10:49:26.820]Receive←◆osinfo
>>>>dump task backtrace begin.
task stack_addr top size overflow backtrace
IDLE [0x20001c6c ~ 0x2000226c] 0x2000218c 1536 0 1bc88 1bc50 1bafc 74a7c 1800 1be1e
cli [0x30030390 ~ 0x30031390] 0x3003121c 4096 0 135bd4 450ba 1000 1a964 1c3e4 45132 ...
...
>>>>dump task list begin.
task state pri water no
cli X 5 536 19
IDLE R 0 328 3
...
>>>>dump task runtime begin.
cli 10 <1%
IDLE 477400 99%
...
<<<<dump task runtime end.
Trigger a forced assert
Command: assert (records general registers, key CSR values, MAC/BTWF registers, and memory data)
[11:07:05.111]Send→◇ap_cmd assert
□
[11:07:05.113]Receive←◆assert
(2013834)Assert at: cli_assert_dump_cmd:43
***********************************user except handler begin***********************************
Current regs:
1 ra x 0x2168e
2 sp x 0x300312c0
...
32 pc x 0x2168a
833 mstatus x 0x80
...
<<<<dump task runtime end.
memstack – display current stack usage for tasks
[10:38:13.578]Send→◇ap_cmd memstack
□
[10:38:13.598]Receive←◆memstack
task stack_size address peak_used current_used water
cli 4096 0x300303e0-0x300313e0 0xbf4 0x174 0x40c
IDLE 1536 0x20001c6c-0x2000226c 0x238 0xe0 0x3c8
...
total_stack_space: used:42496, the rest:38236
memshow – display heap usage
[10:36:41.587]Send→◇ap_cmd memshow
□
[10:36:41.587]Receive←◆memshow
name total free minimum peak
heap 217088 163200 153216 63872
psram 1048576 1048560 1048560 16
memdump – dump memory at a specified address
[10:52:09.129]Send→◇ap_cmd memdump 0x0 16
□
[10:52:09.139]Receive←◆memdump 0x0 16
f3 22 20 34 63 84 02 00 6f 00 20 06 f3 27 a0 7c
$
[10:53:02.349]Receive←◆memdump 0x44000400 16
78 03 00 00 78 03 00 00 78 03 00 00 78 03 00 00
Display CPU load for a specified duration
Command: ostop 1|5|10 (reports CPU usage for 1, 5, or 10 seconds; outputs periodic updates while active).
Note: requires macro CONFIG_FREERTOS_HISTORY_CPU_PERCENT (disabled by default). Enabling it consumes additional memory.
Example with ostop 5:
[10:33:48.295 T]ap_cmd ostop 5
[10:33:48.389 R]ap_cmd ostop 5
os:D(18200):create shell_handle, tcb=60701c48, stack=[60700020-60701c20:7168], prio=5
>>>>dump task runtime begin.
...
<<<<dump task runtime end.
[10:33:53.370 R]>>>>dump task runtime begin.
...
<<<<dump task runtime end.
Stop displaying CPU load
Command: ostop_end (must be called to stop the output started by ostop)
[15:30:02.018 T]ostop_end
[15:30:02.048 R]ostop_end
os:I(165182):create shell_handle, tcb=28020ce0, stack=[28032350-28033f50:7168], prio=5