IntroSoC Lab04
IntroSoC Lab04
IntroSoC Lab04
LAB 4
Cortex M0 and AHB-lite implementation
Issue 1.0
Contents
1 Introduction..............................................................................................1
1.1 Lab overview..........................................................................................................................1
1.1.1 Part 1: Hardware implementation:................................................................................1
1.1.2 Part 2: Software programming.......................................................................................1
2 Learning Objectives...................................................................................1
3 Requirements...........................................................................................2
4 Project files...............................................................................................2
5 Hardware..................................................................................................3
5.1 Overview of the SoC hardware..............................................................................................3
5.1.1 Arm Cortex-M0 microprocessor.....................................................................................3
5.1.2 On-chip program memory:............................................................................................3
5.1.3 LED peripheral................................................................................................................4
5.2 Implementing the System-on-Chip........................................................................................4
7 Hardware Debugging................................................................................7
7.1 Hardware logic simulation.....................................................................................................7
7.2 On-chip debugging.................................................................................................................7
8 Extension work.........................................................................................8
8.1 Extra tasks for this lab:...........................................................................................................8
1 Introduction
1.1 Lab overview
In this lab, we will begin designing a simple SoC platform that contains a Cortex-M0 microprocessor,
an LED peripheral, and an on-chip memory. The Cortex-M0 can be downloaded from the DesignStart
webpage found in https://developer.arm.com/ip-products/designstart/eval.
You will learn how to integrate the processor and other peripherals into a system using the AHB-Lite
bus interconnect and write/modify assembly programs to control the peripheral. This lab is divided
into two parts as shown below
2 Learning Objectives
At the end of this lab, you should be able to:
Implement a simple SoC which consist of Cortex-M0 processor, AHB-Lite bus and AHB
peripherals (Program memory and LED) on an FPGA.
Modify and compile a simple assembly program using Keil to control the LED.
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 1
3 Requirements
This lab requires the following hardware and software:
Hardware:
o Diligent BASYS 3 FPGA board connected to computer via MicroUSB cable. A
constraints file for this board is also provided.
Software
o Xilinx Vivado
Xilinx Vivado.
This lab was tested using Vivado 2019.1. The tcl script provided to
auto add the compiled program to the generated bitstream works
with this version.
The tcl scripts may not work with later versions of Vivado. In this case,
you will need to rerun synthesis, implementation and bitstream
generation when a new code.hex file is generated due to change
made to the program.
o Keil uVision
4 Project files
The following files are provided/needed for this Lab:
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 2
5 Hardware
In this task, you will implement the Cortex-M0 processor core, AHB-lite bus, memory and LED
peripheral on an FPGA board.
The Cortex-M0 DesignStart has almost the same functionality of an industry-standard Cortex-M0
processor, except that some features are reduced, e.g., the number of interrupts is reduced from the
original 32 to 16 interrupts.
Normally, to load your program into the on-chip memory of an FPGA, the program image needs to
be merged into your hardware design during synthesis. For example, if you need to preload a
program file into the hardware, the program file (e.g., “code.hex”) needs to be referred to in your
Verilog code, using syntax such as:
initial begin
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 3
$readmemh("code.hex", memory);
end
However, this approach requires complete regeneration of the bitstream for minor changes in code,
which can be very time-consuming for larger designs. In the labs for this course, we have provided a
post-implementation tcl script which merges the program code to the bitstream. This method is
much quicker for simple testing of different program images and the process will be described later.
1. In the Add Constraints page click create new file and name it basys_3_constraints.
2. On the Device screen chose XC7A35Tcpg236-1
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 4
Hierarchy of files in complete project should look like this:
Run synthesis, implementation and generate bitstream if you are using Vivado 2019.1. You can also
connect a board now but note that there is no program in a memory yet!
Our next step will be to compile an assembly code and merge it with the generated bitstream
(effectively putting it in the memory in the already generated bitstream file in Vivado).
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 5
Initialize the interrupt vector.
In the reset handler, repeat the following:
o Turn on half of the 8-bit LEDs, e.g., LED [0, 2, 4, 6].
o Set a counter and use it to delay for a short time.
o Turn on the other half of the LEDs, e.g., LED [1, 3, 5, 7].
o Delay for another period.
A working code in cm0dsasm.s has been provided with this lab. Study the code in the file. Check
each label (Reset_Handler, AGAIN, Loop and Loop1) and study the corresponding code. Note the
register calling convention and how the instructions are used.
Once you have created/added an assembly program (please see Section 3.4 in the getting Started
Guide), compile it into .hex file (please see Section 3.5 in the getting Started Guide).
On the Tcl Console Ensure you are in the Vivado working directory
The command “source update_bitstream.tcl” should be called from the project directory in the TCL
console using following commands:
source update_bitstream.tcl
The new bitstream is saved as reflash.bit. After it is generated, this file should be found exist
in the project directory.
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 6
7 Hardware Debugging
7.1 Hardware logic simulation
Before downloading the hardware to the FPGA, we can use hardware simulation tools to analyze the
system behaviour, such as MentorGraphic ModelSim and Xilinx Isim.
The simulation tool allows you to analyze a set of signals. The suggested signals are:
HADDR[31:0]
HWDATA[31:0]
HRDATA[31:0]
HWRITE
HREADY
HSIZE[2:0]
HTRANS[1:0]
HRESP
To sample the signals at run-time, on-chip debugging tools are required, for example, ChipScope
from Xilinx and SignalTap from Altera.
HADDR[31:0]
HWDATA[31:0]
HRDATA[31:0]
HWRITE
HREADY
HSIZE[2:0]
HTRANS[1:0]
HRESP
The on-chip debugging tool will also be useful in the following developments of hardware
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 7
8 Extension work
8.1 Extra tasks for this lab:
Add additional registers to the LED peripheral. For example, add a mask register that can
mask out certain bits when writing the LEDs.
Add another peripheral “AHB switch” to input the status of the 8-bit switches. For example,
use the switch to control the LEDs.
Copyright © 07/05/23 Arm Limited (or its affiliates). All rights reserved.
Page 8