openocd 如何支持FreeRTOS 8.1.2

沉寂了数年,认为我们应该分享一下。前段时间通过FreeRTOS做点什么,大家纷纷拿出来拍砖。

我应该说,Linux现在粉丝。所以,我的业余时间来分享它通常应用的经验Linux作为桌面开发平台。无需再费周折。进入专题。

选择FreeRTOS对不是应为他的代码是怎样的优秀,而是由于他在自由软件社区展现出的非常强的生命力。要知道。假设一个自由软件社区足够的活跃,就意味着有很多其它的爱好者不停的解决和修正他执行的过程中遇到的诸多问题。

因为本人的工作中会採用STM32的CortexM的MCU。所以兴许的调试方法会以STM32LDiscovery的开发板为例。

FreeRTOS 公布包中有针对不同平台的移植和实例。要想在Linux主机交叉编译须要选用arm-none-eabi-gcc这种编译工具链。而选用ST的MCU后一个便宜的ST-Link可以作为调试工具,而STM32LDiscovery的板子上自带就有这种工具。硬件调试工具提供的下载调试程序的通道,还须要一个可以支持GDB Server的服务程序才干用arm-none-eabi-gdb完毕代码的调试。

以下的站点讲述了一个st-link的Linux工具能够支持下载调试你的二进制代码。

http://www.wolinlabs.com/blog/linux.stm32.discovery.gcc.html

我个人比較喜欢openocd,他有自己特有的telnet模式能够对目标板进行各种设置。他在支持标准GDB Server的同一时候还针对嵌入式系统提供RTOS的支持,非常多人不太了解这对调试有何优点。假设用gdb调试Linux下的多线程程序能够用info thread这种命令观察线程的执行状态,当然能够非常容的检查线程栈溢出等情况。

准备资源

下载最新的openocd。系统自带的多半太陈旧。嵌入式系统的发展要比PC更快

git clone git://git.code.sf.net/p/openocd/code  openocd

FreeRTOS 8.1.2

为FreeRTOS 8.1.2打补丁

openocd对FreeRTOS的支持。须要在执行openocd的时候增加configure -rtos auto选项。以下是我改动过的openocd board 脚本文件

# This is an STM32L discovery board with a single STM32L152RBT6 chip.
# http://www.st.com/internet/evalboard/product/250990.jsp

source [find interface/stlink-v2.cfg]

transport select hla_swd

set WORKAREASIZE 0x4000
source [find target/stm32l.cfg]

# use hardware reset, connect under reset
reset_config srst_only srst_nogate

$_TARGETNAME configure -rtos auto

执行的时候仅仅须要例如以下命令

openocd -f board/stm32ldiscovery.cfg

这时候假设你用arm-none-eabi-gdb通过target remote:3333 load代码的时候,会显示没有检測的RTOS。

网上找了些帖子。都没有解决。大概说明是openocd採用了7.6.2之前版本号的一个优先级变量,可是假设你把FreeRTOS换成之前的版本号仍旧不能成功检測。

我研究了下面FreeRTOS 8.1.2的代码,发现加回原来的这个全局优先级变量能够解决问题。并且仅仅是两条语句对于FreeRTOS优先级调度应该没有什么影响


在task文件里寻找例如以下行,

PRIVILEGED_DATA static volatile TickType_t xTickCount                 = ( TickType_t ) 0U;

在以下增加这一行

PRIVILEGED_DATA static unsigned portBASE_TYPE uxTopUsedPriority         = tskIDLE_PRIORITY;


在函数xTaskGenericCreate中的例如以下代码

            uxTaskNumber++;
 
            #if ( configUSE_TRACE_FACILITY == 1 )
            {
                /* Add a counter into the TCB for tracing only. */
                pxNewTCB->uxTCBNumber = uxTaskNumber;
            }
            #endif /* configUSE_TRACE_FACILITY */

的前面增加

            #if ( configUSE_TRACE_FACILITY == 1 )
            if( pxNewTCB->uxPriority > uxTopUsedPriority )
            {
                uxTopUsedPriority = pxNewTCB->uxPriority;
            }
            #endif /* configUSE_TRACE_FACILITY */

又一次编译FreeRTOS的实例

(原创文章请著名出处http://blog.csdn.net/rickleaf)

openocd FreeRTOS 调试

开启gdb server

openocd -f board/stm32ldiscovery.cfg

调试下载代码

arm-none-eabi-gdb stm32l1xx_freertos.elf

load

这时候server端显演示样例如以下信息

Open On-Chip Debugger 0.9.0-dev-00186-g30203b3-dirty (2014-11-05-23:00)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 300 kHz
adapter_nsrst_delay: 100
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : clock speed 300 kHz
Info : STLINK v2 JTAG v23 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.918068
Info : stm32l.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection on tcp/3333
Info : STM32L flash size is 128kb, base address is 0x8000000
undefined debug reason 7 - target needs reset
Info : Auto-detected RTOS: FreeRTOS
adapter speed: 300 kHz
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800021c msp: 0x20004000
STM32L: Enabling HSI
adapter speed: 2000 kHz
Info : Padding image section 0 with 3 bytes
target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x20000012 msp: 0x20004000
target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x20000012 msp: 0x20004000
adapter speed: 300 kHz
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800021c msp: 0x20004000

在调试端,通过info thread来查看FreeRTOS的执行状况

GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140529-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/ricky/workspace/stm32/stm32l1xx_freertos/Debug/stm32l1xx_freertos.elf...done.
(gdb) tar rem:3333
Remote debugging using :3333
0x00000000 in ?? ()
(gdb) load
Loading section .isr_vector, size 0x24c lma 0x8000000
Loading section .text, size 0x3df9 lma 0x800024c
Loading section .data, size 0xa4 lma 0x8004048
Start address 0x800010c, load size 16617
Transfer rate: 4 KB/sec, 5539 bytes/write.
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
[Switching to Thread 536872480]
0x08002b78 in prvCheckTasksWaitingTermination ()
    at ../system/src/FreeRTOS/Source/tasks.c:2859
2859            while( uxTasksDeleted > ( UBaseType_t ) 0U )
(gdb) info thread
[New Thread 536871864]
[New Thread 536873328]
[New Thread 536871248]
  Id   Target Id         Frame
  4    Thread 536871248 (LED3) 0x08001b90 in vPortYield ()
    at ../system/src/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c:371
  3    Thread 536873328 (Tmr Svc) 0x08001b90 in vPortYield ()
    at ../system/src/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c:371
  2    Thread 536871864 (LED4) 0x08001b90 in vPortYield ()
    at ../system/src/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c:371
* 1    Thread 536872480 (IDLE :  : Running) 0x08002b78 in prvCheckTasksWaitingTermination () at ../system/src/FreeRTOS/Source/tasks.c:2859
(gdb)


至此我们能够用openocd做一些和FreeRTOS更紧密的调试了。

关于笔者是怎样构建stm32的freertos的编译环境的。我会在后面的文章讲述。

(原创文章请著名出处http://blog.csdn.net/rickleaf)


版权声明:本文博客原创文章,博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/mfrbuaa/p/4739064.html