DE1-SoC User Manual
DE1-SoC User Manual
DE1-SoC User Manual
com
March 14, 2014
CONTENTS
Chapter 7 Examples for using both HPS SoC and FGPA ........................................... 99
DE1-SoC
Development Kit
The DE1-SoC Development Kit presents a robust hardware design platform built around the Altera
System-on-Chip (SoC) FPGA, which combines the latest dual-core Cortex-A9 embedded cores
with industry-leading programmable logic for ultimate design flexibility. Users can now leverage
the power of tremendous re-configurability paired with a high-performance, low-power processor
system. Altera’s SoC integrates an ARM-based hard processor system (HPS) consisting of processor,
peripherals and memory interfaces tied seamlessly with the FPGA fabric using a high-bandwidth
interconnect backbone. The DE1-SoC development board is equipped with high-speed DDR3
memory, video and audio capabilities, Ethernet networking, and much more that promise many
exciting applications.
The DE1-SoC Development Kit contains all the tools needed to use the board in conjunction with a
computer that runs the Microsoft Windows XP or later.
The DE1-SoC System CD contains all the documents and supporting materials associated with
DE1-SoC, including the user manual, system builder, reference designs, and device datasheets.
Users can download this system CD from the link: http://cd-de1-soc.terasic.com.
Here are the addresses where you can get help if you encounter any problems:
Altera Corporation
101 Innovation Drive San Jose, California, 95134 USA
Email: [email protected]
Terasic Technologies
9F., No.176, Sec.2, Gongdao 5th Rd, East Dist, Hsinchu City, 30070. Taiwan
Email: [email protected]
Tel.: +886-3-575-0880
Website: de1-soc.terasic.com
Introduction of the
DE1-SoC Board
This chapter provides an introduction to the features and design characteristics of the board.
Figure 2-1 shows a photograph of the board. It depicts the layout of the board and indicates the
location of the connectors and key components.
The DE1-SoC board has many features that allow users to implement a wide range of designed
circuits, from simple circuits to various multimedia projects.
FPGA
Figure 2-3 is the block diagram of the board. All the connections are established through the
Cyclone V SoC FPGA device to provide maximum flexibility for users. Users can configure the
FPGA to implement any system design.
FPGA Device
Communication
Two port USB 2.0 Host (ULPI interface with USB type A connector)
UART to USB (USB Mini-B connector)
10/100/1000 Ethernet
PS/2 mouse/keyboard
IR emitter/receiver
I2C multiplexer
Connectors
D is p la y
A u d io
Video Input
ADC
Sensors
G-Sensor on HPS
Power
12V DC input
When the DE1-SoC board is powered on, the FPGA can be configured from EPCQ or HPS. The
MSEL[4:0] pins are used to select the configuration scheme. It is implemented as a 6-pin DIP
switch SW10 on the DE1-SoC board, as shown in Figure 3-1.
Figure 3-1 DIP switch (SW10) setting of Active Serial (AS) mode at the back of DE1-SoC board
Table 3-1 shows the relation between MSEL[4:0] and DIP switch (SW10).
Figure 3-1 shows MSEL[4:0] setting of AS mode, which is also the default setting on DE1-SoC.
When the board is powered on, the FPGA is configured from EPCQ, which is pre-programmed with
the default code. If developers wish to reconfigure FPGA from an application software running on
Linux, the MSEL[4:0] needs to be set to “01010” before the programming process begins. If
developers using the "Linux Console with frame buffer" or "Linux LXDE Desktop" SD Card image,
the MSEL[4:0] needs to be set to “00000” before the board is powered on.
1. JTAG programming: It is named after the IEEE standards Joint Test Action Group.
The configuration bit stream is downloaded directly into the Cyclone V SoC FPGA. The FPGA will
retain its current status as long as the power keeps applying to the board; the configuration
information will be lost when the power is off.
The configuration bit stream is downloaded into the quad serial configuration device (EPCQ256),
which provides non-volatile storage for the bit stream. The information is retained within EPCQ256
1. Open the Quartus II programmer and click “Auto Detect”, as circled in Figure 3-3
2. Select detected device associated with the board, as circled in Figure 3-4.
4. Right click on the FPGA device and open the .sof file to be programmed, as highlighted in
Figure 3-6.
Figure 3-7 Select the .sof file to be programmed into the FPGA device
6. Click “Program/Configure” check box and then click “Start” button to download the .sof file
into the FPGA device, as shown in Figure 3-8.
The DE1-SoC board uses a quad serial configuration device (EPCQ256) to store
configuration data for the Cyclone V SoC FPGA. This configuration data is
automatically loaded from the quad serial configuration device chip into the FPGA
when the board is powered up.
Users need to use Serial Flash Loader (SFL) to program the quad serial configuration
device via JTAG interface. The FPGA-based SFL is a soft intellectual property (IP)
core within the FPGA that bridge the JTAG and Flash interfaces. The SFL
Megafunction is available in Quartus II. Figure 3-9 shows the programming method
when adopting SFL solution.
Please refer to Chapter 9: Steps of Programming the Quad Serial Configuration Device
for the basic programming instruction on the serial configuration device.
DE1-SoC has four status LEDs onboard. Table 3-3 describes the status of these LED indicators.
TXD UART TXD Illuminate when data is transferred from FT232R to USB Host.
RXD UART RXD Illuminate when data is transferred from USB Host to FT232R.
D5 JTAG_RX
Reserved
D4 JTAG_TX
There are two HPS reset buttons on DE1-SoC, HPS (cold) reset and HPS warm reset, as shown in
Figure 3-10. Table 3-4 describes the purpose of these two HPS reset buttons. Figure 3-11 is the
reset tree for DE1-SoC.
Figure 3-12 shows the default frequency of all external clocks to the Cyclone V SoC FPGA. A
clock generator is used to distribute clock signals with low jitter. The four 50MHz clock signals
connected to the FPGA are used as clock sources for user logic. One 25MHz clock signal is
connected to two HPS clock inputs, and the other one is connected to the clock input of Gigabit
Ethernet Transceiver. Two 24MHz clock signals are connected to the clock inputs of USB
Host/OTG PHY and USB hub controller. The associated pin assignment for clock inputs to FPGA
I/O pins is listed in Table 3-5.
This section describes the interfaces connected to the FPGA. Users can control or monitor different
interfaces with user logic from the FPGA.
The board has four push-buttons connected to the FPGA, as shown in Figure 3-13 Connections
between the push-buttons and the Cyclone V SoC FPGA. Schmitt trigger circuit is implemented and act
as switch debounce in Figure 3-14 for the push-buttons connected. The four push-buttons named
KEY0, KEY1, KEY2, and KEY3 coming out of the Schmitt trigger device are connected directly to
the Cyclone V SoC FPGA. The push-button generates a low logic level or high logic level when it
is pressed or not, respectively. Since the push-buttons are debounced, they can be used as clock or
reset inputs in a circuit.
Figure 3-13 Connections between the push-buttons and the Cyclone V SoC FPGA
Before
Debouncing
Schmitt Trigger
Debounced
Figure 3-15 Connections between the slide switches and the Cyclone V SoC FPGA
There are also ten user-controllable LEDs connected to the FPGA. Each LED is driven directly and
individually by the Cyclone V SoC FPGA; driving its associated pin to a high logic level or low
level to turn the LED on or off, respectively. Figure 3-16 shows the connections between LEDs and
Cyclone V SoC FPGA. Table 3-6, Table 3-7 and Table 3-8 list the pin assignment of user
push-buttons, switches, and LEDs.
The DE1-SoC board has six 7-segment displays. These displays are paired to display numbers in
various sizes. Figure 3-17 shows the connection of seven segments (common anode) to pins on
Cyclone V SoC FPGA. The segment can be turned on or off by applying a low logic level or high
logic level from the FPGA, respectively.
Each segment in a display is indexed from 0 to 6, with corresponding positions given in Figure
3-17. Table 3-9 shows the pin assignment of FPGA to the 7-segment displays.
Figure 3-17 Connections between the 7-segment display HEX0 and the Cyclone V SoC FPGA
The board has two 40-pin expansion headers. Each header has 36 user pins connected directly to the
Cyclone V SoC FPGA. It also comes with DC +5V (VCC5), DC +3.3V (VCC3P3), and two GND
pins. The maximum power consumption allowed for a daughter card connected to one or two GPIO
ports is shown in Table 3-10.
Each pin on the expansion headers is connected to two diodes and a resistor for protection against
high or low voltage level. Figure 3-18 shows the protection circuitry applied to all 2x36 data pins.
Table 3-11 shows the pin assignment of two GPIO headers.
Figure 3-18 Connections between the GPIO header and Cyclone V SoC FPGA
The DE1-SoC board offers high-quality 24-bit audio via the Wolfson WM8731 audio CODEC
(Encoder/Decoder). This chip supports microphone-in, line-in, and line-out ports, with adjustable
sample rate from 8 kHz to 96 kHz. The WM8731 is controlled via serial I2C bus, which is
connected to HPS or Cyclone V SoC FPGA through an I2C multiplexer. The connection of the
audio circuitry to the FPGA is shown in Figure 3-19, and the associated pin assignment to the
FPGA is listed in Table 3-12. More information about the WM8731 codec is available in its
datasheet, which can be found on the manufacturer’s website, or in the directory
\DE1_SOC_datasheets\Audio CODEC of DE1-SoC System CD.
The DE1-SoC board implements an I2C multiplexer for HPS to access the I2C bus originally
owned by FPGA. Figure 3-20 shows the connection of I2C multiplexer to the FPGA and HPS. HPS
can access Audio CODEC and TV Decoder if and only if the HPS_I2C_CONTROL signal is set to
high. The pin assignment of I2C bus is listed in Table 3-13 .
3.6.6 VGA
The DE1-SoC board has a 15-pin D-SUB connector populated for VGA output. The VGA
synchronization signals are generated directly from the Cyclone V SoC FPGA, and the Analog
Devices ADV7123 triple 10-bit high-speed video DAC (only the higher 8-bits are used) transforms
signals from digital to analog to represent three fundamental colors (red, green, and blue). It can
support up to SXGA standard (1280*1024) with signals transmitted at 100MHz. Figure 3-21 shows
the signals connected between the FPGA and VGA.
The timing specification for VGA synchronization and RGB (red, green, blue) data can be easily
found on website nowadays. Figure 3-21 illustrates the basic timing requirements for each row
(horizontal) displayed on a VGA monitor. An active-low pulse of specific duration is applied to the
horizontal synchronization (hsync) input of the monitor, which signifies the end of one row of data
and the start of the next. The data (RGB) output to the monitor must be off (driven to 0 V) for a
time period called the back porch (b) after the hsync pulse occurs, which is followed by the display
interval (c). During the data display interval the RGB data drives each pixel in turn across the row
being displayed. Finally, there is a time period called the front porch (d) where the RGB signals
must again be off before the next hsync pulse can occur. The timing of vertical synchronization
(vsync) is similar to the one shown in Figure 3-22, except that a vsync pulse signifies the end of
one frame and the start of the next, and the data refers to the set of rows in the frame (horizontal
timing). Table 3-14 and Table 3-15 show different resolutions and durations of time period a, b, c,
and d for both horizontal and vertical timing.
More information about the ADV7123 video DAC is available in its datasheet, which can be found
on the manufacturer’s website, or in the directory \Datasheets\VIDEO DAC of DE1-SoC System
CD. The pin assignment between the Cyclone V SoC FPGA and the ADV7123 is listed in Table
3-16.
3.6.7 TV Decoder
The DE1-SoC board is equipped with an Analog Device ADV7180 TV decoder chip. The
ADV7180 is an integrated video decoder which automatically detects and converts a standard
analog baseband television signals (NTSC, PAL, and SECAM) into 4:2:2 component video data,
which is compatible with the 8-bit ITU-R BT.656 interface standard. The ADV7180 is compatible
with wide range of video devices, including DVD players, tape-based sources, broadcast sources,
and security/surveillance cameras.
The board comes with an infrared remote-control receiver module (model: IRM-V538/TR1), whose
datasheet is provided in the directory \Datasheets\ IR Receiver and Emitter of DE1-SoC system CD.
The remote controller included in the kit has an encoding chip (uPD6121G) built-in for generating
infrared signals. Figure 3-24 shows the connection of IR receiver to the FPGA. Table 3-18 shows
the pin assignment of IR receiver to the FPGA.
The board has an IR emitter LED for IR communication, which is widely used for operating
television device wirelessly from a short line-of-sight distance. It can also be used to communicate
with other systems by matching this IR emitter LED with another IR receiver on the other side.
Figure 3-25 shows the connection of IR emitter LED to the FPGA. Table 3-19 shows the pin
assignment of IR emitter LED to the FPGA.
The board features 64MB of SDRAM with a single 64MB (32Mx16) SDRAM chip. The chip
consists of 16-bit data line, control line, and address line connected to the FPGA. This chip uses the
3.3V LVCMOS signaling standard. Connections between the FPGA and SDRAM are shown in
Figure 3-26, and the pin assignment is listed in Table 3-20.
The DE1-SoC board comes with a standard PS/2 interface and a connector for a PS/2 keyboard or
mouse. Figure 3-27 shows the connection of PS/2 circuit to the FPGA. Users can use the PS/2
keyboard and mouse on the DE1-SoC board simultaneously by a PS/2 Y-Cable, as shown in Figure
3-28. Instructions on how to use PS/2 mouse and/or keyboard can be found on various educational
websites. The pin assignment associated to this interface is shown in Table 3-21.
Note: If users connect only one PS/2 equipment, the PS/2 signals connected to the FPGA I/O should
be “PS2_CLK” and “PS2_DAT”.
The DE1-SoC has an analog-to-digital converter (AD7928), which features lower power,
eight-channel CMOS 12-bit. This ADC offers conversion throughput rate up to 1MSPS. The analog
input range for all input channels can be 0 V to 2.5 V or 0 V to 5V, depending on the RANGE bit in
the control register. It can be configured to accept eight input signals at inputs ADC_IN0 through
ADC_IN7. These eight input signals are connected to a 2x5 header, as shown in Figure 3-29.
More information about the A/D converter chip is available in its datasheet. It can be found on
manufacturer’s website or in the directory \datasheet of De1-SoC system CD.
Figure 3-30 shows the connections between the FPGA, 2x5 header, and the A/D converter.
This section introduces the interfaces connected to the HPS section of the Cyclone V SoC FPGA.
Users can access these interfaces via the HPS processor.
Similar to the FPGA, the HPS also has its set of switches, buttons, LEDs, and other interfaces
connected exclusively. Users can control these interfaces to monitor the status of HPS.
Table 3-23 gives the pin assignment of all the LEDs, switches, and push-buttons.
The board supports Gigabit Ethernet transfer by an external Micrel KSZ9021RN PHY chip and
HPS Ethernet MAC function. The KSZ9021RN chip with integrated 10/100/1000 Mbps Gigabit
Ethernet transceiver also supports RGMII MAC interface. Figure 3-31 shows the connections
between the HPS, Gigabit Ethernet PHY, and RJ-45 connector.
The pin assignment associated to Gigabit Ethernet interface is listed in Table 3-24. More
information about the KSZ9021RN PHY chip and its datasheet, as well as the application notes,
which are available on the manufacturer’s website.
There are two LEDs, green LED (LEDG) and yellow LED (LEDY), which represent the status of
Ethernet PHY (KSZ9021RNI). The LED control signals are connected to the LEDs on the RJ45
connector. The state and definition of LEDG and LEDY are listed in Table 3-25. For instance, the
connection from board to Gigabit Ethernet is established once the LEDG lights on.
3.7.3 UART
The board has one UART interface connected for communication with the HPS. This interface
doesn’t support HW flow control signals. The physical interface is implemented by UART-USB
onboard bridge from a FT232R chip to the host with an USB Mini-B connector. More information
about the chip is available on the manufacturer’s website, or in the directory \Datasheets\UART TO
The DDR3 devices connected to the HPS are the exact same model as the ones connected to the
FPGA. The capacity is 1GB and the data bandwidth is in 32-bit, comprised of two x16 devices with
a single address/command bus. The signals are connected to the dedicated Hard Memory Controller
for HPS I/O banks and the target speed is 400 MHz. Table 3-27 lists the pin assignment of DDR3
and its description with I/O standard.
The board supports Micro SD card interface with x4 data lines. It serves not only an external
storage for the HPS, but also an alternative boot option for DE1-SoC board. Figure 3-33 shows
signals connected between the HPS and Micro SD card socket.
Table 3-28 lists the pin assignment of Micro SD card socket to the HPS.
The board has two USB 2.0 type-A ports with a SMSC USB3300 controller and a 2-port hub
controller. The SMSC USB3300 device in 32-pin QFN package interfaces with the SMSC
USB2512B hub controller. This device supports UTMI+ Low Pin Interface (ULPI), which
communicates with the USB 2.0 controller in HPS. The PHY operates in Host mode by connecting
the ID pin of USB3300 to ground. When operating in Host mode, the device is powered by the two
USB type-A ports. Figure 3-34 shows the connections of USB PTG PHY to the HPS. Table 3-29
lists the pin assignment of USBOTG PHY to the HPS.
3.7.7 G-sensor
The board comes with a digital accelerometer sensor module (ADXL345), commonly known as
G-sensor. This G-sensor is a small, thin, ultralow power assumption 3-axis accelerometer with
high-resolution measurement. Digitalized output is formatted as 16-bit in two’s complement and
can be accessed through I2C interface. The I2C address of G-sensor is 0xA6/0xA7. More
information about this chip can be found in its datasheet, which is available on manufacturer’s
website or in the directory \Datasheet folder of DE1-SoC system CD. Figure 3-35 shows the
connections between the HPS and G-sensor. Table 3-30 lists the pin assignment of G-senor to the
The board has a 14-pin header, which is originally used to communicate with various daughter
cards from Linear Technology. It is connected to the SPI Master and I2C ports of HPS. The
communication with these two protocols is bi-directional. The 14-pin header can also be used for
GPIO, SPI, or I2C based communication with the HPS. Connections between the HPS and LTC
connector are shown in Figure 3-36, and the pin assignment of LTC connector is listed in Table
3-31.
DE1-SoC System
Builder
This chapter describes how users can create a custom design project with the tool named DE1-SoC
System Builder.
4.1 Introduction
The DE1-SoC System Builder is a Windows-based utility. It is designed to help users create a
Quartus II project for DE1-SoC within minutes. The generated Quartus II project files include:
The above files generated by the DE1-SoC System Builder can also prevent occurrence of situations
that are prone to compilation error when users manually edit the top-level design file or place pin
assignment. The common mistakes that users encounter are:
This section provides an introduction to the design flow of building a Quartus II project for
DE1-SoC under the DE1-SoC System Builder. The design flow is illustrated in Figure 4-1.
The top-level design file contains a top-level Verilog HDL wrapper for users to add their own
design/logic. The Quartus II setting file contains information such as FPGA device type, top-level
pin assignment, and the I/O standard for each user-defined I/O pin.
Finally, the Quartus II programmer is used to download .sof file to the development board via JTAG
interface.
Figure 4-1 Design flow of building a project from the beginning to the end
This section provides the procedures in details on how to use the DE1-SoC System Builder.
Enter the project name in the circled area, as shown in Figure 4-3.
The project name typed in will be assigned automatically as the name of your top-level design
entity.
System Configuration
Users are given the flexibility in the System Configuration to include their choice of components in
the project, as shown in Figure 4-4. Each component onboard is listed and users can enable or
disable one or more components at will. If a component is enabled, the DE1-SoC System Builder
will automatically generate its associated pin assignment, including the pin name, pin location, pin
direction, and I/O standard.
GPIO Expansion
If users connect any Terasic GPIO-based daughter card to the GPIO connector(s) on DE1-SoC, the
DE1-SoC System Builder can generate a project that include the corresponding module, as shown
in Figure 4-5. It will also generate the associated pin assignment automatically, including pin name,
pin location, pin direction, and I/O standard.
The “Prefix Name” is an optional feature that denote the pin name of the daughter card assigned in
your design. Users may leave this field blank.
The DE1-SoC System Builder also provides the option to load a setting or save users’ current board
configuration in .cfg file, as shown in Figure 4-6.
Project Generation
When users press the Generate button, the DE1-SoC System Builder will generate the
corresponding Quartus II files and documents, as listed in Table 4-1:
Users can add custom logic into the project in Quartus II and compile the project to generate the
SRAM Object File (.sof).
Installation of Demonstrations
Copy the folder Demonstrations to a local directory of your choice. It is important to make sure the
path to your local directory contains NO space. Otherwise it will lead to error in Nios II. Note
Quartus II v13.0 or later is required for all DE1-SoC demonstrations to support Cyclone V SoC
device.
The DE1-SoC board has a default configuration bit-stream pre-programmed, which demonstrates
some of the basic features onboard. The setup required for this demonstration and the location of its
files are shown below.
If users want to program a new design into the EPCQ device, the easiest method is to
copy the new .sof file into the demo_batch folder and execute the test.bat. Option “2”
will convert the .sof to .jic and option”3” will program .jic file into the EPCQ device.
Figure 5-1 Command line of the batch file to program the FPGA and EPCQ device
This demonstration shows how to implement an audio recorder and player on DE1-SoC board with
the built-in audio CODEC chip. It is developed based on Qsys and Eclipse. Figure 5-2 shows the
buttons and slide switches used to interact this demonstration onboard. Users can configure this
audio system through two push-buttons and four slide switches:
Figure 5-3 shows the block diagram of audio recorder and player design. There are hardware and
software parts in the block diagram. The software part stores the Nios II program in the on-chip
memory. The software part is built under Eclipse in C programming language. The hardware part is
built under Qsys in Quartus II. The hardware part includes all the other blocks such as the “AUDIO
Controller”, which is a user-defined Qsys component and it is designed to send audio data to the
audio chip or receive audio data from the audio chip.
The audio chip is programmed through I2C protocol, which is implemented in C code. The I2C pins
from the audio chip are connected to Qsys system interconnect fabric through PIO controllers. The
audio chip is configured in master mode in this demonstration. The audio interface is configured as
16-bit I2S mode. 18.432MHz clock generated by the PLL is connected to the MCLK/XTI pin of the
audio chip through the audio controller.
Note:
(1). Execute DE1_SoC _Audio \demo_batch\ DE1-SoC_Audio.bat to download .sof and .elf
files.
(3). Playing process will stop if the audio data is played completely.
This demonstration uses the microphone-in, line-in, and line-out ports on DE1-SoC to create a
Karaoke machine. The WM8731 CODEC is configured in master mode. The audio CODEC
generates AD/DA serial bit clock (BCK) and the left/right channel clock (LRCK) automatically. The
I2C interface is used to configure the audio CODEC, as shown in Figure 5-4. The sample rate and
gain of the CODEC are set in a similar manner, and the data input from the line-in port is then
mixed with the microphone-in port. The result is sent out to the line-out port.
The sample rate is set to 48 kHz in this demonstration. The gain of the audio CODEC is
reconfigured via I2C bus by pressing the pushbutton KEY0, cycling within ten predefined gain
values (volume levels) provided by the device.
There are many applications use SDRAM as a temporary storage. Both hardware and software
designs are provided to illustrate how to perform memory access in Qsys in this demonstration. It
also shows how Altera’s SDRAM controller IP accesses SDRAM and how the Nios II processor
reads and writes the SDRAM for hardware verification. The SDRAM controller handles complex
aspects of accessing SDRAM such as initializing the memory device, managing SDRAM banks,
and keeping the devices refreshed at certain interval.
Figure 5-6 shows the system block diagram of this demonstration. The system requires a 50 MHz
clock input from the board. The SDRAM controller is configured as a 64MB controller. The
working frequency of the SDRAM controller is 100MHz, and the Nios II program is running on the
on-chip memory.
The system flow is controlled by a program running in Nios II. The Nios II program writes test
patterns into the entire 64MB of SDRAM first before calling the Nios II system function,
alt_dcache_flush_all, to make sure all the data are written to the SDRAM. It then reads data from
the SDRAM for data verification. The program will show the progress in nios-terminal when
writing/reading data to/from the SDRAM. When the verification process reaches 100%, the result
will be displayed in nios-terminal.
Design Tools
Quartus II v13.1
Nios II Eclipse v13.1
Click “Clean” from the “Project” menu of Nios II Eclipse before compiling the
reference design in Nios II Eclipse.
Demonstration Setup
Quartus II v13.1 and Nios II v13.1 must be pre-installed on the host PC.
Power on the DE1-SoC board.
Connect the DE1-SoC board (J13) to the host PC with a USB cable and install the
USB-Blaster driver if necessary.
Execute the demo batch file “DE1_SoC_SDRAM_Nios_Test.bat” from the directory
DE1_SoC_SDRAM_Nios_Test\demo_batch
After the program is downloaded and executed successfully, a prompt message will be
displayed in nios2-terminal.
Press any button (KEY3~KEY0) to start the SDRAM verification process. Press
KEY0 to run the test continuously.
The program will display the test progress and result, as shown in Figure 5-7.
DE1-SoC system CD offers another SDRAM test with its test code written in Verilog HDL. The
memory size of the SDRAM bank tested is still 64MB.
Figure 5-8 shows the function block diagram of this demonstration. The SDRAM controller uses 50
MHz as a reference clock and generates 100 MHz as the memory clock.
RW_test module writes the entire memory with a test sequence first before comparing the data read
back with the regenerated test sequence, which is same as the data written to the memory. KEY0
triggers test control signals for the SDRAM, and the LEDs will indicate the test result according to
Table 5-3.
Design Tools
Quartus II v13.1
Demonstration Setup
This demonstration turns DE1-SoC board into a TV box by playing video and audio from a DVD
player using the VGA output, audio CODEC and the TV decoder on the DE1-SoC board. Figure
5-9 shows the block diagram of the design. There are two major blocks in the system called
I2C_AV_Config and TV_to_VGA. The TV_to_VGA block consists of the ITU-R 656 Decoder,
SDRAM Frame Buffer, YUV422 to YUV444, YCbCr to RGB, and VGA Controller. The figure also
shows the TV decoder (ADV7180) and the VGA DAC (ADV7123) chip used.
The register values of the TV decoder are used to configure the TV decoder via the I2C_AV_Config
block, which uses the I2C protocol to communicate with the TV decoder. The TV decoder will be
unstable for a time period upon power up, and the Lock Detector block is responsible for detecting
this instability.
The ITU-R 656 Decoder block extracts YcrCb 4:2:2 (YUV 4:2:2) video signals from the ITU-R 656
data stream sent from the TV decoder. It also generates a data valid control signal, which indicates
the valid period of data output. De-interlacing needs to be performed on the data source because the
video signal for the TV decoder is interlaced. The SDRAM Frame Buffer and a field selection
multiplexer (MUX), which is controlled by the VGA Controller, are used to perform the
Finally, the YcrCb_to_RGB block converts the YcrCb data into RGB data output. The VGA
Controller block generates standard VGA synchronous signals VGA_HS and VGA_VS to enable
the display on a VGA monitor.
More information about the PS/2 protocol can be found on various websites.
Introduction
PS/2 protocol uses two wires for bi-directional communication. One is the clock line and the other
one is the data line. The PS/2 controller always has total control over the transmission line, but it is
the PS/2 device which generates the clock signal during data transmission.
After the PS/2 mouse receives an enabling signal at stream mode, it will start sending out
displacement data, which consists of 33 bits. The frame data is cut into three sections and each of
them contains a start bit (always zero), eight data bits (with LSB first), one parity check bit (odd
check), and one stop bit (always one).
The PS/2 controller samples the data line at the falling edge of the PS/2 clock signal. This is
implemented by a shift register, which consists of 33 bits.
easily be implemented using a shift register of 33 bits, but be cautious with the clock domain
crossing problem.
When the PS/2 controller wants to transmit data to device, it first pulls the clock line low for more
than one clock cycle to inhibit the current transmission process or to indicate the start of a new
transmission process, which is usually called as inhibit state. It then pulls low the data line before
releasing the clock line. This is called the request state. The rising edge on the clock line formed by
the release action can also be used to indicate the sample time point as for a 'start bit. The device
will detect this succession and generates a clock sequence in less than 10ms time. The transmit data
consists of 12bits, one start bit (as explained before), eight data bits, one parity check bit (odd
After the power on cycle of the PS/2 mouse, it enters into stream mode automatically and disable
data transmit unless an enabling instruction is received. Figure 5-11 shows the waveform while
communication happening on two lines.
Figure 5-11 Waveform of clock and data signals during data transmission
Figure 5-12 shows the block diagram of the design. It implements a IR TX Controller and a IR RX
Controller. When KEY0 is pressed, data test pattern generator will generate data to the IR TX
Controller continuously. When IR TX Controller is active, it will format the data to be compatible
with NEC IR transmission protocol and send it out through the IR emitter LED. The IR receiver
will decode the received data and display it on the six HEXs. Users can also use a remote to send
data to the IR Receiver. The main function of IR TX /RX controller and IR remote in this
demonstration is described in the following sections.
IR TX Controller
Users can input 8-bit address and 8-bit command into the IR TX Controller. The IR TX Controller will
encode the address and command first before sending it out according to NEC IR transmission protocol
through the IR emitter LED. The input clock of IR TX Controller should be 50MHz.
The NEC IR transmission protocol uses pulse distance to encode the message bits. Each pulse burst is
562.5µs in length with a carrier frequency of 38kHz (26.3µs).
Figure 5-13 shows the duration of logical “1” and “0”. Logical bits are transmitted as follows:
• Logical '0' – a 562.5µs pulse burst followed by a 562.5µs space with a total transmit time
of 1.125ms
Figure 5-14 shows a frame of the protocol. Protocol sends a lead code first, which is a 9ms leading
pulse burst, followed by a 4.5ms window. The second inversed data is sent to verify the accuracy of the
information received. A final 562.5µs pulse burst is sent to signify the end of message transmission.
Because the data is sent in pair (original and inverted) according to the protocol, the overall
transmission time is constant.
Note: The signal received by IR Receiver is inverted. For instance, if IR TX Controller sends a lead
code 9 ms high and then 4.5 ms low, IR Receiver will receive a 9 ms low and then 4.5 ms high lead
code.
When a key on the remote controller show in Figure 5-15 is pressed, the remote controller will emit
a standard frame, as shown in Table 5-5. The beginning of the frame is the lead code, which
represents the start bit, followed by the key-related information. The last bit end code represents the
end of the frame. The value of this frame is completely inverted at the receiving end.
Table 5-5 Key Code Information for Each Key on the Remote
Key Key Code Key Key Code Key Key Code Key Key Code
IR RX Controller
The following demonstration shows how to implement the IP of IR receiver controller in the FPGA.
Figure 5-17 shows the modules used in this demo, including Code Detector, State Machine, and
Shift Register. At the beginning the IR receiver demodulates the signal inputs to the Code Detector .
The Code Detector will check the Lead Code and feedback the examination result to the State
Machine.
The State Machine block will change the state from IDLE to GUIDANCE once the Lead Code is
detected. If the Code Detector detects the Custom Code status, the current state will change from
GUIDANCE to DATAREAD state. The Code Detector will also save the receiving data and output
to the Shift Register and display on the 7-segment. Figure 5-18 shows the state shift diagram of
State Machine block. The input clock should be 50MHz.
This demonstration illustrates steps to evaluate the performance of the 8-channel 12-bit A/D
Converter ADC7928. The DC 5.0V on the 2x5 header is used to drive the analog signals by a
trimmer potentiometer. The voltage can be adjusted within the range between 0 and 5.0V. The 12-bit
voltage measurement is displayed on the NIOS II console. Figure 5-19 shows the block diagram of
this demonstration.
If the input voltage is -2.5V ~ 2.5V, a pre-scale circuit can be used to adjust it to 0 ~ 5V.
Figure 5-20 depicts the pin arrangement of the 2x5 header. This header is the input source of ADC
convertor in this demonstration. Users can connect a trimmer to the specified ADC channel
(ADC_IN0 ~ ADC_IN7) that provides voltage to the ADC convert. The FPGA will read the
associated register in the convertor via serial interface and translates it to voltage value to be
displayed on the Nios II console.
Figure 5-20 Pin distribution of the 2x5 Header for the ADC
System Requirements
Connect the trimmer to corresponding ADC channel on the 2x5 header, as shown in
Figure 5-21, as well as the +5V and GND signals. The setup shown above is
connected to ADC channel 0.
Execute the demo batch file DE1_SoC_ADC.bat to load the bitstream and software
execution file to the FPGA.
The Nios II console will display the voltage of the specified channel voltage result
information
This chapter provides several C-code examples based on the Altera SoC Linux built by Yocto
project. These examples demonstrates major features connected to HPS interface on DE1-SoC
board such as users LED/KEY, I2C interfaced G-sensor, and I2C MUX. All the associated files can
be found in the directory Demonstrations/SOC of the DE1_SoC System CD. Please refer to Chapter
5 "Running Linux on the DE1-SoC board" from the DE1-SoC_Getting_Started_Guide.pdf to run
Linux on DE1-SoC board.
Copy the directory Demonstrations into a local directory of your choice. Altera SoC EDS v13.1 is
required for users to compile the c-code project.
This demonstration shows how to develop first HPS program with Altera SoC EDS tool. Please
refer to My_First_HPS.pdf from the system CD for more details.
Program File
Makefile
A Makefile is required to compile a project. The Makefile used for this demo is:
Compile
Please launch Altera SoC EDS Command Shell to compile a project by executing
C:\altera\13.1\embedded\Embedded_Command_Shell.bat
The "cd" command can change the current directory to where the Hello World project is located.
The "make" command will build the project. The executable file "my_first_hps" will be generated
after the compiling process is successful. The "clean all" command removes all temporary files.
Demonstration Setup
Connect a USB cable to the USB-to-UART connector (J4) on the DE1-SoC board and
the host PC.
Copy the demo file "my_first_hps" into a microSD card under the "/home/root"
folder in Linux.
Insert the booting microSD card into the DE1-SoC board.
Power on the DE1-SoC board.
Launch PuTTY and establish connection to the UART port of Putty. Type "root" to
login Altera Yocto Linux.
Type "./my_first_hps" in the UART terminal of PuTTY to start the program, and the
"Hello World!" message will be displayed in the terminal.
This demonstration shows how to control the users LED and KEY by accessing the register of
GPIO controller through the memory-mapped device driver. The memory-mapped device driver
allows developer to access the system physical memory.
Figure 6-1 shows the function block diagram of this demonstration. The users LED and KEY are
connected to the GPIO1 controller in HPS. The behavior of GPIO controller is controlled by the
register in GPIO controller. The registers can be accessed by application software through the
memory-mapped device driver, which is built into Altera SoC Linux.
The HPS provides three general-purpose I/O (GPIO) interface modules. Figure 6-2 shows the block
diagram of GPIO Interface. GPIO[28..0] is controlled by the GPIO0 controller and GPIO[57..29] is
controlled by the GPIO1 controller. GPIO[70..58] and input-only GPI[13..0] are controlled by the
GPIO2 controller.
The gpio_swporta_ddr configures the LED pin as output pin and drives it high or low by writing
data to the gpio_swporta_dr register. The first bit (least significant bit) of gpio_swporta_dr
controls the direction of first IO pin in the associated GPIO controller and the second bit controls
the direction of second IO pin in the associated GPIO controller and so on. The value "1" in the
register bit indicates the I/O direction is output, and the value "0" in the register bit indicates the I/O
direction is input.
The first bit of gpio_swporta_dr register controls the output value of first I/O pin in the associated
GPIO controller, and the second bit controls the output value of second I/O pin in the associated
GPIO controller and so on. The value "1" in the register bit indicates the output value is high, and
the value "0" indicates the output value is low.
The status of KEY can be queried by reading the value of gpio_ext_porta register. The first bit
represents the input status of first IO pin in the associated GPIO controller, and the second bit
represents the input status of second IO pin in the associated GPIO controller and so on. The value
"1" in the register bit indicates the input state is high, and the value "0" indicates the input state is
low.
The registers of HPS peripherals are mapped to HPS base address space 0xFC000000 with 64KB
size. The registers of the GPIO1 controller are mapped to the base address 0xFF708000 with 4KB
size, and the registers of the GPIO2 controller are mapped to the base address 0xFF70A000 with
4KB size, as shown in Figure 6-3.
Software API
Developers can use the following software API to access the register of GPIO controller.
Developers can also use the following MACRO to access the register
The program must include the following header files to use the above API to access the registers of
GPIO controller.
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
Figure 6-4 shows the HPS users LED and KEY pin assignment for the DE1_SoC board. The LED
is connected to HPS_GPIO53 and the KEY is connected to HPS_GPIO54. They are controlled by
the GPIO1 controller, which also controls HPS_GPIO29 ~ HPS_GPIO57.
Figure 6-5 shows the gpio_swporta_ddr register of the GPIO1 controller. The bit-0 controls the
pin direction of HPS_GPIO29. The bit-24 controls the pin direction of HPS_GPIO53, which
connects to HPS_LED, the bit-25 controls the pin direction of HPS_GPIO54, which connects to
HPS_KEY and so on. The pin direction of HPS_LED and HPS_KEY are controlled by the bit-24
and bit-25 in the gpio_swporta_ddr register of the GPIO1 controller, respectively. Similarly, the
output status of HPS_LED is controlled by the bit-24 in the gpio_swporta_dr register of the
GPIO1 controller. The status of KEY can be queried by reading the value of the bit-24 in the
gpio_ext_porta register of the GPIO1 controller.
The following mask is defined in the demo code to control LED and KEY direction and LED’s
output value.
The following statement is used to configure the LED associated pins as output pins.
alt_setbits_word( ( virtual_base +
( ( uint32_t )( ALT_GPIO1_SWPORTA_DDR_ADDR ) &
( uint32_t )( HW_REGS_MASK ) ) ), USER_IO_DIR );
alt_setbits_word( ( virtual_base +
( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR ) &
( uint32_t )( HW_REGS_MASK ) ) ), BIT_LED );
The following statement is used to read the content of gpio_ext_porta register. The bit mask is used
to check the status of the key.
alt_read_word( ( virtual_base +
Demonstration Setup
Connect a USB cable to the USB-to-UART connector (J4) on the DE1-SoC board and
the host PC.
Copy the executable file "hps_gpio" into the microSD card under the "/home/root"
folder in Linux.
Insert the booting micro SD card into the DE1-SoC board.
Power on the DE1-SoC board.
Launch PuTTY and establish connection to the UART port of Putty. Type "root" to
login Altera Yocto Linux.
Type "./hps_gpio " in the UART terminal of PuTTY to start the program.
HPS_LED will flash twice and users can control the user LED with push-button.
Press HPS_KEY to light up HPS_LED.
Press "CTRL + C" to terminate the application.
This demonstration shows how to control the G-sensor by accessing its registers through the built-in
I2C kernel driver in Altera Soc Yocto Powered Embedded Linux.
I2C Driver
The procedures to read a register value from G-sensor register files by the existing I2C bus driver in
the system are:
The G-sensor I2C bus is connected to the I2C0 controller, as shown in the Figure 6-7. The driver
name given is '/dev/i2c-0'.
The step 4 above can be changed to the following to write a value into a register.
The step 4 above can also be changed to the following to read multiple byte values.
The step 4 above can be changed to the following to write multiple byte values.
G-sensor Control
The ADI ADXL345 provides I2C and SPI interfaces. I2C interface is selected by setting the CS pin
to high on the DE1_SoC board.
The ADI ADXL345 G-sensor provides user-selectable resolution up to 13-bit ± 16g. The
resolution can be configured through the DATA_FORAMT(0x31) register. The data format in this
demonstration is configured as:
The X/Y/Z data value can be derived from the DATAX0(0x32), DATAX1(0x33), DATAY0(0x34),
DATAY1(0x35), DATAZ0(0x36), and DATAX1(0x37) registers. The DATAX0 represents the least
significant byte and the DATAX1 represents the most significant byte. It is recommended to
perform multiple-byte read of all registers to prevent change in data between sequential registers
read. The following statement reads 6 bytes of X, Y, or Z value.
Connect a USB cable to the USB-to-UART connector (J4) on the DE1-SoC board and
the host PC.
Copy the executable file "gsensor" into the microSD card under the "/home/root"
folder in Linux.
Insert the booting microSD card into the DE1-SoC board.
Power on the DE1-SoC board.
Launch PuTTY to establish connection to the UART port of DE1-SoC board. Type
"root" to login Yocto Linux.
Execute "./gsensor" in the UART terminal of PuTTY to start the G-sensor polling.
The demo program will show the X, Y, and Z values in the PuTTY, as shown in Figure
6-8.
The I2C bus on DE1-SoC is originally accessed by FPGA only. This demonstration shows how to
switch the I2C multiplexer for HPS to access the I2C bus.
Figure 6-9 shows the function block diagram of this demonstration. The I2C bus from both FPGA
and HPS are connected to an I2C multiplexer. It is controlled by HPS_I2C_CONTROL, which is
connected to the GPIO1 controller in HPS. The HPS I2C is connected to the I2C0 controller in
HPS, as well as the G-sensor.
HPS_I2C_CONTROL Control
The following mask in the demo code is defined to control the direction and output value of
HPS_I2C_CONTROL.
The following statement is used to configure the HPS_I2C_CONTROL associated pins as output
pin.
alt_setbits_word( ( virtual_base +
( ( uint32_t )( ALT_GPIO1_SWPORTA_DDR_ADDR ) &
( uint32_t )( HW_REGS_MASK ) ) ), HPS_I2C_CONTROL );
alt_setbits_word( ( virtual_base +
( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR ) &
( uint32_t )( HW_REGS_MASK ) ) ), HPS_I2C_CONTROL );
alt_clrbits_word( ( virtual_base +
( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR ) &
( uint32_t )( HW_REGS_MASK ) ) ), HPS_I2C_CONTROL );
The procedures to read register value from TV Decoder by the existing I2C bus driver in the system
are:
Demonstration Setup
Connect a USB cable to the USB-to-UART connector (J4) on the DE1-SoC board and
host PC.
Copy the executable file " i2c_switch " into the microSD card under the "/home/root"
folder in Linux.
Insert the booting microSD card into the DE1-SoC board.
Power on the DE1-SoC board.
Launch PuTTY to establish connection to the UART port of DE1_SoC borad. Type
"root" to login Yocto Linux.
Execute "./ i2c_switch " in the UART terminal of PuTTY to start the I2C MUX test.
The demo program will show the result in the Putty, as shown in Figure 6-10.
Although HPS and FPGA can operate independently, they are tightly coupled via a high-bandwidth
system interconnect built from high-performance ARM AMBA® AXITM bus bridges. Both FPGA
fabric and HPS can access to each other via these interconnect bridges. This chapter provides
demonstrations on how to achieve superior performance and lower latency through these
interconnect bridges when comparing to solutions containing a separate FPGA and discrete
processor.
This demonstration shows how HPS controls the FPGA LED and HEX through Lightweight
HPS-to-FPGA Bridge. The FPGA is configured by HPS through FPGA manager in HPS.
The FPGA manager in HPS configures the FPGA fabric from HPS. It also monitors the state of
FPGA and drives or samples signals to or from the FPGA fabric. The application software is
provided to configure FPGA through the FPGA manager. The FPGA configuration data is stored in
the file with .rbf extension. The MSEL[4:0] must be set to 01010 or 01110 before executing the
application software on HPS.
Figure 7-1 shows the block diagram of this demonstration. The HPS uses Lightweight
HPS-to-FPGA AXI Bridge to communicate with FPGA. The hardware in FPGA part is built into
The Lightweight HPS-to-FPGA Bridge is a peripheral of HPS. The software running on Linux
cannot access the physical address of the HPS peripheral. The physical address must be mapped to
the user space before the peripheral can be accessed. Alternatively, a customized device driver
module can be added to the kernel. The entire CSR span of HPS is mapped to access various
registers within that span. The mapping function and the macro defined below can be reused if any
other peripherals whose physical address is also in this span.
The start address of Lightweight HPS-to-FPGA Bridge after mapping can be retrieved by
ALT_LWFPGASLVS_OFST, which is defined in altera_hps hardware library. The slave IP
connected to the bridge can then be accessed through the base address and the register offset in
these IPs. For instance, the base address of the PIO slave IP in this system is 0x0001_0040, the
direction control register offset is 0x01, and the data register offset is 0x00. The following statement
is used to retrieve the base address of PIO slave IP.
alt_write_word(h2p_lw_led_addr, Mask );
The Mask in the statement decides which bit in the data register of the PIO IP is high or low. The
bits in data register decide the output state of the pins connected to the LEDs. The HEX controlling
part is similar to the LED.
Since Linux supports multi-thread software, the software for this system creates two threads. One
controls the LED and the other one controls the HEX. The system calls pthread_create, which is
called in the main function to create a sub-thread, to complete the job. The program running in the
sub-thread controls the LED flashing in a loop. The main-thread in the main function controls the
digital shown on the HEX that keeps changing in a loop. The state of LED and HEX state change
simultaneously when the FPGA is configured and the software is running on HPS.
Demonstration Setup
Execute "./HPS_LED_HEX " in the UART terminal of PuTTY to start the program.
The message shown in Figure 7-3, will be displayed in the terminal. The LED[9:0]
will be flashing and the number on the HEX[5:0] will keep changing simultaneously.
This example not only controls the peripherals of HPS and FPGA, but also shows how to
implement a GUI program on Linux. Figure 7-4 is the screenshot of DE1-SOC Control Panel.
Programming the
EPCQ Device
This chapter describes how to program the quad serial configuration (EPCQ) device with Serial
Flash Loader (SFL) function via the JTAG interface. Users can program EPCQ devices with a
JTAG indirect configuration (.jic) file, which is converted from a user-specified SRAM object file
(.sof) in Quartus. The .sof file is generated after the project compilation is successful. The steps of
converting .sof to .jic in Quartus II are listed below.
The FPGA should be set to AS x4 mode i.e. MSEL[4..0] = “10010” to use the quad Flash as a
FPGA configuration device.
1. Choose Convert Programming Files from the File menu of Quartus II, as shown in Figure
8-1.
2. Select JTAG Indirect Configuration File (.jic) from the Programming file type field in
the dialog of Convert Programming Files.
5. Browse to the target directory from the File name field and specify the name of output file.
6. Click on the SOF data in the section of Input files to convert, as shown in Figure 8-2.
8. Select the .sof to be converted to a .jic file from the Open File dialog.
9. Click Open.
10. Click on the Flash Loader and click Add Device, as shown in Figure 8-3.
12. Select the targeted FPGA to be programed into the EPCQ, as shown in Figure 8-4.
13. Click OK and the Convert Programming Files page will appear, as shown in Figure 8-5.
Figure 8-5 “Convert Programming Files” page after selecting the device
When the conversion of SOF-to-JIC file is complete, please follow the steps below to program the
EPCQ device with the .jic file created in Quartus II Programmer.
2. Choose Programmer from the Tools menu and the Chain.cdf window will appear.
3. Click Auto Detect and then select the correct device. Both FPGA device and HPS should be
detected, as shown in Figure 8-6.
4. Double click the green rectangle region shown in Figure 8-6 and the Select New
Programming File page will appear. Select the .jic file to be programmed.
The steps to erase the existing file in the EPCQ device are:
2. Choose Programmer from the Tools menu and the Chain.cdf window will appear.
3. Click Auto Detect, and then select correct device, both FPGA device and HPS will detected.
(See Figure 8-6)
4. Double click the green rectangle region shown in Figure 8-6, and the Select New
Programming File page will appear. Select the correct .jic file.
5. Erase the EPCQ device by clicking the corresponding Erase box. A factory default SFL
image will be loaded, as shown in Figure 8-8.
There is a known problem in Quartus II software that the Quartus Programmer must be used to
program the EPCQ device on DE1-SoC board.
Appendix