知方号

知方号

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

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

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

1. 项目背景

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

2. 环境 WindowsJlink.exeJlink连接器开发板 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 infoh haltIsHalted Returns the current CPU state (halted / running)WaitHalt Waits until the CPU is halted or the given timeout is exceeded. Syntax: WaitHalt Default timeout is 1000 msg goSleep Waits the given time (in milliseconds). Syntax: Sleep s Single step the target chip Syntax: s []st Show hardware statushwinfo Show hardware infomem Read memory. Syntax: mem [:], (hex)mem8 Read 8-bit items. Syntax: mem8 [:], (hex)mem16 Read 16-bit items. Syntax: mem16 [:], (hex)mem32 Read 32-bit items. Syntax: mem32 [:], (hex)w1 Write 8-bit items. Syntax: w1 [:], (hex)w2 Write 16-bit items. Syntax: w2 [:], (hex)w4 Write 32-bit items. Syntax: w4 [:], (hex)erase Erase internal flash of selected device. Syntax: Erasewm Write test words. Syntax: wm is Identify length of scan chain select registerms Measure length of scan chain. Syntax: ms mr Measure RTCK react time. Syntax: mrq Quitqc Close JLink connection and quiteoe Exit on error Syntax: eoe r Reset target (RESET)rx Reset target (RESET). Syntax: rx RSetType Set the current reset type. Syntax: RSetType Regs Display contents of registerswreg Write register. Syntax: wreg , moe Shows mode-of-entry, meaning: Reason why CPU is haltedSetBP Set breakpoint. Syntax: SetBP [A/T] [S/H]SetWP Set Watchpoint. Syntax: [R/W] [ [] [A-Mask]]ClrBP Clear breakpoint. Syntax: ClrBP ClrWP Clear watchpoint. Syntax: ClrWP VCatch Write vector catch. Syntax: VCatch loadfile Load data file into target memory. Syntax: loadfile , [] Supported extensions: *.bin, *.mot, *.hex, *.srec is needed for bin files only.loadbin Load *.bin file into target memory. Syntax: loadbin , savebin Saves target memory into binary file. Syntax: savebin , , verifybin Verfies if the specified binary is already in the target memory at the specified address. Syntax: verifybin , SetPC Set the PC to specified value. Syntax: SetPC le Change to little endian modebe Change to big endian modelog Enables log to file. Syntax: log unlock Unlocks a device. Syntax: unlock Type unlock without to get a list of supported device names. nRESET has to be connectedterm 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 outputs the 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 to and 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-Link flash programming functionality as well as using unlimited breakpoints in flash memory. For some devices explicit device selection is mandatory in order to allow the DLL to perform special handling needed by the device.ExpDevList Exports the device names from the DLL internal device list to a text file Syntax: ExpDevList ExpDevListXML Exports the device names from the DLL internal device list to a text file in XML format Syntax: ExpDevListXML PowerTrace Perform power trace (not supported by all models)Syntax: PowerTrace [ ]: File to store power trace data to: 32-bit mask to specify what channels shall be enabled: Sampling frequency in Hz (0 == max): 0: No reference count 1: Number of bytes transmitted on SWO---- CP15 ------------rce Read CP15. Syntax: rce , , , wce Write CP15. Syntax: wce , , , , ---- ICE -------------Ice Show state of the embedded ice macrocell (ICE breaker)ri Read Ice reg. Syntax: ri (hex)wi Write Ice reg. Syntax: wi , (hex)---- TRACE -----------TClear TRACE - Clear bufferTSetSize TRACE - Set Size of trace bufferTSetFormat TRACE - SetFormatTSR TRACE - Show Regions (and analyze trace buffer)TStart TRACE - StartTStop TRACE - Stop---- SWO -------------SWOSpeed SWO - Show supported speedsSWOStart SWO - StartSWOStop SWO - StopSWOStat SWO - Display SWO statusSWORead SWO - Read and display SWO dataSWOShow SWO - Read and analyze SWO dataSWOFlush SWO - Flush dataSWOView SWO - View terminal data---- PERIODIC --------PERConf PERIODIC - ConfigurePERStart PERIODIC - StartPERStop PERIODIC - StopPERStat PERIODIC - Display statusPERRead PERIODIC - Read and display dataPERShow PERIODIC - Read and analyze data---- File I/O --------fwrite Write file to emulatorfread Read file from emulatorfshow Read and display file from emulatorfdelete Delete file on emulatorfsize Display size of file on emulatorflist List directory on emulatorSecureArea Creates/Removes secure area on probe---- Test ------------TestHaltGo Run go/halt 1000 timesTestStep Run step 1000 timesTestCSpeed Measure CPU speed. Parameters: []TestWSpeed Measure download speed into target memory. Parameters: [ []]TestRSpeed Measure upload speed from target memory. Parameters: [ [] []]TestNWSpeed Measure network download speed. Parameters: [ []]TestNRSpeed Measure network upload speed. Parameters: [ []]---- JTAG ------------JTAGConf Set number of IR/DR bits before ARM device. Syntax: Config , speed Set target interface speed. Syntax: speed |auto|adaptive, e.g. speed 2000, speed ai Read JTAG Id (Host CPU)wjc Write JTAG command (IR). Syntax: wjc (hex)wjd Write JTAG data (DR). Syntax: wjd (hex), (dec)RTAP Reset TAP Controller using state machine (111110)wjraw Write Raw JTAG data. Syntax: wjraw , , rt Reset TAP Controller (nTRST)---- JTAG-Hardware ---c00 Create clock with TDI = TMS = 0c Clocktck0 Clear TCKtck1 Set TCK0 Clear TDI1 Set TDIt0 Clear TMSt1 Set TMStrst0 Clear TRSTtrst1 Set TRSTr0 Clear RESETr1 Set RESET---- Connection ------usb Connect to J-Link via USB. Syntax: usb , where port is 0..3ip Connect to J-Link ARM Pro or J-Link TCP/IP Server via TCP/IP. Syntax: ip ---- Configuration ---si Select target interface. Syntax: si , where can be any supported target interface (e.g SWD, JTAG, ICSP, FINE, ...power Switch power supply for target. Syntax: power [perm], where State is either On or Off. Example: power on permwconf Write configuration byte. Syntax: wconf , rconf Read configuration bytes. Syntax: rconflicense Shows a list of all available license commandsipaddr 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 host The interfaces to search on, can be specified Syntax: selemu [ ...]ShowEmuList Shows a list of all emulators which are connected to the host. The interfaces to search on, can be specified. Syntax: ShowEmuList [ ...]VCOM enable/disable VCOM. Takes effect after power cycle of the J-Link Syntax: VCOM VTREF Sets a fixed value for VTref on J-Link. Syntax: VTREF ---------------------- 4. 通过Jlink Comander读取芯片ID

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

5. 通过BAT脚本读取

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

5.1 jlink文件 si SWDDevice AMA3B2KK-KBRspeed 4000mem 0x40020004 8q 5.2 bat 文件 @echo offSET ids=59602747:LOOPpauseecho ==== 读取CHIP ID ====C:Keil_v5ARMSeggerJLink.exe usb %ids% Read_chipid.jlink > temp.txtfindstr "40020004" temp.txt > chip_id.txttype chip_id.txt::equ == neq !=::0 ok else errorif %errorlevel% neq 0 (color 04echo 读取失败!)::del chip_id.txtdel temp.txtping 127.0.0.1 -n 3 >nulclsgoto LOOP 5.3 结果文件 chip_id.txt 40020004 = 02 61 FA 33 29 F3 D5 09 5.4 运行界面

6. 写在最后

Jlink的功能很强大,大家可多试试帮助里面的命令。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。