- Part 0 開發(fā)工具安裝
- Part 1 編譯環(huán)境搭建
- Part 2 調(diào)試環(huán)境搭建
- Part 3 FreeRTOS Mulit-threads Debug
VSCode下 搭建 ARM Cortex-M 開發(fā)環(huán)境 -- Part 3 FreeRTOS Multi-threads Debug
前言
本章旨在記錄如何在VSCode Debug環(huán)境下打開FreeRTOS Multi-threads Debug功能虫给,包含以下內(nèi)容:
- 修改OpenOCD config文件從而打開OpenOCD RTOS Support功能
- 定義uxTopUsedPriority變量
- 修改LinkScript避免uxTopUsedPriority變量被優(yōu)化掉
- VSCode Debug時查看FreeRTOS下各個task狀況
修改OpenOCD config文件從而打開OpenOCD RTOS Support功能
GDB本身是Support Multi-threads Debug的(例如info threads)毫玖。為了實現(xiàn)FreeRTOS下的Multi-threads debug,我們需要首先打開OpenOCD的RTOS Support功能:
-
在OpenOCD Config文件-rtos FreeRTOS Option
該步要做的事情很簡單:只需要在openocd config文件中增加“-rtos FreeRTOS”即可(如下代碼)
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -rtos FreeRTOS
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME stm32f2x 0 0 0 0 $_TARGETNAME
定義uxTopUsedPriority變量
-
在Kernel/FreeRTOS/portable/GCC/ARM_CM4F/port.c中定義uxTopUsedPriority變量
該步要做的事情也很簡單:只需要在Kernel/FreeRTOS/portable/GCC/ARM_CM4F/port.c中定義uxTopUsedPriority變量(如下代碼)
要注意的是:uxTopUsedPriority變量 一定需要用 __attribute__((used))修飾,從而避免uxTopUsedPriority變量在編譯階段就被優(yōu)化掉了
/* Each task maintains its own interrupt status in the critical nesting
variable. */
static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
__attribute__((used)) const UBaseType_t uxTopUsedPriority = configMAX_PRIORITIES - 1;
修改LinkScript避免uxTopUsedPriority變量被優(yōu)化掉
-
在頂層Makefile文件中增加--undefined=uxTopUsedPriority
該步要做的事情也很簡單:只需要在在頂層Makefile文件中增加--undefined=uxTopUsedPriority(如下代碼)
該步的作用是避免uxTopUsedPriority變量在Link階段被優(yōu)化掉
# LDFLAGS = --specs=nano.specs -lnosys -nostartfiles
# LDFLAGS += -Wl,-wrap=malloc -Wl,-wrap=calloc -Wl,-wrap=realloc -Wl,-wrap=free
# LDFLAGS += -Wl,-T./LinkerScripts/STM32F429ZI_FLASH.ld -Wl,--gc-sections
LDFLAGS += -nostartfiles --gc-sections
LDFLAGS += --undefined=uxTopUsedPriority
VSCode Debug時查看FreeRTOS下各個task狀況
以上步驟完成后烁登,我們再按照Part3的內(nèi)容Debug時就會發(fā)現(xiàn):暫停Target后奶陈,在VSCode Debug界面的調(diào)用堆棧下可以顯示該Project中各個Tasks的callgraph可
需要注意的時易阳,Multi-Thread debug下第一次按“開始調(diào)試”會連上后自動斷開。遇到這個狀況不用擔心吃粒,只需要再按一次“開始調(diào)試”即可潦俺。(這個現(xiàn)象是VSCode已知bug:https://github.com/Microsoft/vscode-cpptools/issues/1075)
Screenshot from 2019-08-17 10-32-31.png
本章總結(jié)
至此,我們在VSCode下debug Freertos multi-threads又更加方便了一點:可以在debug的時候同時查看各個task callgraph了^_^徐勃。
整個工程我已經(jīng)Upload到Github, 歡迎大家下載事示!
https://github.com/TuringChenChao/STM32-VSCode