MuraxSoC 是一个轻量级的基于RISC-V的SoC,基于VexRiscv(SpinalHDL实现的RISC-V ),支持RV32I,中断,JTAG调试等,详细规格如下
- VexRiscv RV32I[M]
- JTAG debugger (Eclipse/GDB/openocd ready)
- 8 kB of on-chip ram
- Interrupt support
- APB bus for peripherals
- 32 GPIO pin
- one 16 bits prescaler, two 16 bits timers
- one UART with tx/rx fifo
准备工作
- iCESugar 开发板,并正常连接至Linux中
- icestorm工具链
- risc-v gcc工具链
- openocd-riscv
MuraxSoC bitstream 构建
在iCESugar目录下输入make,make会调用sbt工具对SpinalHDL源码进行编译
ubuntu@ubuntu:~$cd oss/icesugar/src/advanced/VexRiscv/scripts/Murax/iCESugar
ubuntu@ubuntu:~/oss/icesugar/src/advanced/VexRiscv/scripts/Murax/iCESugar$make
编译完成之后,会在顶层目录生成MuraxSoC的verilog源码Murax.v
生成最终的bitstream文件
ubuntu@ubuntu:~/oss/icesugar/src/advanced/VexRiscv/scripts/Murax/iCESugar$make bin/toplevel.bin
会调用icestorm工具链对Murax.v和顶层toplevel.v进行综合布线,最终生成bin/toplevel.bin bitstream文件,生成的bitstream文件可直接使用icesprog命令行工具烧录,亦可拖拽至iCELink虚拟U盘中烧录。
$icesprog bin/toplevel.bin
同时打开iCELink提供的虚拟串口,波特率115200,MuraxSoC启动之后,会向串口输出打印,如图所示
MuraxSoC默认装载的固件是VexRiscv/src/main/ressource/hex/muraxDemo.hex,此镜像会被自动装载至内部的8K RAM中运行,亦可修改sbt命令行参数,综合出支持xip的bitstream,支持从spi flash中取指令运行,可运行更复杂的程序。
MuraxSoC固件编译
可自行编译固件,编译固件之前需要先准备要risc-v gcc工具链,推荐直接下载已预编译好的工具链,
$wget https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-20171231-x86_64-linux-centos6.tar.gz
$tar -zxvf riscv64-unknown-elf-gcc-20171231-x86_64-linux-centos6.tar.gz
$sudo mv riscv64-unknown-elf-gcc-20171231-x86_64-linux-centos6 /opt/riscv
$echo "export PATH=${PATH}:/opt/riscv/bin" >>~/.bashrc
$source ~/.bashrc
固件编译方法如下:
$git clone https://github.com/SpinalHDL/VexRiscvSocSoftware
$cd VexRiscvSocSoftware/projects/murax/demo
$make
即可在build目录下生成目标demo.hex文件,可将hex文件拷贝至vexriscv目录替换掉muraxDemo.hex,重新综合生成bitstream。
MuraxSoC 调试
MuraxSoC启动之后,接好调试信号
- TCK - P20
- TMS - P18
- TDI - P21
- TDO - P19
即可使用openocd配合板载的iCELink对其进行调试,首先需要编译openocd-riscv 调试工具
$git clone https://github.com/SpinalHDL/openocd_riscv.git
$cd openocd_riscv
$./bootstrap
$./configure --enable-cmsis-dap
$make
编译完成之后,新建一个配置文件vexriscv_cmsis_dap.cfg\
interface cmsis-dap
transport select jtag
set _ENDIAN little
set _TAP_TYPE 1234
if { [info exists CPUTAPID] } {
set _CPUTAPID $CPUTAPID
} else {
# set useful default
set _CPUTAPID 0x10001fff
}
adapter_khz 4000
adapter_nsrst_delay 260
jtag_ntrst_delay 250
set _CHIPNAME fpga_spinal
jtag newtap $_CHIPNAME bridge -expected-id $_CPUTAPID -irlen 4 -ircapture 0x1 -irmask 0xF
target create $_CHIPNAME.cpu0 vexriscv -endian $_ENDIAN -chain-position $_CHIPNAME.bridge -coreid 0 -dbgbase 0xF00F0000
vexriscv readWaitCycles 12
vexriscv cpuConfigFile $VEXRISCV_YAML
poll_period 50
init
#echo "Halting processor"
soft_reset_halt
并调用openocd命令attach到目标上
/home/ubuntu/oss/openocd_riscv$./src/openocd -c "set VEXRISCV_YAML /home/ubuntu/oss/icesugar/src/advanced/VexRiscv/cpu0.yaml" -f tcl/target/vexriscv_cmsis_dap.cfg
Open On-Chip Debugger 0.10.0+dev-01223-g92c05420 (2020-04-13-04:44)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
/home/ubuntu/oss/icesugar/src/advanced/VexRiscv/cpu0.yaml
adapter speed: 4000 kHz
adapter_nsrst_delay: 260
jtag_ntrst_delay: 250
Info : set servers polling period to 50ms
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 0254
Info : CMSIS-DAP: Serial# = 07000001066aff323731544157253316a5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (JTAG)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 4000 kHz
Info : cmsis-dap JTAG TLR_RESET
Info : cmsis-dap JTAG TLR_RESET
Info : JTAG tap: fpga_spinal.bridge tap/device found: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)
Info : Listening on port 3333 for gdb connections
requesting target halt and executing a soft reset
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
另外开一个终端窗口,使用gdb连接3333端口,即可进行寄存器查看,单步调试
/opt/riscv/bin/riscv64-unknown-elf-gdb
GNU gdb (GDB) 8.0.50.20170724-git
Copyright (C) 2017 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=riscv64-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
Remote debugging using localhost:3333
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x80000000 in ?? ()
(gdb) monitor reset halt
cmsis-dap JTAG TLR_RESET
cmsis-dap JTAG TLR_RESET
cmsis-dap JTAG TLR_RESET
JTAG tap: fpga_spinal.bridge tap/device found: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)
(gdb) i r
x1 0x80001194 -2147479148
x2 0x80001ff0 -2147475472
x3 0x800025e8 -2147473944
x4 0x00000000 0
x5 0x00000000 0
x6 0x00000000 0
x7 0x00000000 0
x8 0x80001ff0 -2147475472
x9 0x00000000 0
x10 0x000000a1 161
x11 0x00000001 1
x12 0x00000096 150
x13 0x00000002 2
x14 0x0000000b 11
x15 0xf0000000 -268435456
x16 0x00000000 0
x17 0x00000000 0
x18 0x00000000 0
x19 0x00000000 0
x20 0x00000000 0
x21 0x00000000 0
x22 0x00000000 0
x23 0x00000000 0
x24 0x00000000 0
x25 0x00000000 0
x26 0x00000000 0
x27 0x00000000 0
x28 0x00000000 0
x29 0x00000000 0
x30 0x00000000 0
x31 0x00000000 0
pc 0x800000bc -2147483460
(gdb) si
0x800000b0 in ?? ()
接线说明
参考资料