当前位置: 首页 > 工具软件 > Cortex lab > 使用案例 >

Lab Assignment #1 – ARM Cortex Familiarization

公冶弘壮
2023-12-01

ARM Cortex作业代做、LEDs留学生作业代写、C/C++程序语言作业代写、代做C/C++实验作业
Lab Assignment #1 – ARM Cortex Familiarization
The main purpose of this lab exercise is to gain some familiarity with the equipment and development
environment we will be using in the lab. The lab consists of five parts enumerated below:
1. Background Information
2. Create an ARM Cortex project in the Monitor
3. Blinking LEDs
4. A Counter
5. Final Discussion
You will not be required to submit any sort of formal lab reports. You will instead by evaluated by
verbal interview with a TA who will ask you some questionsto ensure you have learned the key material
from each lab.
This lab exercise has a mix of activities. Some can be (and SHOULD be) completed before coming to the
lab. Others will require the use of the hardware in the lab and can only be completed there. I STRONGLY
recommend reading through this entire document and completing all the parts identified as Pre-Lab
Preparation
Part 1: Introduction to The Cyclone V
Pre-Lab Preparation
For the labs in this course, we will be working on the “bare metal”. That is to say, we are going to be
writing and debugging programs that run directly on the ARM hardware with very little software in
between. (No operating system, no device drivers, etc.) As such, the best place to start is to explain what
exactly it is that we are working with.
The hardware we will use in the lab is the DE-10 standard platform that you probably remember from
digital logic class. The DE-10 is basically an Altera Cyclone V surrounded by some I/O. The Cyclone V is a
fascinating piece of electronics. It has the following basic structure:
2 ECE 3375b-Lab Assignment 1
Basically, it has two interconnected halves. One half, which Altera calls the HPC (stands for “hard
processor core”) is an ARM Cortex A9 microcontroller. That’s all it is, and all it can ever be. The other half
is an FPGA, and it is as reconfigurable as any other FPGA.
Then there’s the ARM-FPGA-bridge. This is a programmable set of interconnects that allows you to map
the FPGA into the ARM’s memory space. What this means is that you can essentially add functionality to
the microcontroller almost at will, limited only by the resources in the FPGA. If there’s a peripheral device
the ARM Cortex A9 doesn’t have, you can make it, put it into the FPGA and map it into the ARM using the
bridge, then control it using software written for ARM.
Needless to say, this is REALLY, REALLY COOL. However, it is also really, really complicated. In order to
program the processor, you must first program the FPGA. In essence, you have to first tell the device how
to configure itself, THEN you can download a “preloader”, THEN you can download application software.
Here’s the GOOD NEWS. You CAN take advantage of these features for the purposes of the design project
later in the course, if you want to do that. However, you don’t actually HAVE to do any it, because Altera
has made available a piece of software called the Intel FPGA Monitor. (Intel bought Altera about two
years ago, but they kept the Altera brand, so the names of things are sometimes not what you think they
will be). The Monitor makes all of the above simple, in practice.
Part 2 – Welcome to the Intel FPGA Monitor
Introduction
When working with a new microcontroller, once you can light up a single LED, you can do anything.
In this section, we will create a simple project in the Monitor to make one of the LEDs on the DE-10 board
to blink.
Pre-lab Preparation
This part of the lab requires the hardware and software setup in the lab. As such, there is very little
pre-lab preparation to be done for this part.
The Monitor seems not to like long complicated path names. As such, I recommend that you create a
folder on your H:\ drive with a short, simple name for use with the labs in the course. In my case, I am
using C:\DE10 as the root directory of all my work. I will assume you are going to use H:\DE10.
So, step one is to create the new folder H:\DE10. Within it, put a subfolder H:\DE10\Lab1. Then, from
the OWL site, download the files Lab1Part1.c and address_map_arm.h. That’s it! You are ready to go.
Creating the Project
Once you get to the lab, open the Intel FPGA Monitor. The easiest way is to double-click the
icon on the desktop, which looks like this:
3 ECE 3375b-Lab Assignment 1
When you open it, it will bring you to the main screen of the Monitor:
The Monitor’s documentation says that it includes a text editor, but at least on my computer, that function
is disabled. You will have to use your favorite text editor to actually write the code. The other windows
you can see provide debugging functionality.
So, let’s create our first project. On the File menu, pick New Project. You will get this window:
4 ECE 3375b-Lab Assignment 1
Choose your H:\DE10\Lab1 directory as the project directory and give the project a simple name. For
Architecture you will choose ARM Cortex-A9. You should now have this:
5 ECE 3375b-Lab Assignment 1
Pick Next. The next window allows you to specify the “system”. (This step takes care of all that FPGA and
FPGA-bridge configuration we discussed above.) For this lab, we will be using the default DE-10
configuration, so you will choose DE10-Standard Computer. The other windows should immediately
populate with path information to the FPGA configuration so you have this:
Click Next. Now you have a chance to specify your programming language. We will be using C to write
these programs, so pick C. Leave the box about using a sample program unchecked.
The next window allows you to add C files to your project. The Monitor will make you a Makefile that
knows how to compile and link all your files. For the purposes of this lab, we need only one file, which is
the Lab1Part1.c file that we downloaded above. Add that file to the project, so you should have this
window:
6 ECE 3375b-Lab Assignment 1
From now on, we are going to accept defaults, so click Next until it is grayed. You should be at this
window:
7 ECE 3375b-Lab Assignment 1
OK! We are ready to go! Click Save. This will create the project and start your debugging session. You
will get the following prompt:
As it asks you to do, make sure there is power to the DE-10 board, then click Yes. Things will happen.
Lights will turn on and off. The LCD backlight might come on. You will see text in the Info & Errors window.
On my computer, this step takes a fairly long time. It might be faster in the lab. Eventually, it will tell you
this:
Congratulations! You have created a project and are ready to go.
Part 3 – Getting to know the Monitor
Introduction
The purpose of this section is to let you try out some of the things the Monitor can do, and experiment
with making simple program changes.
Pre-lab Preparation
For this step, none.
Working with the DE-10
At the end of Part 2, we had created a project and configured the board. However, we have not yet
done anything. In fact, I expect the Disassembly window in the Monitor is still blank. To fix that, we need
to Load a program. On the Actions menu, choose Compile & Load.
You can watch the Info & Errors window to see the progress of this activity. In this case, the program will
compile without errors, but if compilation errors were to occur, that’s where you’d see them. Once again,
the Load process might take a non-trivial amount of time. Once it is done, the monitor will be much more
interesting. Here’s what it looks like for me:
8 ECE 3375b-Lab Assignment 1
What you are seeing in the Disassembly window is an assembly language program, reconstructed from
the contents of the ARM’s memory. The Monitor knows your “symbol table” (all the names of your
functions, subroutines, variables and other labels), so it can turn the disassembly into something very
nearly readable.
On the right, you will see the Registers window. That is the actual register contents of the ARM processor
at this moment. If you look at the top of the Registers window, for example, you will see that the first
register listed is the program counter pc. pc's contents in the example (and probably the same for you)
are 0x00000128. Not coincidentally, that is the address of the first instruction the compiler put into your
program. It is also the address of the highlighted line of disassembled code in the Disassembly window.
OK! Let’s see some blinking lights. Press Continue (it looks like ). An LED should blink. It is probably
blinking for you at a frequency of roughly 2Hz. (That is, it turns on about once every half second.) If you
get bored of looking at it, you can push Break ( ) and it will stop.
Also, when you press Break, you will find yourself now in the program. The Monitor is smart enough to
put the disassembled code reconstructed from the memory contents in line with the source. What this
means is that you can see the lines of the original C program interspersed with the assembly code the
compiler has generated. The two versions of the program look less and less similar with more compiler
9 ECE 3375b-Lab Assignment 1
minimization, but the default setting is to keep them looking pretty much the same, to help you with
debugging. Almost certainly, you are somewhere in the delay loop, as I am in the following image:
For reference, here’s the entire C program:
10 ECE 3375b-Lab Assignment 1
Now, let’s do some stuff. A very useful function is single step debugging. Step looks like this: and it
will cause the program counter to advance by one assembly instruction (that is, NOT one line of C-code).
What I want to do next is step out of the loop. Press single step a few times and you can watch the
program counter chase its way around the loop.
Wow. That’s boring. In my case, the loop still has 0xFD37 times to run (that’s roughly 65000 times). You
will probably see a different number, but it’s probably still big. Fortunately, you are all powerful, and
there is a better way!
Step to the instruction where the loop test occurs. In the Registers window, change the register value so
the loop will terminate. You can change a register value just by double clicking and typing a new value.
So that’s a useful trick. What else can we do? Well, suppose you decide you don’t like the length of the
delay loop and you’d like it to be slower. Of course, we can re-compile and download again, but we can
also change the behaviour at run time. Click the Memory tab under the main window. You will get
something like this:
That is the actual memory contents of the ARM’s RAM. And you can change if you want to. Go back to
the disassembly and figure out the address that has been assigned to the variable DELAY_LENGTH. (Hint:
you will see this variable read at the beginning of the loop, as well as being assigned at the beginning of
the program.) Type the address into the Goto address window of the Memory window. You will see
something like this, though of course in your case the addresses won’t be blanked out.
11 ECE 3375b-Lab Assignment 1
The value initialized to DELAY_LENGTH is 700,000, which is AAE60. I have circled it. Unfortunately, the
ARM’s endian-ness means that it is kind of hard to read. Fortunately, if you right click, you have the choice
to view the data as Byte (1-byte), Half-word (2-bytes) or Word (4-bytes). Put it into Word (4-bytes) mode,
and the number is much easier to read. The right-click popup menu also gives you the option to choose
Number format. If you choose Decimal, then 700,000 becomes very easy to see. Now, change it to
something else and watch the blink rate change as you vary the number.
Here’s one more useful debugger feature before we move on to writing our own program. Go back to the
Disassembly window and click in the gray margin along the left hand side. A red dot should appear. This
is a Breakpoint. Execution will immediately halt if the program counter gets to that location in the
program memory.
Evaluation
The TAs will interview you and ask you to demonstrate some simple changes to the registers and
memory.
Part 4 – Our first program
Introduction and Background
Now it is time for you to do something. What I would like to do is use the lowest order four slide
switches to control the hex character displayed on the seven segment display. For this we need some
information.
The slide switches are memory mapped to address 0xFF200040 (called SW_BASE in
address_map_arm.h).
The lower order four seven segment displays are mapped to address 0xFF200020 (called
HEX3_HEX0_BASE in address_map_arm.h).
The wiring of port I/O bits to segments in the seven segment display is as in the following diagram:
12 ECE 3375b-Lab Assignment 1
Pre-Lab Preparation
I STRONGLY RECOMMEND that you develop the basic program required as pre-lab work, then devote
time in lab to testing and debugging. Your program must have the following features:
1) A function int ReadSwitches(void) that reads the slide switch bank and returns the current value,
encoded as a binary number.
2) A function void DisplayHex(int value) that shows the hex equivalent of value on the lowest-order
seven segment display. The easiest way to do this is with a look-up table (array) of values
corresponding to the LEDs you want to light up to show a specific value. For example, if you want
to display “1”, you want to turn on LED segments 1&2 in the picture. So your array would contain
the following (among other things):
lookUpTable[1]=0x06;
3) A main routine that blinks the lowest seven segment display ON and OFF. When ON, it should
display the hex equivalent of the four-bit number encoded by the lowest four bits of the slide
switch bank and this value should update as you change the switch positions. You can use the
same delay loop from Part 1 to time the blinking.
You will want to create a new project for Part 2. I have provided a stub Lab1Part2.c file that you can
populate with this code. You should follow all the same steps for project creation as we used in Part 1,
except that now you will use the new source file.
Lab Component
Test and demonstrate that your program works as expected.
Evaluation
The TAs will verify the performance of your program and interview you to establish your
understanding of the program you have written. In particular you should be prepared to answer questions
related to the behaviour of the program at and around the call to the functions. (How is the parameter
passed? How is the return value passed? How is the return address saved? Etc.)
13 ECE 3375b-Lab Assignment 1
Part 5 – Discussion
Finally, I like to invite you to think about the experience of the lab. Was it worthwhile? Did you learn
anything? Can you see ways to apply what you have learned? Did you have problems with the
development environment? Was the lab too easy? Too difficult? Too long?
You do not have to submit anything at this time. However, I will be asking you to submit a document
towards the end of the semester summarizing your reaction to the labs as a whole, so making some notes
now while it is fresh in your memory is a good idea.

 

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:99515681@qq.com 

微信:codinghelp

转载于:https://www.cnblogs.com/bbbaaa/p/10376644.html

 类似资料: