verilog 编程环境搭建2 —— vscode 插件安装与配置

verilog 编程环境搭建2 —— vscode 插件安装与配置

安装 vscode 的过程这里就不进行详细讲解,这里主要是介绍如何配置 verilog 通过一些插件来实现编译,在安装插件之前我们需要确认电脑中是否已经安装了 C/C++ 和 python 的开发环境

基本环境配置

安装 verilog-HDL/SystemVerilog/Bluespec SystemVerilog 插件

首先我们需要下载 Verilog-HDL/SystemVerilog/Bluespec SystemVerilog 插件

插件配置

首先,我们需要下载最新版本的 ctags ,我们可以直接从 github 上进行下载。windows 上可以直接下载 x64 版本,建议下载最新版本,版本越新,功能就越齐全,github 连接:ctags

下载好之后,我们需要选择并解压到我们指定的文件夹中,注意,我们选择的路径中不能够有中文或空格,否则路径解析会出现问题

配置过程如下:


我们还需要将 ctag.exe 添加到系统路径中:

在插件中我们可以选择不同的编译器:

这里我们选择使用 iverilog ,关于 iverilog 的使用推荐观看这篇博客:全平台轻量开源verilog仿真工具iverilog+GTKWave使用教程

下面附上一些关于 iverilog 的资源的地址:

iverilog 官网

iverilog 下载

iverilog 用户指南

Github 开源地址

GTKWave 下载( iverilog 已经包含)

功能展示

支持 verilog、SV 等语法高亮:

shift+ctrl+p 输入 verilog ,可以直接自动例化模块:

鼠标放在信号上,就会有声明显示在悬浮框中。Ctrl + 左键,点击信号名,自动跳转到声明处。光标放在信号处,右键选择查看定义(快捷键可自行绑定),可以在此处展开声明处的代码,用于修改声明十分方便,就不用再来回跳转了:

注意:这里使用 iverilog 只有按下 ctrl+s 进行保存之后才能够检查报错,按下 ctrl+~ 可以查看报错信息,但是有一点问题就是即使代码全部正确也有可能出现报错,报错信息为:Unknown module type ,所以需要在插件配置的时候添加 -i 指令,这样可以避免这种报错,但是这样就会屏蔽所有报错:

安装 Verilog_Testbench 插件

安装插件:

这个插件可以实现自动生成 testbench ,shift+ctrl+p 输入 testbench,可以直接生成 tb。然后在终端复制即可:

安装 verilog-utils 插件

安装插件:

使用方法

安装好之后,需要实例化的部分,我们只需要选中,打开命令面板,输入 utils 找到命令,就能够进行自动实例化,过程如下:


自动实例化结果如下:

安装 SystemVerilog and Verilog Formatter 插件

安装插件:

这款工具由谷歌推出,同时支持 Verilog 和 System Verilog,效果非常好,支持自定义的格式化参数也很丰富,但是在某些方面上可能会觉得没有 verilog format 好用

可实现功能:

· 自动格式化文件

· 自动格式化选定内容

· 自定义格式

配置插件

一下两处都需要进行配置:

第一处参数如下:

verible-verilog-format: usage: bazel-bin/verilog/tools/formatter/verible-verilog-format [options] <file> [<file...>]
To pipe from stdin, use '-' as <file>.

  Flags from common/formatting/basic_format_style_init.cc:
    --column_limit (Target line length limit to stay under when formatting.);
      default: 100;
    --indentation_spaces (Each indentation level adds this many spaces.);
      default: 2;
    --line_break_penalty (Penalty added to solution for each introduced line
      break.); default: 2;
    --over_column_limit_penalty (For penalty minimization, this represents the
      baseline penalty value of exceeding the column limit. Additional penalty
      of 1 is incurred for each character over this limit); default: 100;
    --wrap_spaces (Each wrap level adds this many spaces. This applies when the
      first element after an open-group section is wrapped. Otherwise, the
      indentation level is set to the column position of the open-group
      operator.); default: 4;


  Flags from external/com_google_absl/absl/flags/parse.cc:
    --flagfile (comma-separated list of files to load flags from); default: ;
    --fromenv (comma-separated list of flags to set from the environment [use
      'export FLAGS_flag1=value']); default: ;
    --tryfromenv (comma-separated list of flags to try to set from the
      environment if present); default: ;
    --undefok (comma-separated list of flag names that it is okay to specify on
      the command line even if the program does not define a flag with that
      name); default: ;


  Flags from verilog/formatting/format_style_init.cc:
    --assignment_statement_alignment (Format various assignments:
      {align,flush-left,preserve,infer}); default: infer;
    --case_items_alignment (Format case items:
      {align,flush-left,preserve,infer}); default: infer;
    --class_member_variable_alignment (Format class member variables:
      {align,flush-left,preserve,infer}); default: infer;
    --compact_indexing_and_selections (Use compact binary expressions inside
      indexing / bit selection operators); default: true;
    --distribution_items_alignment (Aligh distribution items:
      {align,flush-left,preserve,infer}); default: infer;
    --enum_assignment_statement_alignment (Format assignments with enums:
      {align,flush-left,preserve,infer}); default: infer;
    --expand_coverpoints (If true, always expand coverpoints.); default: false;
    --formal_parameters_alignment (Format formal parameters:
      {align,flush-left,preserve,infer}); default: infer;
    --formal_parameters_indentation (Indent formal parameters: {indent,wrap});
      default: wrap;
    --module_net_variable_alignment (Format net/variable declarations:
      {align,flush-left,preserve,infer}); default: infer;
    --named_parameter_alignment (Format named actual parameters:
      {align,flush-left,preserve,infer}); default: infer;
    --named_parameter_indentation (Indent named parameter assignments:
      {indent,wrap}); default: wrap;
    --named_port_alignment (Format named port connections:
      {align,flush-left,preserve,infer}); default: infer;
    --named_port_indentation (Indent named port connections: {indent,wrap});
      default: wrap;
    --port_declarations_alignment (Format port declarations:
      {align,flush-left,preserve,infer}); default: infer;
    --port_declarations_indentation (Indent port declarations: {indent,wrap});
      default: wrap;
    --port_declarations_right_align_packed_dimensions (If true, packed
      dimensions in contexts with enabled alignment are aligned to the right.);
      default: false;
    --port_declarations_right_align_unpacked_dimensions (If true, unpacked
      dimensions in contexts with enabled alignment are aligned to the right.);
      default: false;
    --struct_union_members_alignment (Format struct/union members:
      {align,flush-left,preserve,infer}); default: infer;
    --try_wrap_long_lines (If true, let the formatter attempt to optimize line
      wrapping decisions where wrapping is needed, else leave them unformatted.
      This is a short-term measure to reduce risk-of-harm.); default: false;


  Flags from verilog/parser/verilog_parser.cc:
    --verilog_trace_parser (Trace verilog parser); default: false;


  Flags from verilog/tools/formatter/verilog_format.cc:
    --failsafe_success (If true, always exit with 0 status, even if there were
      input errors or internal errors. In all error conditions, the original
      text is always preserved. This is useful in deploying services where
      fail-safe behaviors should be considered a success.); default: true;
    --inplace (If true, overwrite the input file on successful conditions.);
      default: false;
    --lines (Specific lines to format, 1-based, comma-separated, inclusive N-M
      ranges, N is short for N-N. By default, left unspecified, all lines are
      enabled for formatting. (repeatable, cumulative)); default: ;
    --max_search_states (Limits the number of search states explored during line
      wrap optimization.); default: 100000;
    --show_equally_optimal_wrappings (If true, print when multiple optimal
      solutions are found (stderr), but continue to operate normally.);
      default: false;
    --show_inter_token_info (If true, along with show_token_partition_tree,
      include inter-token information such as spacing and break penalties.);
      default: false;
    --show_largest_token_partitions (If > 0, print token partitioning and then
      exit without formatting output.); default: 0;
    --show_token_partition_tree (If true, print diagnostics after token
      partitioning and then exit without formatting output.); default: false;
    --stdin_name (When using '-' to read from stdin, this gives an alternate
      name for diagnostic purposes. Otherwise this is ignored.);
      default: "<stdin>";
    --verbose (Be more verbose.); default: false;
    --verify_convergence (If true, and not incrementally formatting with
      --lines, verify that re-formatting the formatted output yields no further
      changes, i.e. formatting is convergent.); default: true;

Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.

参数推荐:

--indentation_spaces=4 --named_port_alignment=align  --ort_declarations_alignment=align --module_net_variable_alignment=align

上述参数可以实现大部分常用代码的对齐

第二处只要选择电脑使用的系统对应的即可,我这里使用的是 64 位 windows 系统,所以我选择 Win64

使用方法

和 vscode 内置格式化一样,直接 shift+ctrl+f 就可以格式化文件,ctrl+k 可以格式化选定内容,但是由于插件还在开发中,所以存在以下问题:

  1. else 不会自动换行

  2. 存在语法问题,或者不能识别语法的时候,格式化会使用不了。这里我将最后一个端口加上 "," 就不能格式化了

安装 Verilog Format 插件

在安装插件之前,我们需要安装 Verilog Format ,github 上就可以下载,GitHub 代码仓库:Verilog Format

直接下载系统对应的即可,下载后需要解压出来

配置插件

图中的两个位置都需要进行配置:

第一处需要选择我们刚解压出来的目录中的 verilog-format.exe ,我都目录如下:D:\environment\FPGA\verilog-format-master\bin\verilog-format.exe

第二处需要选择我们刚解压出来的目录中的 .verilog.verilog-format.properties ,我都目录如下:D:\environment\FPGA\verilog-format-master\verilog.verilog-format.properties

如果没有找到第二处需要的文件,选择显示隐藏文件就可以看到了

安装 TerosHDL 插件

安装此插件需要安装 python 环境

image

使用说明

配置完成之后,界面右上角有几个选项,可以用来查看状态机转移图、原理图、说明文档这些

image

到此所哟配置基本全部完成

posted @ 2022-10-27 00:05  ppqppl  阅读(4870)  评论(0编辑  收藏  举报