# verilog-serv **Repository Path**: yuan_hp/verilog-serv ## Basic Information - **Project Name**: verilog-serv - **Description**: bit by bit 的RISCV 软核serv的使用,提供wishbone选择器自动生成的脚本模块 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-05-22 - **Last Updated**: 2025-05-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: Verilog, mcu, RISC, riscv ## README 针对 icesugar 系列 # RSIC-V-GCC相关参数 例如: ```makefile riscv32-unknown-elf-gcc test.c -march=rv32i --entry=main -nostdlib -lgcc -o test.elf ``` * -march=rv32i,表示使用rv32i指令集架构进行编译。 * --entry=main,表示编译生成的程序的入口地址为main函数的开始地址。 * -nostdlib,表示不使用标准库,考虑在裸机上编译运行尽可能降低程序的编译出来的复杂度,所以不使用标准库。 * -lgcc,表示使用libgcc.a,以支持C语言中的浮点操作。 ## 指令、数据提取 对于编译生成的**elf文件**,其中包含指令、数据等多段内容,现在需要提取出其中的指令部分,用于写入裸机的指令内存。对此可以使用`riscv32-unknown-elf-objcopy`将**elf文件**中对应`段(section)`提取到对应文件中。 ```Bash ## test.inst.bin表示提取出的文件名,test.elf表示输入的文件名。 riscv32-unknown-elf-objcopy --dump-section .text=test.inst.bin test.elf ``` `--dump-section .text=test.inst.bin test.elf`,表示将`test.elf`文件中的`.text`段的内容提取到`test.inst.bin`中,现在只需将`test.inst.bin`的格式进行转换,即可写入FPGA的BRAM中。 程序的运行不止需要指令,还需要程序对应的数据,即**elf文件**中数据部分,由于程序需要的数据在**elf文件**中包含多段内容,所以现在采取一种简单的方式,即**将elf文件转换成二进制文件**,再讲该文件写入裸机的数据内存,作为该段程序所需要的数据 ```bash # test.data.bin表示提取出的文件名,test.elf表示输入的文件名。 riscv32-unknown-elf-objcopy -O binary test.elf test.data.bin ``` 现在只需将`test.data.bin`的格式进行转换,即可写入FPGA的BRAM中 ## wb_mux.py 该脚本用于将二进制文件转换为Verilog的ROM初始化文件,即wb_mux.v文件。 ```bash Administrator@PC-20230414RCQN /c/g/S/1/0/cbb_serv_sensor_hub (master)# ./rtl/wb_mux.py -h usage: wb_mux.py [-h] [-p PORTS] [-n NAME] [-o OUTPUT] Generates a Wishbone multiplexer with the specified number of ports optional arguments: -h, --help show this help message and exit -p PORTS, --ports PORTS number of ports -n NAME, --name NAME module name -o OUTPUT, --output OUTPUT output file name ``` ## 堆栈 堆栈设置为存储器空间的最大值(按32位计算) ```assembly .section .init .global main /* set stack pointer */ lui sp, %hi(1*8192/4) addi sp, sp, %lo(1*8192/4) /* call main */ jal ra, main /* break */ ebreak ``` ## 注意点 注意优化等级!如果 Os优化功能不正常,切换为O0 * 优化等级 * 堆栈指针起始位置 * ROM空间大小 * 36MHz系统时钟下,IO最大翻转频率为69KHz * 局部变量中不要使用 volatile 修饰 ## 应用 * 实现低速接口,如SPI,IIC,串口 * 传感器数据采集 * TEC温度控制