Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Embedded Microprocessor System Design using

FPGAs
Uwe Meyer-Baese

Embedded Microprocessor
System Design using FPGAs
Uwe Meyer-Baese
Tallahassee, FL, USA

ISBN 978-3-030-50532-5    ISBN 978-3-030-50533-2 (eBook)


https://doi.org/10.1007/978-3-030-50533-2

© Springer Nature Switzerland AG 2021


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of
the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology
now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication
does not imply, even in the absence of a specific statement, that such names are exempt from the relevant
protective laws and regulations and therefore free for general use.
The publisher, the authors, and the editors are safe to assume that the advice and information in this book
are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the material contained herein or for any
errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
To
Anke, Lisa, and my Parents
Preface

Embedded microprocessor systems are everywhere, just look around you. You will
find them in your cellular phones, digital clocks, GPS, video recorder, and internet
router as well as in household electronic entertainment devices. A modern car typi-
cally uses 50–100 microprocessors. Embedded systems are often resource-limited
by price, power dissipation, memory, or storage. A general-purpose computer typi-
cally uses up hundreds of watts, while a clock or remote control only consumes in
microwatts to be able to run for a year on a single AAA battery. Although many
embedded systems require low-power dissipation, the implemented algorithms,
like the error turbo correction coding used in UMTS phones, are computational
demanding. Nevertheless, today, embedded processors perform sophisticated task
and run these complex algorithms. The microprocessors in a car use an estimated
100 million lines of code, the GPS and radio alone account for 20 million lines
of code.
FPGAs are the best choice to start with embedded system design space explora-
tion since these are fine grain logic programmable COTS devices with much lower
NRE costs than cell-based systems available today. The newest generation of
FPGA boards and devices allow to design microprocessor systems using soft,
parameterized, or hardcore microprocessor all with the same board. These boards
are great starting points for many designs since they also have a substantial number
of peripheral components such as Audio CODEC, Video HDMI connector, or SD
cards. It would be very time consuming to include these components in your proj-
ect if using a non-FPGA, standard COTS microprocessor system.
At the beginning of the second decade of the twenty-first century, we find that
the two programmable logic device (PLD) market leaders (Altera/Intel and Xilinx)
both report revenues greater than US$2 billion. FPGAs have enjoyed steady growth
of more than 20% in the last decade, outperforming ASICs and PDSPs by 10%.
This comes from the fact that FPGAs have many features in common with ASICs,
such as reduction in size, weight, and power dissipation; higher throughput; better
security against unauthorized copies; reduced device and inventory cost and
reduced board test costs; and claim advantages over ASICs, such as a reduction in
development time (rapid prototyping), in-circuit (re)programmability, and lower

vii
viii Preface

NRE costs, resulting in more economical designs for solutions requiring less than
1000  units. Another trend in the hardware design world is the migration from
graphical design entries to hardware description language (HDL). It has been
found that “code reuse” is much higher with HDL-based entries than with graphi-
cal design entries. There is a high demand for HDL design engineers and we
already find undergraduate classes teaching logic design with HDLs. Unfortunately,
only two HDL languages are popular today. The US West Coast and Asia area
prefer Verilog, while US East Coast and Europe more frequently use VHDL. For
embedded microprocessor design with FPGAs both languages seem to be well
suited, although some VHDL examples are a little easier to read because of the
supported fixed and floating-point data type in VHDL-2008. Other constraints may
include personal preferences, EDA library and tool availability, readability, capa-
bility, and language extensions using PLIs as well as commercial, business, and
marketing issues, to name just a few. Tool providers acknowledge today that both
languages must be supported, and this book covers examples in both design lan-
guages. We are now fortunate that “baseline” FPGA tools are available from dif-
ferent sources at essentially no cost for educational use. We take advantage of this
fact in this book. It includes code for Altera/Intel Quartus 15.1 Lite Edition as well
as Xilinx Vivado 2016.4 tools, which provides a complete set of design tools, from
a content-sensitive editor, microprocessor configurator, compiler, and simulator to
a bitstream generator. All examples presented are written in VHDL and Verilog
and should be easily adapted to other propriety design-entry systems.
The book is structured as follows. The first chapter starts with a snapshot of
today’s microprocessors and basic microprocessor principles in general and
FPGA-­based microprocessors in particular. It also includes an overview on design
with IP blocks and a PLL IP core design example. The second chapter discusses
devices, boards, and tools used to design state-of-the-art FPGA systems. It dis-
cusses a detailed case study of the ultimate RISC (URISC) microprocessor,
including model discussion, compilation steps, simulation, performance evalua-
tion, power estimation, and floor planning using Quartus and Vivado. This case
study is the basis for many other design examples in subsequent chapters. Chapters
3 and 4 deal with VHDL and Verilog language elements that are used in the
microprocessor design. Chapter 5 reviews the ANSI C language and also dis-
cusses debug methods and differences to C++. In Chap. 6, software tool develop-
ment for microprocessors is presented. We will cover lexical analysis using GNU
Flex and parser implementation with GNU Bison. We will design an assembler
for PicoBlaze microprocessor and a basic and full featured C compiler for a
3-address machine. Instruction set simulator and SW debugger are discussed too.
In Chap. 7, the softcore PicoBlaze is developed in a step-by-step fashion adding
more and more architecture features. Loop control and data memory design are
studied and implemented in HDL. The whole instruction set of the most popular
8-bit FPGA-based microprocessor is then fully discussed in Chap. 8. The Chaps.
9 and 10 discuss the two most popular parameterized core for Altera/Intel and
Xilinx devices called Nios II and MicroBlaze, respectively. We will develop a
top-down and a bottom-up system design approach. Adding custom IP to the
Preface ix

microprocessor will be demonstrated with a floating-point co-processor for Nios


and an HDMI decoder for the MicroBlaze. We will also build a Tiny RISC ver-
sion of the processors called Trisc3n and Trisc3mb that includes the reduced
instruction set and can run basic program generated with the vendor GCC tools.
In Chap. 11, the most popular 32-bit COTS ARM Cortex-A9 hard IP processor
core is discussed, which is part of Altera/Intel and Xilinx’s newest devices. Again
top-down and bottom-up design are presented and a Tiny RISC version Trisc3a
is developed that shows some ideas why ARM Cortex-A9 is a superior architec-
ture. A CIP to accelerate FFT address computation is designed and speed-up is
measured. The Appendix A contains for all five (tiny) processor models (URISC,
Tric2, Trisc3n, Trisc3mb, and Trisc3a) the Verilog source code for Quartus and
Vivado and xsim simulations. Appendix B contains the acronym list. Additional
files, HDL language reference cards, and utilities are include in the CD-ROM and
will be posted online at GitHub and the author’s personal web page.

Acknowledgments

This book is based on an embedded microprocessor system design class I am


teaching every year since 2003 at the FAMU-FSU College of Engineering in
Tallahassee. I have supervised more than 60 Master’s and Ph.D. thesis projects in
the last 17 years. I wish to thank all my colleagues who helped me with critical
discussions in the lab and at conferences and my students that inspired me with
their design ideas, some of which are discussed in the game designs in Chaps. 9,
10, and 11.
I am particularly thankful to my friends and colleagues from the University of
Granada with whom I have had the pleasure of working since 1998 and have also
visited them in Spain in the summer of 2014. They recently helped in getting my lab
started with the research on FECG analysis. Special thanks to A. Garcia, E. Castillo,
L. Parrilla, A. Lloris, and J. Ramírez.
I would like to thank my colleagues from the University of Kassel summer
research stay in Germany in 2015 for their effort to help me with the Vivado Xilinx
designs and ZyBo boards. Special thanks go to P. Zipf, M. Kumm, and K. Möller.
Special thank also to Francesco Poderico for his confidence in me to continue the
support of his Pccomp compiler for PicoBlaze.
I would like to thank my colleagues from the ISS at RHTH Aachen for their time
and efforts in teaching me LISA and C-compiler design during my Humboldt
award– sponsored summer research stay in Germany in 2006 and 2008. Special
thanks go to H. Meyr, G. Ascheid, R. Leupers, D. Kammler, and M. Witte.
I am particular thankful to Guillermo Botella and Diego Gonzalez from the
University of Madrid for help with the image and video processing applications.
I would like to thank Rebecca Nevin, B.  Esposito, M.  Phipps, A.  Vera,
M. Pattichis, and C. Dick at Altera/Intel and Xilinx for software and hardware sup-
port and the permission to include datasheets on the CD of this book. From my
x Preface

publisher (Springer-Verlag) I would like to thank Charles Glaser and Dr. Merkle
for their continuous support and help over recent years.
If you find any errata or have any suggestions to improve this book, please con-
tact me at Uwe.Meyer-­Baese@ieee.org or through my publisher.

Tallahassee, FL, USA  Uwe Meyer-Baese

April 2020
Contents

1 Embedded Microprocessor Systems Basics������������������������������������������    1


1.1 Introduction��������������������������������������������������������������������������������������    1
Fundamental Microprocessors Aspects������������������������������������������������     3
1.2 Embedded Microprocessor on FPGAs����������������������������������������������    6
1.3 Microprocessor Instruction Set Design��������������������������������������������    8
Addressing Modes ������������������������������������������������������������������������������     8
Data Flow Architectures����������������������������������������������������������������������    12
Comparison of Zero-, One-, Two-, and Three-Address CPUs������������    16
Register File and Memory Architecture����������������������������������������������    18
Operation Support��������������������������������������������������������������������������������    20
Next Operation Location����������������������������������������������������������������������    22
1.4 FPGA Technology����������������������������������������������������������������������������   22
Classification by Granularity ��������������������������������������������������������������    24
Classification by Technology ��������������������������������������������������������������    25
Benchmark for FPLDs ������������������������������������������������������������������������    26
Recent FPGA Families and Features ��������������������������������������������������    28
FPGAs Competing Technology ����������������������������������������������������������    30
1.5 Design with Intellectual Property Cores ������������������������������������������   31
IP Core Comparison and Challenges ��������������������������������������������������    33
IP Core-Based PLL Design Example��������������������������������������������������    34
Review Questions and Exercises ��������������������������������������������������������������   37
Short Answer����������������������������������������������������������������������������������������    37
Fill in the Blank ����������������������������������������������������������������������������������    38
True or False����������������������������������������������������������������������������������������    38
Projects and Challenges ����������������������������������������������������������������������    39
References��������������������������������������������������������������������������������������������������   41
2 FPGA Devices, Boards, and Design Tools����������������������������������������������   43
2.1 Introduction��������������������������������������������������������������������������������������   43
2.2 Selection of Prototype Board������������������������������������������������������������   47
Memory������������������������������������������������������������������������������������������������    48

xi
xii Contents

Basic I/O Components ������������������������������������������������������������������������    49


Display Options ����������������������������������������������������������������������������������    51
Analog Interface����������������������������������������������������������������������������������    52
Communication������������������������������������������������������������������������������������    56
2.3 FPGA Structure��������������������������������������������������������������������������������   61
Xilinx FPGA Architecture Overview��������������������������������������������������    61
Altera FPGA Architecture Overview��������������������������������������������������    64
2.4 Case Study: A PSM Called URISC��������������������������������������������������   69
The URISC Processor Model��������������������������������������������������������������    70
Design Compilation in Altera Quartus����������������������������������������������    75
Design Compilation in Xilinx Vivado������������������������������������������������    77
Design Tool Considerations for Simulation����������������������������������������    79
Quartus Floor Planning ��������������������������������������������������������������������    87
Vivado Floor Planning������������������������������������������������������������������������    88
Timing Estimates and Performance Analysis��������������������������������������    88
Review Questions and Exercises ��������������������������������������������������������������   91
Short Answer������������������������������������������������������������������������������������������   91
Fill in the Blank ������������������������������������������������������������������������������������   91
True or False������������������������������������������������������������������������������������������   92
Projects and Challenges ������������������������������������������������������������������������   93
References��������������������������������������������������������������������������������������������������   94
3 Microprocessor Component Design in VHDL��������������������������������������   95
3.1 Introduction��������������������������������������������������������������������������������������   95
3.2 Lexical Elements������������������������������������������������������������������������������   96
3.3 Operators and Assignments��������������������������������������������������������������  100
3.4 Data Types, Data Objects, and Attributes ����������������������������������������  102
VHDL Data Types ������������������������������������������������������������������������������   102
Attributes����������������������������������������������������������������������������������������������   104
Data Objects����������������������������������������������������������������������������������������   105
3.5 VHDL Statements and Design Coding Recommendations��������������  105
Combinational Coding Recommendations������������������������������������������   107
Basic Sequential Circuit Coding: Flip-Flop and Latches��������������������   110
Memory������������������������������������������������������������������������������������������������   111
Finite State Machine����������������������������������������������������������������������������   111
Design Hierarchy and Components ����������������������������������������������������   113
VHDL Coding Style, Resources, and Common Errors ����������������������   114
3.6 Further Readings������������������������������������������������������������������������������  115
Review Questions and Exercises ��������������������������������������������������������������  116
Short Answer����������������������������������������������������������������������������������������   116
Fill in the Blank ����������������������������������������������������������������������������������   118
True or False����������������������������������������������������������������������������������������   118
Projects and Challenges ����������������������������������������������������������������������   120
References��������������������������������������������������������������������������������������������������  126
Contents xiii

4 Microprocessor Component Design in Verilog��������������������������������������  127


4.1 Introduction��������������������������������������������������������������������������������������  127
4.2 Lexical Elements������������������������������������������������������������������������������  128
4.3 Operators and Assignments��������������������������������������������������������������  132
4.4 Data Types and Value Set������������������������������������������������������������������  134
Verilog Values Set��������������������������������������������������������������������������������   134
Verilog Data Types������������������������������������������������������������������������������   134
4.5 Verilog Statements and Design Coding Recommendations��������������  137
Combinational Coding Recommendations������������������������������������������   139
Basic Sequential Circuit Coding: Flip-Flop and Latches��������������������   141
Memory������������������������������������������������������������������������������������������������   142
Finite-State Machine����������������������������������������������������������������������������   144
Design Hierarchy and Components ����������������������������������������������������   145
Verilog Coding Style, Resources, and Common Errors����������������������   146
4.6 Further Reading��������������������������������������������������������������������������������  147
Review Questions and Exercises ��������������������������������������������������������������  148
Short Answer����������������������������������������������������������������������������������������   148
Fill in the Blank ����������������������������������������������������������������������������������   150
True or False����������������������������������������������������������������������������������������   151
Projects and Challenges ����������������������������������������������������������������������   152
References��������������������������������������������������������������������������������������������������  158
5 Microprocessor Programming in C/C++ ����������������������������������������������  159
5.1 Introduction��������������������������������������������������������������������������������������  159
5.2 Lexical Elements������������������������������������������������������������������������������  160
5.3 Data Types, Data Attributes, and Storage Class��������������������������������  165
Basic C Data Types������������������������������������������������������������������������������   165
5.4 C-Operators and Assignments����������������������������������������������������������  168
5.5 Control Flow Constructs ������������������������������������������������������������������  171
5.6 Code Hierarchy and I/O��������������������������������������������������������������������  173
5.7 Additional Considerations and Recommendations��������������������������  178
Debugger Versus Debug Printing��������������������������������������������������������   178
C Versus C++ ��������������������������������������������������������������������������������������   182
Performance Evaluation of Microprocessor Systems��������������������������   183
5.8 Further Readings������������������������������������������������������������������������������  186
Review Questions and Exercises ��������������������������������������������������������������  188
Short Answer����������������������������������������������������������������������������������������   188
Fill in the Blank ����������������������������������������������������������������������������������   189
True or False����������������������������������������������������������������������������������������   190
Projects and Challenges ����������������������������������������������������������������������   191
References��������������������������������������������������������������������������������������������������  194
6 Software Tool for Embedded Microprocessor Systems������������������������  197
6.1 Introduction��������������������������������������������������������������������������������������  197
6.2 Assembler Development and Lexical Analysis��������������������������������  199
6.3 Parser Development��������������������������������������������������������������������������  209
6.4 SW Debugger and Instruction Set Simulator������������������������������������  220
xiv Contents

Review Questions and Exercises ��������������������������������������������������������������  222


Short Answer����������������������������������������������������������������������������������������   222
Fill in the Blank ����������������������������������������������������������������������������������   222
True or False����������������������������������������������������������������������������������������   223
Projects and Challenges ����������������������������������������������������������������������   224
References��������������������������������������������������������������������������������������������������  225
7 Design of the PicoBlaze Softcore Microprocessor������������������������������  227
7.1 Introduction��������������������������������������������������������������������������������������  227
7.2 Overview Kcpsm6 Instruction Set����������������������������������������������������  230
7.3 Initial PicoBlaze Synthesizable Architecture ��������������������������������  233
7.4 PicoBlaze Synthesizable Architecture
with Scratchpad Memory������������������������������������������������������������������  238
7.5 PicoBlaze Synthesizable Architecture with Link Control��������������  241
Review Questions and Exercises ��������������������������������������������������������������  249
Short Answer����������������������������������������������������������������������������������������   249
Fill in the Blank ����������������������������������������������������������������������������������   249
True or False����������������������������������������������������������������������������������������   250
Projects and Challenges ����������������������������������������������������������������������   250
References��������������������������������������������������������������������������������������������������  251
8 Software Tools for the PicoBlaze Softcore Microprocessor��������������  253
8.1 Introduction��������������������������������������������������������������������������������������  253
8.2 The KCPSM6 Assembler������������������������������������������������������������������  254
8.3 Instruction Set Simulator for the PicoBlaze ����������������������������������  257
8.4 C-Compiler for the PicoBlaze��������������������������������������������������������  261
Data Types in Pccomp��������������������������������������������������������������������������   261
Pccomp Operation Support������������������������������������������������������������������   262
Control Flow Options in Pccomp��������������������������������������������������������   264
Functions Call in Pccomp��������������������������������������������������������������������   265
Additional Pccomp Features and Recommendations��������������������������   267
Review Questions and Exercises ��������������������������������������������������������������  268
Short Answer����������������������������������������������������������������������������������������   268
Fill in the Blank ����������������������������������������������������������������������������������   269
True or False����������������������������������������������������������������������������������������   269
Projects and Challenges ����������������������������������������������������������������������   270
References��������������������������������������������������������������������������������������������������  271
9 Altera Nios Embedded Microprocessor������������������������������������������������  273
9.1 Introduction��������������������������������������������������������������������������������������  273
9.2 Top-Down Nios II System Design����������������������������������������������������  276
9.3 Bottom-Up Nios II System Design ��������������������������������������������������  279
9.4 Custom Instruction Nios II System Design��������������������������������������  289
Floating-Point Number Formats and Operations��������������������������������   289
Floating-Point Operations HDL Synthesis������������������������������������������   292
Floating-Point Algorithms Design Example: FECG���������������������������   296
Contents xv

Custom Floating-Point Hardware Options for Nios II������������������������   296


Creation and Integration of Custom Logic Block��������������������������������   300
9.5 Looking Under the Hood: Nios II Instruction Set Architecture��������  311
HDL Implementation and Testing��������������������������������������������������������   319
Synthesis Results for Trisc3n ������������������������������������������������������������   326
Review Questions and Exercises ��������������������������������������������������������������  327
Short Answer����������������������������������������������������������������������������������������   327
Fill in the Blank ����������������������������������������������������������������������������������   328
True or False����������������������������������������������������������������������������������������   328
Projects and Challenges ����������������������������������������������������������������������   329
References��������������������������������������������������������������������������������������������������  336
10 Xilinx MicroBlaze Embedded Microprocessor ��������������������������������  339
10.1 Introduction������������������������������������������������������������������������������������  339
10.2 Top-Down MicroBlaze System Design ��������������������������������������  340
10.3 Bottom-Up MicroBlaze System Design��������������������������������������  342
10.4 Custom Instruction MicroBlaze System Design��������������������������  349
DVI and HDMI Display Options Implementation������������������������������   349
TMDS Encoding and Decoding����������������������������������������������������������   350
HDMI Encoder������������������������������������������������������������������������������������   354
Text Terminals and Font Design����������������������������������������������������������   357
HDMI Encoder in HDL ����������������������������������������������������������������������   361
CIP Interface for HDMI Encoder��������������������������������������������������������   367
Synthesis Results for HDMI Encoder��������������������������������������������������   373
10.5 Looking Under the Hood: MicroBlaze Instruction
Set Architecture������������������������������������������������������������������������������  373
HDL Implementation and Testing��������������������������������������������������������   387
Synthesis Results and ISA Lesson Learned����������������������������������������   395
Review Questions and Exercises ��������������������������������������������������������������  397
Short Answer����������������������������������������������������������������������������������������   397
Fill in the Blank ����������������������������������������������������������������������������������   397
True or False����������������������������������������������������������������������������������������   398
Projects and Challenges ����������������������������������������������������������������������   399
References��������������������������������������������������������������������������������������������������  405
11 ARM Cortex-A9 Embedded Microprocessor����������������������������������������  407
11.1 Introduction������������������������������������������������������������������������������������  407
11.2 Top-Down ARM System Design����������������������������������������������������  408
11.3 Bottom-Up ARM System Design ��������������������������������������������������  414
11.4 Custom Instruction ARM System Design��������������������������������������  420
Bit-Reverse Application Example and Software Implementation ������   420
HDL Design of Bit-Swap CIP ������������������������������������������������������������   422
HW/SW Solution Performance Comparisons��������������������������������������   425
xvi Contents

11.5 Looking Under the Hood: ARMv7 Instruction


Set Architecture������������������������������������������������������������������������������  427
HDL Implementation and Testing��������������������������������������������������������   441
Synthesis Results and Lesson Learned������������������������������������������������   450
Review Questions and Exercises ��������������������������������������������������������������  451
Short Answer����������������������������������������������������������������������������������������   451
Fill in the Blank ����������������������������������������������������������������������������������   451
True or False����������������������������������������������������������������������������������������   452
Projects and Challenges ����������������������������������������������������������������������   453
References��������������������������������������������������������������������������������������������������  460

Appendix A: Verilog Source Code and Xilinx Vivado Simulation��������������  463

Appendix B: Glossary��������������������������������������������������������������������������������������  499

Index������������������������������������������������������������������������������������������������������������������  505

You might also like