scr1源码地址:https://github.com/syntacore/scr1
scr1_SDK地址:https://github.com/syntacore/scr1-sdk
syntacore/openocd源码地址:https://github.com/syntacore/openocd
riscv/riscv-openocd源码地址:https://github.com/riscv/riscv-openocd
openocd官方地址:http://openocd.org/
riscv/riscv-gnu-toolchain源地址:https://github.com/riscv/riscv-gnu-toolchain
一、搭建openocd+jlink
下载linux下的jlink的驱动并安装
jlink驱动
1.SEGGER官网下载最新jlink驱动,网址 https://www.segger.com/downloads/jlink
2.下载完成后,找到下载好的文件,双击JLink_Linux_V614b_i386.deb,会自动在ubuntu software center安装,比压缩文件安装方便多啦。
3.找到路径 /opt/SEGGER/JLink/ ;终端执行JLinkExe,能进入则成功。
下载 syntacore/openocd源码
终端输入git clone --recursive https://github.com/syntacore/openocd
git克隆完成后,切到openocd的目录下,
终端输入sudo ./bootstrap
终端输入sudo ./configue
终端输入sudo make
终端输入sudo make install
运行完后就把openocd安装完毕了
更新最新关于scr1的openocd配置文件
下载https://github.com/syntacore/openocd/releases并解压。
然后将里面的./share/openocd/scripts/target文件夹下的5个.cfg文件
syntacore_riscv32_v2.cfg
syntacore_riscv.cfg
syntacore_riscv32_v1.cfg
syntacore_riscv32i.cfg
syntacore_riscv32i_2tap.cfg
拷贝到上面openocd的git目录下的./tcl/target/目录下
并将各个文件中的“adapter_khz 2000”更改为“adapter_khz 1000”,原因是jlink的接口速率太高会不稳定。
运行openocd进行下载和调试
插入jlink调试器到USB上.
终端输入lsusb,查看是否能够识别到jlink,下面为实际运行的终端打印信息
Bus 001 Device 005: ID 1366:0105 SEGGER
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
然后在openocd的git目录下打开终端输入
sudo ./src/openocd -s ./tcl -f ./tcl/interface/jlink.cfg -f ./tcl/target/syntacore_riscv.cfg
实际运行的终端打印信息
Open On-Chip Debugger 0.10.0+dev-01974-g3d33e053f-dirty (2020-01-03-12:17)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
sw_reset_halt
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
adapter speed: 1000 kHz
trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_deassert_srst
Info : auto-selecting first available session transport “jtag”. To override use 'transport select '.
riscv.cpu
Info : J-Link V9 compiled Sep 1 2016 18:29:50
Info : Hardware version: 9.60
Info : VTarget = 3.317 V
Info : clock speed 1000 kHz
Info : JTAG tap: riscv.cpu tap/device found: 0xdeb11001 (mfg: 0x000 (), part: 0xeb11, ver: 0xd)
Info : riscv.cpu: datacount=2 progbufsize=6
Info : riscv.cpu: Examined RISC-V core; found 1 harts
Info : riscv.cpu: hart 0: XLEN=32, misa=0x40001104
Info : Listening on port 3333 for gdb connections
Warn : Failed to receive data from device: LIBUSB_ERROR_TIMEOUT.
然后打开新的终端输入telnet localhost 4444
实际终端的打印信息
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
Open On-Chip Debugger
Failed to receive data from device: LIBUSB_ERROR_TIMEOUT.
reset halt //##注释:复位并暂停
JTAG tap: riscv.cpu tap/device found: 0xdeb11001 (mfg: 0x000 (), part: 0xeb11, ver: 0xd)
load_image /home/hjz/openocd_stlink_debug/dhry21-o3lto.bin 0xf0000000 bin //##注释:下载scr1案例文件到mcu中
14028 bytes written at address 0xf0000000
downloaded 14028 bytes in 6.477761s (2.115 KiB/s)
resume 0xf0000200 //##注释:指定重启地址,
此时串口会打印
Dhrystone Benchmark, Version 2.1 (Language: C)
Program compiled without ‘register’ attribute
Compiler flags: -O3 -funroll-loops -fpeel-loops -fgcse-sm -fgcse-las -flto
HZ 1000000, CPU MHz 25.000
Execution starts, 500 runs through Dhrystone
Execution ends
Final values of the variables used in the benchmark:
Int_Glob: 5
should be: 5
Bool_Glob: 1
should be: 1
Ch_1_Glob: A
should be: A
Ch_2_Glob: B
should be: B
Arr_1_Glob[8]: 7
should be: 7
Arr_2_Glob[8][7]: 510
should be: Number_Of_Runs + 10
Ptr_Glob->
Ptr_Comp: -268421380
should be: (implementation-dependent)
Discr: 0
should be: 0
Enum_Comp: 2
should be: 2
Int_Comp: 17
should be: 17
Str_Comp: DHRYSTONE PROGRAM, SOME STRING
should be: DHRYSTONE PROGRAM, SOME STRING
Next_Ptr_Glob->
Ptr_Comp: -268421380
should be: (implementation-dependent), same as above
Discr: 0
should be: 0
Enum_Comp: 1
should be: 1
Int_Comp: 18
should be: 18
Str_Comp: DHRYSTONE PROGRAM, SOME STRING
should be: DHRYSTONE PROGRAM, SOME STRING
Int_1_Loc: 5
should be: 5
Int_2_Loc: 13
should be: 13
Int_3_Loc: 7
should be: 7
Enum_Loc: 1
should be: 1
Str_1_Loc: DHRYSTONE PROGRAM, 1’ST STRING
should be: DHRYSTONE PROGRAM, 1’ST STRING
Str_2_Loc: DHRYSTONE PROGRAM, 2’ND STRING
should be: DHRYSTONE PROGRAM, 2’ND STRING
Time: begin= 830653057, end= 830803126, diff= 150069
Microseconds for one run through Dhrystone: 300.138
Dhrystones per Second: 3331
至此完成了环境搭建。
二、搭建openocd+gdb
riscv/riscv-gnu-toolchain源地址:https://github.com/riscv/riscv-gnu-toolchain
下载编译器,终端输入git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
然后根据里面的README.md来进行安装。
安装完毕后
运行gdb调试工具
在openocd的git目录下打开终端输入
sudo ./src/openocd -s ./tcl -f ./tcl/interface/jlink.cfg -f ./tcl/target/syntacore_riscv.cfg
打开新终端输入riscv32-unknown-elf-gdb
终端的打印信息
GNU gdb (GDB) 7.11.50.20160212-git
Copyright © 2016 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=x86_64-pc-linux-gnu --target=riscv32-unknown-elf”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type “help”.
Type “apropos word” to search for commands related to “word”.
(gdb) target remote localhost:3333 //##注释:连接到openocd的3333端口进行调试
Remote debugging using localhost:3333
warning: Target-supplied registers are not supported by the current architecture
0xf00003c4 in ?? ()
(gdb)
来源:CSDN
作者:柚树
链接:https://blog.csdn.net/h420255243/article/details/103859193