配置openocd与gdb调试环境时USB设备添加与访问

开发环境

wsl 连接USB设备

wsl连接usb设备

安装驱动

win11
ubuntu
  • usbipd
sudo apt install linux-tools-5.4.0-77-generic hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/5.4.0-77-generic/usbip 20
  • usb device
sudo apt-get install libusb-1.0-0-dev libudev-dev usbutils
  • usb device driver
sudo apt-get install libftdi-dev libftdi1

添加USB

powershell:

usbipd wsl list
usbipd wsl attach --busid <busid>

没有接入USB设备
没接入USB设备
接入USB设备并添加到wsl之后
接入USB设备并添加到WSL

linux:

lsusb

wsl中显示已经添加上该设备
wls显示

powershell:

usbipd wsl detach --busid <busid>

ubuntu中USB插拔设备访问权限

wsl中识别了usb驱动后,可以尝试打开openocd,可能会出现不能访问的问题(LIBUSB_ERROR_ACCESS)
LIBUSB_ERROR_ACCESS

  • 1 修改usb总线的访问权限
sudo chmod -R 777 /dev/bus/usb/

usb总线访问权限

  • 2 修改 USB 设备权限
    修改ttyUSB的设备所属组,并添加当前用户到该组,方便给予设备访问权限
sudo chown root:plugdev /dev/ttyUSB*
sudo usermod -aG plugdev hz

临时给与USB设备权限

sudo chmod 666 /dev/ttyUSB*

或者永久修改该USB设备权限
1)使用lsusb命令找出 USB 设备的 vendorID 和 productID
2)创建一个新的udev规则

sudo vim /etc/udev/rules.d/99-openocd.rules
 
#找出"idVendor"和"idProduct"来替换默认值。MODE="0666"表示USB设备的权限。
#将下面的规则写入文件99-openocd.rules并保存 
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", GROUP="plugdev", MODE="0666"

3)重启电脑或重新加载 udev 规则

sudo  services udev  --reload

4) 重新插入USB,并attach到wsl

openocd 文件注释

# 适配器频率设置
adapter_khz     1000

# 适配器类型设置(官方改成了adapter driver ‘name’命令,即:adapter driver ftdi)
interface ftdi
# 适配器的供应商ID和产品ID(最新命令:ftdi vid_pid 0x0403 0x6010)
ftdi_vid_pid 0x0403 0x6010
# 关闭适配器OSCAN1模式(最新命令:ftdi oscan1_mode off)
ftdi_oscan1_mode off

## Bind ftdi device using ftdi_serial
## the serial number could be checked using FT_Prog or dmesg
# ftdi_serial "FT5Q5L33"

## bindto 0.0.0.0 can be used to cover all available interfaces.
## Uncomment bindto line to enable remote machine debug
# 指定监听的IP地址,0.0.0.0表示覆盖所有可用接口
bindto 0.0.0.0

## If ftdi_device_desc not specified, the device description is ignored during device selection.
## So if you want to specify a dedicated FTDI device, you can select following device description:
## "Dual RS232-HS" is for HummingBird Debugger V1
## "USB <-> JTAG-DEBUGGER" is for HummingBird Debugger V2
## Uncomment one which match your device description
# ftdi_device_desc "Dual RS232-HS"
# ftdi_device_desc "USB <-> JTAG-DEBUGGER"

# 选择在此OpenOCD会话中使用jtag的传输。
transport select jtag

# 指定FTDI GPIO数据和方向寄存器的初始值分别为0x0008 0x001b
ftdi_layout_init 0x0008 0x001b 
# 创建nSRST信号,-oe指示output-enable输入到输出缓存的连接位置:0x0020, 
# -data表示不转换的数据掩码(管脚位掩码用于连接输出缓存的数据输入):0x0020
ftdi_layout_signal nSRST -oe 0x0020 -data 0x0020
# 创建TCK信号,数据掩码:0x0001
ftdi_layout_signal TCK -data 0x0001
# 创建TDI信号,数据掩码:0x0002
ftdi_layout_signal TDI -data 0x0002 
# 创建TDO信号,-input表示用fidi get_signal方法读取管脚位掩码0x0004
ftdi_layout_signal TDO -input 0x0004 
# 创建TMS信号,数据掩码:0x0008
ftdi_layout_signal TMS -data 0x0008  
# 创建JTAG_SEL信号,数据掩码:0x0100, 连接位置:0x0100 
ftdi_layout_signal JTAG_SEL -data 0x0100 -oe 0x0100 

# 设置芯片名称:riscv
set _CHIPNAME riscv                
# 添加riscv芯片主cpu的TAP到JTAG scan chain,指令寄存器的位长度为5 
jtag newtap $_CHIPNAME cpu -irlen 5

# 设置debug target名称riscv.cpu
set _TARGETNAME $_CHIPNAME.cpu
# 创建gdb调试目标riscv.cpu,类型riscv,TAP名称:riscv.cpu      
target create $_TARGETNAME riscv -chain-position $_TARGETNAME 
# 配置riscv.cpu:工作区基址:0x80000000,指定工作区大小10000字节,工作区备份:是
$_TARGETNAME configure -work-area-phys 0x80000000 -work-area-size 10000 -work-area-backup 1 

# 设置flash名称:riscv.flash
set _FLASHNAME $_CHIPNAME.flash     
# Please use Nuclei OpenOCD >= 2022.01 release version
# 配置flash bank,名称:riscv.flash,设备名称:nuspi(芯来科技的SPI控制器),flash芯片的基址:0x20000000,
# 芯片大小:0(自动检测),flash芯片宽:0(忽略),数据总线宽:0(忽略),target名:riscv.cpu
flash bank $_FLASHNAME nuspi 0x20000000 0 0 0 $_TARGETNAME  
# Set the ILM space also as flash, to make sure it can be add breakpoint with hardware trigger
#flash bank onboard_ilm nuspi 0x80000000 0 0 0 $_TARGETNAME

# Expose Nuclei self-defined CSRS
# See https://github.com/riscv/riscv-gnu-toolchain/issues/319#issuecomment-358397306
# Then user can view the csr register value in gdb using: info reg csr775 for CSR MTVT(0x307)
# 配置除了标准CSR之外还要公开哪些CSR。
riscv expose_csrs 416-496,770-800,835-850,1227-1231,1483-1486,1984-2032,2064-2070,2370-2380,2490-2500,4032-4040

# 该命令终止配置阶段并进入运行阶段。
init

# 如果当前上下文存在pulse_srst变量,设置信号nSRST为drive low,然后到高阻抗
if {[ info exists pulse_srst]} {
  ftdi_set_signal nSRST 0
  ftdi_set_signal nSRST z
}
# 向target发送中断请求,等待中断
halt
# We must turn on this because otherwise the IDE version debug cannot download the program into flash
# 关闭flash板0的保护块0到保护块last的flash块保护
flash protect 0 0 last off

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值