其他分享
首页 > 其他分享> > JLink OB SWI 取代串口打印的方式

JLink OB SWI 取代串口打印的方式

作者:互联网

1:debug的串口被占用

2:从Keil 迁移到的LINUX下开发.

3:手上只有JLinkOB,(4线:CLK,SWIO,GND,RST)

4:设备只引出了4线(SWO 没接出)

 

环境:

JLink版本:  执行 JLinkExe 命令会先显示版本信息

SEGGER J-Link Commander V6.56a (Compiled Nov 25 2019 16:58:42)
DLL version V6.56a, compiled Nov 25 2019 16:58:26

 

Host: Ubuntu 16.04

 

A:找到JLINK 安装时的exmaple 和 RTT相关的头文件

路径:/opt/SEGGER/JLink_V656a/Samples/SEGGER_RTT_V656a.tgz

解压出来就好

 

B:使用,复制路径下的RTT文件夹和Syscalls文件夹下的文件到工程目录,makefile增加对应的源文件

 

C:编译可能报错:  xxxxx87:5: error: conflicting types for '_write_r' xxxxx

原因,是arm-gcc版本造成的,修改报错的地方的 _write_r(在 reent.h中161行) 的声明即可

修改如下

1 //extern _ssize_t _write_r _PARAMS ((struct _reent *, int, const void *, size_t));
2 extern int _write_r(struct _reent *r, int file, const void *ptr, int len);

再编译即可.

D: 实现打印:

打印代码如下:

//main.c

#include <stdio.h>
#include "SEGGER_RTT.h"

void main(){
  /*HAL init 之类的初始化*/
  SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
  SEGGER_RTT_printf(0, "printf Test: %%c,         'S' : %c.\r\n", 'S');
 while(1){
 }   
}

 

E:运行:

1:先运行 JLinkExe -Device STM32FXXXX  -Speed 4000 -If SWD

2:connect

3:r

 

4:另起窗口运行 JLinkRTTClient

 

5:回到JLink的窗口 运行 go

操作如下:

JLinkExe -Device STM32F446RE -Speed 4000 -If SWD
SEGGER J-Link Commander V6.56a (Compiled Nov 25 2019 16:58:42)
DLL version V6.56a, compiled Nov 25 2019 16:58:26

Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-STM32F072-CortexM compiled Mar  8 2020 11:15:54
Hardware version: V1.00
S/N: -1
License(s): GDB, RDI, FlashBP, FlashDL, JFlash, RDDI
VTref=3.300V


Type "connect" to establish a target connection, '?' for help
J-Link>connect 
Device "STM32F446RE" selected.


Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Found SW-DP with ID 0x2BA01477
Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
Cortex-M4 identified.
J-Link>r
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
J-Link>go
JLinkRTTClient
###RTT Client: ************************************************************ 
###RTT Client: *               SEGGER Microcontroller GmbH                * 
###RTT Client: *   Solutions for real time microcontroller applications   * 
###RTT Client: ************************************************************ 
###RTT Client: *                                                          * 
###RTT Client: *       (c) 2012 - 2016  SEGGER Microcontroller GmbH       * 
###RTT Client: *                                                          * 
###RTT Client: *     www.segger.com     Support: support@segger.com       * 
###RTT Client: *                                                          * 
###RTT Client: ************************************************************ 
###RTT Client: *                                                          * 
###RTT Client: * SEGGER J-Link RTT Client   Compiled Nov 25 2019 16:59:02 * 
###RTT Client: *                                                          * 
###RTT Client: ************************************************************ 

###RTT Client: -----------------------------------------------
###RTT Client: Connecting to J-Link RTT Server via localhost:19021 ...
###RTT Client: Connected.

SEGGER J-Link V6.56a - Real time terminal output
J-Link OB-STM32F072-CortexM compiled Mar  8 2020 11:15:54 V1.0, SN=-1
Process: JLinkExe
printf Test: %c,         'S' : S.

剩下问题:

启动JLinkRTT Logger 失败问题

标签:SWI,AP,SEGGER,OB,RTT,Client,Link,串口,###
来源: https://www.cnblogs.com/CXianRen/p/12198943.html