【项目实例】通过Jlink读取芯片ID

article/2025/9/16 8:57:55

目录:

  • 1. 项目背景
  • 2. 环境
  • 3. Jlink Comander使用
    • 3.1 建立连接
    • 3.2 查看帮助
  • 4. 通过Jlink Comander读取芯片ID
  • 5. 通过BAT脚本读取
    • 5.1 jlink文件
    • 5.2 bat 文件
    • 5.3 结果文件 chip_id.txt
    • 5.4 运行界面
  • 6. 写在最后

1. 项目背景

公司有一款产品需要在生产时通过读取它的芯片ID来生成一个二维码,用于后续问题追踪。

2. 环境

  • Windows
  • Jlink.exe
  • Jlink连接器
  • 开发板 AMA3B2KK-KBR

接下来我们会通过两种方式读取芯片ID,使用Jlink Comander工具和通过BAT脚本读取。

3. Jlink Comander使用

Jlink Comander是jlink的命令行工具,可以直接在里面输入命令。
打开Jlink Comander的第一个界面是这样的:
在这里插入图片描述
打开会去自动识别Jlink,如果识别成功的话,可以显示出它的序列号,如上图的S/N: 59602747。

根据提示,输入“connect”可建立连接,输入“?”查看帮助。

3.1 建立连接

输入connect,识别到了芯片的类型"AMA3B2KK-KBR"。接着选择连接方式 J S T,最后选择通讯速度。
在这里插入图片描述

3.2 查看帮助

输入“?”,可以看到支持哪些命令。

J-Link>?Available commands are:
----------------------
f          Firmware info
h          halt
IsHalted   Returns the current CPU state (halted / running)
WaitHalt   Waits until the CPU is halted or the given timeout is exceeded.Syntax: WaitHalt <TimeoutMs>  Default timeout is 1000 ms
g          go
Sleep      Waits the given time (in milliseconds). Syntax: Sleep <delay>
s          Single step the target chipSyntax: s [<NumSteps (dec)>]
st         Show hardware status
hwinfo     Show hardware info
mem        Read memory. Syntax: mem  [<Zone>:]<Addr>, <NumBytes> (hex)
mem8       Read  8-bit items. Syntax: mem8  [<Zone>:]<Addr>, <NumBytes> (hex)
mem16      Read 16-bit items. Syntax: mem16 [<Zone>:]<Addr>, <NumItems> (hex)
mem32      Read 32-bit items. Syntax: mem32 [<Zone>:]<Addr>, <NumItems> (hex)
w1         Write  8-bit items. Syntax: w1 [<Zone>:]<Addr>, <Data> (hex)
w2         Write 16-bit items. Syntax: w2 [<Zone>:]<Addr>, <Data> (hex)
w4         Write 32-bit items. Syntax: w4 [<Zone>:]<Addr>, <Data> (hex)
erase      Erase internal flash of selected device. Syntax: Erase
wm         Write test words. Syntax: wm <NumWords>
is         Identify length of scan chain select register
ms         Measure length of scan chain. Syntax: ms <Scan chain>
mr         Measure RTCK react time. Syntax: mr
q          Quit
qc         Close JLink connection and quit
eoe        Exit on errorSyntax: eoe <1/0>
r          Reset target         (RESET)
rx         Reset target         (RESET). Syntax: rx <DelayAfterReset>
RSetType   Set the current reset type. Syntax: RSetType <type>
Regs       Display contents of registers
wreg       Write register.   Syntax: wreg <RegName>, <Value>
moe        Shows mode-of-entry, meaning: Reason why CPU is halted
SetBP      Set breakpoint.   Syntax: SetBP <addr> [A/T] [S/H]
SetWP      Set Watchpoint. Syntax: <Addr> [R/W] [<Data> [<D-Mask>] [A-Mask]]
ClrBP      Clear breakpoint. Syntax: ClrBP  <BP_Handle>
ClrWP      Clear watchpoint. Syntax: ClrWP  <WP_Handle>
VCatch     Write vector catch. Syntax: VCatch <Value>
loadfile   Load data file into target memory.Syntax: loadfile <filename>, [<addr>]Supported extensions: *.bin, *.mot, *.hex, *.srec<addr> is needed for bin files only.
loadbin    Load *.bin file into target memory.Syntax: loadbin <filename>, <addr>
savebin    Saves target memory into binary file.Syntax: savebin <filename>, <addr>, <NumBytes>
verifybin  Verfies if the specified binary is already in the target memory at the specified address.Syntax: verifybin <filename>, <addr>
SetPC      Set the PC to specified value. Syntax: SetPC <Addr>
le         Change to little endian mode
be         Change to big endian mode
log        Enables log to file.  Syntax: log <filename>
unlock     Unlocks a device. Syntax: unlock <DeviceName>Type unlock without <DeviceName> to get a listof supported device names.nRESET has to be connected
term       Test command to visualize printf output from the target device,using DCC (SEGGER DCC handler running on target)
ReadAP     Reads a CoreSight AP register.Note: First read returns the data of the previous read.An additional read of DP reg 3 is necessary to get the data.
ReadDP     Reads a CoreSight DP register.Note: For SWD data is returned immediately.For JTAG the data of the previous read is returned.An additional read of DP reg 3 is necessary to get the data.
WriteAP    Writes a CoreSight AP register.
WriteDP    Writes a CoreSight DP register.
SWDSelect  Selects SWD as interface and outputsthe JTAG -> SWD switching sequence.
SWDReadAP  Reads a CoreSight AP register via SWD.Note: First read returns the data of the previous read.An additional read of DP reg 3 is necessary to get the data.
SWDReadDP  Reads a CoreSight DP register via SWD.Note: Correct data is returned immediately.
SWDWriteAP Writes a CoreSight AP register via SWD.
SWDWriteDP Writes a CoreSight DP register via SWD.
Device     Selects a specific device J-Link shall connect toand performs a reconnect.In most cases explicit selection of the device is not necessary.Selecting a device enables the user to make use of the J-Linkflash programming functionality as well as using unlimitedbreakpoints in flash memory.For some devices explicit device selection is mandatory in orderto allow the DLL to perform special handling needed by the device.
ExpDevList Exports the device names from the DLL internaldevice list to a text fileSyntax: ExpDevList <Filename>
ExpDevListXML Exports the device names from the DLL internaldevice list to a text file in XML formatSyntax: ExpDevListXML <Filename>
PowerTrace Perform power trace (not supported by all models)
Syntax: PowerTrace <LogFile> [<ChannelMask> <RefCountSel>]
<LogFile>: File to store power trace data to
<ChannelMask>: 32-bit mask to specify what channels shall be enabled
<SampleFreq>: Sampling frequency in Hz (0 == max)
<RefCountSel>:       0: No reference count1: Number of bytes transmitted on SWO
---- CP15 ------------
rce        Read CP15.  Syntax: rce <Op1>, <CRn>, <CRm>, <Op2>
wce        Write CP15. Syntax: wce <Op1>, <CRn>, <CRm>, <Op2>, <Data>
---- ICE -------------
Ice        Show state of the embedded ice macrocell (ICE breaker)
ri         Read Ice reg.  Syntax: ri <RegIndex>(hex)
wi         Write Ice reg. Syntax: wi <RegIndex>, <Data>(hex)
---- TRACE -----------
TClear     TRACE - Clear buffer
TSetSize   TRACE - Set Size of trace buffer
TSetFormat TRACE - SetFormat
TSR        TRACE - Show Regions (and analyze trace buffer)
TStart     TRACE - Start
TStop      TRACE - Stop
---- SWO -------------
SWOSpeed   SWO - Show supported speeds
SWOStart   SWO - Start
SWOStop    SWO - Stop
SWOStat    SWO - Display SWO status
SWORead    SWO - Read and display SWO data
SWOShow    SWO - Read and analyze SWO data
SWOFlush   SWO - Flush data
SWOView    SWO - View terminal data
---- PERIODIC --------
PERConf    PERIODIC - Configure
PERStart   PERIODIC - Start
PERStop    PERIODIC - Stop
PERStat    PERIODIC - Display status
PERRead    PERIODIC - Read and display data
PERShow    PERIODIC - Read and analyze data
---- File I/O --------
fwrite     Write file to emulator
fread      Read file from emulator
fshow      Read and display file from emulator
fdelete    Delete file on emulator
fsize      Display size of file on emulator
flist      List directory on emulator
SecureArea Creates/Removes secure area on probe
---- Test ------------
TestHaltGo   Run go/halt 1000 times
TestStep     Run step 1000 times
TestCSpeed   Measure CPU speed.Parameters: [<RAMAddr>]
TestWSpeed   Measure download speed into target memory.Parameters:  [<Addr> [<Size>]]
TestRSpeed   Measure upload speed from target memory.Parameters: [<Addr> [<Size>] [<NumBlocks>]]
TestNWSpeed  Measure network download speed.Parameters: [<NumBytes> [<NumReps>]]
TestNRSpeed  Measure network upload speed.Parameters: [<NumBytes> [<NumReps>]]
---- JTAG ------------
JTAGConf   Set number of IR/DR bits before ARM device.Syntax: Config <IRpre>, <DRpre>
speed      Set target interface speed. Syntax: speed <freq>|auto|adaptive, e.g. speed 2000, speed a
i          Read JTAG Id (Host CPU)
wjc        Write JTAG command (IR). Syntax: wjc <Data>(hex)
wjd        Write JTAG data (DR). Syntax: wjd <Data64>(hex), <NumBits>(dec)
RTAP       Reset TAP Controller using state machine (111110)
wjraw      Write Raw JTAG data. Syntax: wjraw <NumBits(dec)>, <tms>, <tdi>
rt         Reset TAP Controller (nTRST)
---- JTAG-Hardware ---
c00        Create clock with TDI = TMS = 0
c          Clock
tck0       Clear TCK
tck1       Set   TCK
0          Clear TDI
1          Set   TDI
t0         Clear TMS
t1         Set   TMS
trst0      Clear TRST
trst1      Set   TRST
r0         Clear RESET
r1         Set   RESET
---- Connection ------
usb        Connect to J-Link via USB.  Syntax: usb <port>, where port is 0..3
ip         Connect to J-Link ARM Pro or J-Link TCP/IP Server via TCP/IP.Syntax: ip <ip_addr>
---- Configuration ---
si         Select target interface. Syntax: si <Interface>,where <Interface> can be any supported target interface (e.g SWD, JTAG, ICSP, FINE, ...
power      Switch power supply for target. Syntax: power <State> [perm],where State is either On or Off. Example: power on perm
wconf      Write configuration byte. Syntax: wconf <offset>, <data>
rconf      Read configuration bytes. Syntax: rconf
license    Shows a list of all available license commands
ipaddr     Show/Assign IP address and subnetmask of/to the connected J-Link.
gwaddr     Show/Assign network gateway address of/to the connected J-Link.
dnsaddr    Show/Assign network DNS server address of/to the connected J-Link.
conf       Show configuration of the connected J-Link.
calibrate  Calibrate the target current measurement.
selemu     Select a emulator to communicate with,from a list of all emulators which are connected to the hostThe interfaces to search on, can be specifiedSyntax: selemu [<Interface0> <Interface1> ...]
ShowEmuList Shows a list of all emulators which are connected to the host.The interfaces to search on, can be specified.Syntax: ShowEmuList [<Interface0> <Interface1> ...]
VCOM        enable/disable VCOM. Takes effect after power cycle of the J-LinkSyntax: VCOM <enable|disable>
VTREF       Sets a fixed value for VTref on J-Link.Syntax: VTREF <ValuemV>
----------------------

4. 通过Jlink Comander读取芯片ID

从帮助里面可以看出,mem 是读取内存的命令。AMA3B2KK-KBR的芯片ID的寄存器地址是0x40020004。
在这里插入图片描述
以上命令成功读取到的芯片ID,其中0x40020004代表起始地址,8代表读取的长度,单位是字节。

5. 通过BAT脚本读取

Jlink命令需要放在一个*.jlink文件里面,所以我们在实践中是在一个批处理文件里面去调用它。读取到的芯片ID存储到chip_id.txt中。
在这里插入图片描述
话不多说,直接上代码。

5.1 jlink文件

si SWD
Device AMA3B2KK-KBR
speed 4000mem 0x40020004 8q

5.2 bat 文件

@echo off
SET ids=59602747:LOOP
pause
echo ==== 读取CHIP ID ====C:\Keil_v5\ARM\Segger\JLink.exe usb %ids% Read_chipid.jlink > temp.txtfindstr "40020004" temp.txt > chip_id.txt
type chip_id.txt
::equ ==   neq !=
::0 ok else error
if %errorlevel% neq 0 (
color 04
echo 读取失败!
)::del chip_id.txt
del temp.txt
ping 127.0.0.1 -n 3 >nul
clsgoto LOOP

5.3 结果文件 chip_id.txt

40020004 = 02 61 FA 33 29 F3 D5 09 

5.4 运行界面

在这里插入图片描述

6. 写在最后

Jlink的功能很强大,大家可多试试帮助里面的命令。本文通过读取ID来介绍,希望能起到以小见大的作用。

如对以上内容有疑问请在评论区留言,我们会尽快回复。


http://chatgpt.dhexx.cn/article/m4EVIdne.shtml

相关文章

Jlink使用技巧之烧写SPI Flash存储芯片

文章目录 前言准备硬件连接1.打开2.连接SPI Flash芯片3.打开程序文件4.下载5.程序文件的读取6.程序文件的保存7.命令行工具的使用支持的芯片列表速度说明参考资料&#xff1a;JLink软件的下载 前言 大多数玩单片机的人都知道Jlink可以烧写Hex文件&#xff0c;作为ARM仿真调试器…

JTAG 、 SWD 和 J-Link、ST-Link

JTAG和SWD的区别与联系JTAG接口SWD接口JTAG和SWD的区别与联系J-Link和ST-LinkJ-LINK仿真器STLINK仿真器JLINK和STLINK的比较与选择 JTAG和SWD的区别与联系 JTAG和SWD是两种常用的用于调试和编程ARM微控制器的接口&#xff0c;它们都可以通过调试器&#xff08;如ST-LINK或J-Li…

Jlink总结记录

一&#xff0c;引脚图 Jlink引脚定义 1、SWD模式第15脚可接可不接&#xff08;有问题再接&#xff09; 2、SWD模式第1脚VCC由目标板提供参考电压&#xff0c;若目标板MCU电压与SWD第2脚电压相同&#xff0c;则可以将1脚与2脚短接&#xff0c;实现3线式SWD 二&#xff0c;注意…

JLINK识别不到芯片

文章转载&#xff1a;KEIL里面JLINK V9无法识别芯片&#xff0c;但是J-FLASH可以烧录_Jun626的博客-CSDN博客_jlink不识别芯片 今天发生一件事情&#xff0c;JLINK突然之间识别不到芯片。 我也算是一个JLINK老客户了&#xff0c;折腾了半天才搞出来&#xff0c;所以写个帖子记…

Jlink 接口定义

接口定义 引脚定义

国民技术MCU开发之JLink添加芯片

JLink添加国民技术芯片型号 JLink 在 V770d 版本上不再沿用之前的添加新设备的方式支持新设备下载&#xff0c;而是使用了一种新的方式。 去官方发布的网盘获取如下文件夹 V770d版本以前 旧添加芯片方法 下载到本地如下图示例&#xff0c;可以参照官方提供的文档 参照文…

redis-redis官网下载步骤(包含windows版)

1.百度搜索redis,可以看到Redis官网&#xff0c;如下图所示&#xff1a; 2.点击进入Redis官网&#xff0c;点击右上角Download&#xff0c;如下图所示&#xff1a; 3.点击 Stable&#xff08;稳定&#xff09;下的Download4.0.6&#xff0c;如下图所示&#xff1a; 4.点击会弹出…

redis下载安装教程

前言 今天做一个redis下载安装教程文章分享给大家。 操作 1、下载网址&#xff1a;https://github.com/MicrosoftArchive/redis/releases 2、我们选择安装版的 3、双击安装 4、下一步 5、选择一个安装路径&#xff0c;并打上对勾&#xff0c;对勾可以将redis添加到环境变量…

Redis—安装与配置

1. Redis 1.1. Redis的安装 ​ 大多数企业都是基于Linux服务器来部署项目&#xff0c;而且Redis官方也没有提供Windows版本的安装包。本教程会在Linux下部署redis。 ​ Linux版本为CentOS 7。 ​ Redis的官方网站地址&#xff1a;https://redis.io/ 1.1.1. Windows安装 ​…

redis下载与安装(Linux环境下)

用的是阿里云的深度os Linux系统 一&#xff0c;下载 键入命令&#xff1a; wget http://download.redis.io/releases/redis-6.2.1.tar.gz 检查时候有gcc环境 gcc --version 若有gcc环境会有类似于下图的提示 没有则执行&#xff1a; yum install gcc 下载完毕之后&…

Redis下载安装图文教程(Windows版_超详细)

一、下载 1、Redis官网 Download | Redis 注意&#xff1a;官网没有提供Windows版本&#xff0c;只有Linux版本。 2、github下载地址 Releases microsoftarchive/redis GitHub 可选择&#xff1a;下载msi包或zip压缩包 这里我选择的是zip压缩包&#xff0c;直接通过…

redis的下载和安装详解(linux)

一、下载redis安装包 进入redis官网查看当前稳定版本&#xff1a; https://redis.io/download/发现此时的稳定版本是6.2.4&#xff0c; 此时可以去这个网站下载6.2.4稳定版本的tar包。 暂时不考虑不在windows上使用redis&#xff0c;那样将无法发挥redis的性能 二、上传ta…

Linux/Windows Redis的下载与安装

Redis简介 参考视频教程: https://www.bilibili.com/video/BV13a411q753?p143 Redis下载与安装 Windows版 下载地址: https://github.com/microsoftarchive/redis/releases Linux版下载地址: https://download.redis.io/releases/ 1. Window版本 1.1 redis下载 官网下载…

windows下载redis、windows安装redis、windows启动redis

一、下载并解压 下载网址&#xff1a;https://github.com/tporadowski/redis/releases 下载后解压并重命名文件夹为redis 二、打开redis文件夹 找到redis.windows.conf配置文件&#xff0c;作如下修改 protected-mode no // 将yes改为no 部分配置信息说明 bind 127.0.…

Mac上redis下载安装与配置详细版

在Mac上安装redis 1.打开官网直接下载&#xff0c;也可以尝试底下旧版本&#xff0c;但是6.0以下版本容易出错&#xff1a;https://redis.io/download 2.打开终端进入到下载后到目录下&#xff1a; cd /Users/jiale/Downloads/ 使用tar命令进行解压缩&#xff1a; tar -zxvf …

Linux服务器下载Redis

一、下载redis 方法一&#xff1a; 用redis的下载链接下载redis压缩包&#xff0c;该种方法只能下载最新版本 1、登录redis官网 Redis官网链接&#xff1a; https://redis.io/ 2、跳转redis下载页面 3、找到redis的下载链接 4、用wget下载redis压缩包 wget https://gith…

Redis的下载与安装——Windows版

资源链接Redis下载验证Redis是否可用将Redis注册成系统服务 Redis服务常用指令 资源链接 Redis官网&#xff1a; Redis Redis官方文档&#xff1a; Redis Document Redis国内文档&#xff1a; Redis菜鸟教程 Windows版本下载地址&#xff1a; Redis For Windows 码云…

Redis - Windows下载与安装

1.获取Redis在windows下的安装包 Windows版下载地址&#xff1a;https://github.com/microsoftarchive/redis/releases 选择Redis-x64-*.zip 2.解压zip文件与配置 2.1 选取目录 选取一个目录作为解压目录&#xff0c;这个目录就是你Redis程序所在位置&#xff0c;尽量找一…

Redis下载和安装

1.windows版本 [注意&#xff1a;Redis官方没有windows&#xff0c;只有Linux系统&#xff0c;这个是别人封装对应的] 下载地址: Releases microsoftarchive/redis GitHub 安装版本和解压版本 最好下载安装版本&#xff0c;都给你自动配置好。 安装完成后&#xff1a; 打…

Redis下载安装教程 (windows)

一、安装和配置Redis 前言:windows没有32位的Redis&#xff0c;所以32位机器的朋友考虑换一下机器。 1、windows环境下的redis需要去github上获取: https://github.com/MicrosoftArchive/redis/releases 注&#xff1a; 如果访问不进去官方&#xff0c;就需要爬墙进入 2、下…