ECEN3000/3360 - Digital Design Lab
Lab 2: Understanding How the Arm Cortex M0 Actually Works
2 lab periods
Figure 1. The
LPCXpresso LPC1114 board.
In the previous lab, we learned how to use the Arm Cortex M0 to
do some work for us--specifically, we made a digital oscilloscope,
and with less than $5 in parts (1 microprocessor, 1 oscillator, 1
resistor, 6 capacitors, and an LED). In doing so, we learned
how an embedded software IDE is used and got a feel for some of
the capability available to us through such a platform. So,
now that we are able to use it we can do some pretty powerful
things, but without knowing how our code is working underneath we
will always be limited in what we can do.
For the pre-lab, write a function in C which implements a look-up
style table to convert a single digit integer 0-9 into it's Morse
code equivalent, with 1 being long and 0 being short. This will be
similar to the code needed as part of the translateFib function
You must implement this without enumerating all possibilities
using if and else statements (Hint: Look into structures and
and Structure examples)
Print out and hand in the code for the function, one per group.
It will be collected at the beginning of lab on Tuesday and don't
forget there will also be a quiz!
Figure 2. The Code Red debugging environment (see
Section 4.1.2 of the Code Red getting started manual).
- Core Register View:
This shows all of the registers in the processor
core. Registers that have changed from step to
highlighted in yellow.
- Debug View:
This shows you the stack trace and the debug
toolbar. Using the icons at the top of the view,
you can step through
code or execute at full speed. In the ‘stopped’
state, you can click on any particular function
and inspect its local variables in the
right hand panel on the Variables tab.
- Editor: In
here you will see the code you are executing and
can step from line to line. By pressing the ‘i’
icon at the top of the
Debug view, you can switch to stepping by assembly
instruction. Clicking in the left margin will set
and delete breakpoints.
- Console View:
On the lower right is the Console View. The
Console View displays status information on
compiling and debugging,
as well as program output.
- Quick Start View:
Below, the ‘Quick Start’ view has fast links to
commonly used features. This is the best place to
go to find
options such as Build, Debug, and Import.
Part 2 (The "asm_sum_cm0.s" example)
- Download and import
the inline assembly example project here. This project is
written mainly in C, but calls a subroutine written purely in
assembly. Such a configuration is ideal when an especially
critical section of code must be ensured to execute as
efficiently as possible.
- Run the project on the board. Important(!): you will want to step
through the asm_sum_m0.s subroutine line-by-line, paying
particular attention as to how the data values change in both
the registers and in memory. Gaining a real understanding
of what is happening is essential
for being able to write our own assembly in the second
portion of this lab.
- Lab Questions:
- What happens to the stack pointer when the subroutine is
called in the main.c file (view the disassembly)? What
hex values are placed on the stack by the push instruction in
asm_sum_cm0.s? What do these hex values represent?
- How are the subroutine arguments (asm_sum(5, 6)) passed to a subroutine
when it is called? Where are they stored?
- How can you tell by looking only at the asm_sum_cm0.s file
that it will require two arguments?
- View the disassembly for the "sum(int x, int y)"
subroutine. At what hex instruction address does the
actual addition of x and y take place? There are two
"adds" instructions, what is the purpose of the other adds
Part 3 (The Fibonacci-driven Morse Code Generator)
For this lab portion, we will be leveraging all the knowledge you
have learned over the past 2 weeks into one assignment--C
programming, assembly programming, and Arm peripheral
control. Since we are covering so much, you will want to get
started as early as possible to make sure it works by the
end-of-lab deadline by next Tuesday. Specifically, you will
be writing a program that recursively generates Fibonacci numbers
based on an always incrementing Fibonacci index n that is in the range
[1,20], translate that number into it's Morse Code equivalent of
short and long pulses, and display those pulses in an easy to read
duration using the LED.
- Write the bulk of your project in C
- int fibonacci(int
- Style: recursion
- Input: the Index
n, more specifically, f(0) = 0; f(1)=1; f(n)= f(n-1) + f(n-2) if n <= 10; and f(n)=f(n-1) - f(n-2) if n > 10
- Output: the
Fibonacci Number, seen also in Table 1
- int translateFib(int
C is fine, but assembly is also allowed
- Style: look up
table is probably most suitable
- Input: fibNum
holds the value of the Fibonacci number corresponding to
the supplied index
- Output: The
bit-encoding for a Morse Code signal that represents the
four hex characters of your Fibonacci Number (there are
four hex characters in a 32-bit number; e.g. 0xFFFF has
- A '1' equals a long Morse Code pulse (equal to 3 short
- A '0' equals a short Morse Code pulse (you decide an
appropriate length for this, using the timer)
- Example: Index
the Fibonacci Number 6765. In hex, this number is
- Using this table,
you would output 1: as 01111; then A: 01; then 6:
10000; and finally D: 100; before computing the next
Fibonacci Number to output
- Treat each of these as separate integers,
zero-padding from the MSB side (use any convention
that you feel is appropriate)
- int main(void)
- GPIO, Timer, etc. initialization code (maybe use an
example project as your base)
- Within the a while(1) loop, cycle your index n from 1 to 20 and
repeat (you can try numbers larger than 20--don't go
higher than 46(!!!), but be aware they will take longer
and longer to do the computation
- At each increment of n,
calculate the Fibonacci number for it, and translate that
number into the binary signal to turn the LED on or off
according to the Morse Code equivalent for its hex value
- Delay the LED on/off period such that we can watch the
Morse Code values as they appear
Fibonacci and Morse Code Information