CN0363
Overview
The purpose of this testbench is to validate the SPI interface functionality of the projects/cn0363 reference design.
The entire HDL documentation can be found here CN0363 HDL project.
Block design
The testbench block design includes part of the CN0363 HDL reference design, along with VIPs used for clocking, reset, PS and DDR simulations.
Block diagram
The data path and clock domains are depicted in the below diagram:
Configuration parameters and modes
The following parameters of this project can be configured:
DATA_WIDTH: defines the SPI data width in bits
DATA_DLENGTH: defines the actual data length in bits being transferred
NUM_OF_CS: defines the number of chip select lines
THREE_WIRE: enables three-wire SPI mode: Options: 0 - Four-wire mode, 1 - Three-wire mode
CPOL: defines the SPI clock polarity: Options: 0 - Clock idle state is low, 1 - Clock idle state is high
CPHA: defines the SPI clock phase: Options: 0 - Data captured on first edge, 1 - Data captured on second edge
CLOCK_DIVIDER: defines the SPI clock divider value
NUM_OF_WORDS: defines the number of words per transfer
SDO_IDLE_STATE: defines the SDO idle state: Options: 0 - Low, 1 - High
Configuration files
The following configuration file is available:
Configuration mode
Parameters
DATA_WIDTH
DATA_DLENGTH
NUM_OF_CS
THREE_WIRE
CPOL
CPHA
CLOCK_DIVIDER
NUM_OF_WORDS
SDO_IDLE_STATE
cfg1
8
8
2
0
0
1
0
1
0
Tests
The following test program file is available:
Test program |
Usage |
|---|---|
test_program |
Tests the SPI Engine interface and DMA transfer capabilities for CN0363 colorimeter data acquisition. |
Available configurations & tests combinations
The test program is compatible with all of the above mentioned configurations.
CPU/Memory interconnect addresses
Below are the CPU/Memory interconnect addresses used in this project:
Instance |
Address |
|---|---|
axi_intc |
0x4120_0000 |
axi_adc |
0x43C0_0000 |
spi_cn0363_axi_regmap |
0x44A0_0000 |
cn0363_dma |
0x44A3_0000 |
ddr_axi_vip |
0x8000_0000 |
Interrupts
Below are the Programmable Logic interrupts used in this project:
Instance name |
HDL |
|---|---|
cn0363_dma |
13 |
spi_cn0363 |
12 |
Test stimulus
The test program is structured into several tests as follows:
Environment bringup
The steps of the environment bringup are:
Create the environment
Start the environment
Start the clocks
Assert the resets
Sanity test
This test verifies basic communication with the AXI register maps by:
Reading the VERSION register from the SPI Engine AXI interface
Testing SCRATCH register read/write functionality
Performing sanity tests on the DMA interface
This ensures that the AXI bus communication is working correctly before proceeding with more complex tests.
FIFO SPI test
The FIFO SPI test verifies simple serial transfers made through the SPI Engine Execution module in FIFO mode.
The steps of this test are:
Enable the SPI Engine and configure the Execution module with transfer parameters
Set up the interrupt mask to enable SYNC and offload SYNC interrupts
Write test data (0xDEAD) to the SDO FIFO
Generate a FIFO transaction using SPI Engine commands:
Assert chip select
Transfer data word
De-assert chip select
Generate SYNC interrupt
Wait for the SYNC interrupt to indicate transfer completion
Read back the captured data from the SDI FIFO using the PEEK register
Compare the received data with the expected pattern generated by the testbench SDI data generator
Offload SPI test
The Offload SPI test verifies the SPI Engine Offload module functionality for autonomous data acquisition triggered by the util_sigma_delta_spi data_ready signal.
The CN0363 design uses the util_sigma_delta_spi module to detect ADC conversion completion and generate a trigger for the SPI Engine Offload. The testbench simulates the AD7175-2 DOUT/RDY behavior by driving SDI LOW when the SPI bus is idle, allowing util_sigma_delta_spi to naturally detect data_ready and trigger offload transfers.
The steps of this test are:
Configure the DMA for data transfer:
Enable DMA
Set flags (non-cyclic, TLAST enabled, partial reporting enabled)
Set transfer length (NUM_OF_TRANSFERS * 4 * 2 bytes)
Set destination address in DDR memory
Start the DMA transfer
Configure the Offload module with SPI Engine command sequence:
Configuration command (INST_CFG)
Prescaler setting (INST_PRESCALE)
Data length configuration (INST_DLENGTH)
Assert chip select
Read command (INST_RD)
De-assert chip select
Re-assert chip select (re-arms the 63-clock data_ready counter)
SYNC command with ID=2 to generate interrupt
Assert CS LOW via FIFO command to bootstrap the first natural trigger
Start the offload module to begin autonomous operation
Count completed transfers using offload SYNC IRQ events
Wait for all transfers (NUM_OF_TRANSFERS) to complete
Stop the offload module
Verify that:
Interrupts were properly generated (IRQ test)
Captured SDI data at the offload output matches the expected pattern from the SDI data generator (Offload test)
Note
In the CN0363 design, offload SDI data passes through a processing pipeline (phase_data_sync, HPF, CORDIC demodulator, LPF, DMA sequencer) before reaching DDR memory. Therefore, offload data verification is performed by tapping the SPI Engine Offload module’s SDI output directly, rather than reading back from DDR.
Stop the environment
Stop the clocks
Building the testbench
The testbench is built upon ADI’s generic HDL reference design framework. ADI does not distribute compiled files of these projects so they must be built from the sources available here and here, with the specified hierarchy described Set up the Testbenches repository. To get the source you must clone the HDL repository, and then build the project as follows:
Linux/Cygwin/WSL
Example 1
Build all the possible combinations of tests and configurations, using only the command line.
user@analog:~$
cd testbenches/project/cn0363
user@analog:~/testbenches/project/cn0363$
make
Example 2
Build all the possible combinations of tests and configurations, using the Vivado GUI. This command will launch Vivado, will run the simulation and display the waveforms.
user@analog:~$
cd testbenches/project/cn0363
user@analog:~/testbenches/project/cn0363$
make MODE=gui
Example 3
Build a particular combination of test and configuration, using the Vivado GUI. This command will launch Vivado, will run the simulation and display the waveforms.
user@analog:~$
cd testbenches/project/cn0363
user@analog:~/testbenches/project/cn0363$
make MODE=gui CFG=cfg1 TST=test_program
The built projects can be found in the runs folder, where each configuration
specific build has its own folder named after the configuration file’s name.
Example: if the following command was run for a single configuration in the
clean folder (no runs folder available):
make CFG=cfg1
Then the subfolder under runs name will be:
cfg1
Resources
More information
Support
Analog Devices, Inc. will provide limited online support for anyone using the reference design with ADI components via the EngineerZone FPGA reference designs forum.
It should be noted, that the older the tools’ versions and release branches are, the lower the chances to receive support from ADI engineers.