Lattice Diamond `include errors [SOLVED]


I am using Lattice Diamond and I have a verilog file with a bunch of `define statements to define global constants.

I include this “header” file (UART_header.v) into another file (uart_loopback_tb.v). It finds the file but there is an error:

" 2049990 ERROR - C:/_libraries/LatticeDiamond/verilog-uart/source/uart/uart_loopback_tb.v(184,38-184,53) (VERI-1128) UART_1_STOP_BIT is not declared "

All of my `defines can not be found.

I have the directory of the header file set as an include path in the project settings for the implementation as well. Also the header file is in the same directory as the file that includes it.

* 	@file UART_Header.v
*	@brief
*	Defines UART module parameter constants
*	@details
*	This file is to support the UART_core.v 
*	@namespace UART_

// UART core register addresses
`define	UART_WRITE_ADDR		= 8'h00;		///< UART TX address
`define	UART_READ_ADDR 		= 8'h00;		///< UART address to read received data
`define	UART_LCR_ADDR 		= 8'h03;		///< Line control register
`define	UART_LSR_ADDR 		= 8'h05;		///< Line status register
`define	UART_DIV_LW_ADDR 	= 8'b00000111;	///< Baud Rate divisor register low word
`define	UART_DIV_HW_ADDR 	= 8'b00000110;	///< Baud Rate divisor register high word

// UART core bit masks
`define	UART_5_DATA_BITS	= 16'b00000000;	///< 5 data bits mask
`define	UART_6_DATA_BITS	= 16'b00000001;	///< 6 data bits mask
`define	UART_7_DATA_BITS	= 16'b00000010;	///< 7 data bits mask
`define	UART_8_DATA_BITS	= 16'b00000011;	///< 8 data bits mask

`define	UART_1_STOP_BIT		= 16'b00000000;	///< 1 stop bit mask
`define	UART_1_5_STOP_BIT	= 16'b00000100;	///< 1.5 stop bits mask
`define	UART_2_STOP_BIT		= 16'b00001000;	///< 2 stop bits mask

`define	UART_PARITY_ENABLE	= 16'b00010000;	///< Enable parity bit mask
`define	UART_PARITY_DISABLE = 16'b00000000;	///< Disable parity bit mask



Then the file that includes it:


//                          Includes

`include "source/uart/UART_header.v"

// Rest of the code for this file



Why can’t it find my `defines? The file that includes the header file is even in the same directory as the header file itself. Does Lattice Diamond support this?

I also tried `include “UART_header.v” since it’s in the same directory, but that gives the same error.

Attached is the project files to open if needed. The uart_loopback_tb.v is selected for synthesis and simulation even though it’s a test bench. This is because the errors won’t show up in lattice if you choose simulation only and then when you use a simulator, it will catch the error. This is just so lattice diamond catches the error without needing to open active HDL. (29.2 KB)


A couple things you’ll want to change:

  1. Remember that your macros are not variables, they are replaced with whatever is on the right-hand side of them. It behaves similar to the C macro preprocessor. This means that any extra symbols and comments will be directly substituted as well.

    Instead of this:

    `define	UART_WRITE_ADDR		= 8'h00;		///< UART TX address

    Do this:

    /// UART TX address
    `define	UART_WRITE_ADDR		  8'h00		
  2. When you reference a macro, you need to use the ` character before the macro name.

    Instead of this:


    Do this:


The reason the tool can’t find your macro is because of #2. Once you fix that, you’ll need to also fix #1.

Good luck!


Yes, thank you. I converted those `defines from localparam when I moved them to their own file and forgot to remove the “=” and “;”. Don’t know how I missed that.


Great! I hope this solved your problem. If it did, let me know and we can add the [SOLVED] tag to the topic title.


Yes. That fixed the issue. Thank you