Lecture #2 1
EE251: Introduction to Microprocessors
• Thursday, August 24
• Flip-Flops and Sequential Circuits
• Components of a Microcontroller
• Register Model
• Read: Chapter 3 (3.3 is C and not required)
• Labs: Started this week! Lab 1 due next week.
– Note, Lab 2 starts next week and will be due two weeks
later (week of Sept. 11). Prework is due at beginning
of your Lab 2, so get started on it!
• Homework: #1 Due Sept. 7, 4 p.m. Check web page.
Just for Fun Again
Lecture #2 2
Lecture #2 3
Important Resources for ECE251
Embedded Systems: Introduction to ARM Cortex-M
Microcontrollers, Jonathan Valvano, On reserve in Morgan
Embedded Systems: Real Time Interfacing to ARM Cortex-M
Microcontrollers, Jonathan Valvano. On reserve in Morgan
The Definitive Guide to Arm Cortex-M3 and Cortex-M4 Processors,
Joseph Yiu. See instructor.
ARM Microprocessor Systems, Tahir and Javed. See instructor.
Tiva TM4C123GH6PM Microcontroller Data Sheet (1409 pages)
Various other Reference Manuals, User Guides, and web page
references that can sometimes be helpful: found on ECE251 main
website.
Check the ECE251 website regularly to find more helpful
resources for the course.
Lecture #1 4
Flip-Flops
A key memory device in microprocessors is the flip-flop.
Remember: Flip-flops are clocked. Latches are not. Computers
use clocked circuits => flip-flops.
For example, a J-K flip-flop is shown as:
When do the outputs of the flip-flop above change? __________________
How can you tell?
In microprocessors, flip-flops are typically grouped together with common
control signals into registers.
K
Clk
J
Q’ Q
Lecture #1 5
Memory
Another common subsystem in microprocessors is MEMORY, with
multiple address lines and multiple data lines:
The above has N address lines and M data lines. The capacity of this
memory system is _________ bits.
Why the power of 2 for addresses, but not data?
a0
a1
aN-1
d0 d1 . . . dM-1
Read/Write
Clk
.
.
.
Lecture #1 6
Sequential Circuits
Sequential circuits are logic circuits with memory (state), including
registers and/or memory cells
What kind of sequential circuit have I drawn? ______________________
Hint: What are the two types, and what is the difference between them?
In
Memory
Output
Sn+1 Sn Next State
Logic
Output
Logic
Clk
Lecture #1 7
Sequential Circuits continued
Another type of sequential circuit:
What kind of sequential circuit is this? ______________________
Hint: Outputs do not depend on inputs.
This is (almost) universally the kind of sequential circuits used in real
computer systems. Why?
In
Memory
Output
Sn+1 Sn
Next State
Logic
Clk
Output
Logic
Lecture #2 8
State Transition Diagrams
State
Output
Input Next State
Output
Moore
State
Input
Output Next State
Mealy
Lecture #2 9
New Content: Computer Block Diagrams
Instructions and data are
stored in the same memory.
Von-Neumann Harvard – e.g. ARM Instructions and data are
stored in separate memories.
Lecture #2 10
Features of the ARM Cortex M4 Microcontroller (Specifically the TM4C123GH6PM that we’ll be using)
- 32-bit CPU (32 bit wide registers and address path)
- 80 MHz max internal clock
- 4 GBytes memory space (232 = 22230 = 4230 = 4G where G = 230 = 1,073,741,824)
- 32 kBytes of on-chip RAM
- 2 kBytes of flash EEPROM memory
- 256 kBytes of Flash memory
- SysTick Real-Time Clock
- Sophisticated timer functions that include: input capture, pulse output, …
- Serial communication interfaces: SCI, SPI, CAN, …
- 2 12-bit A/D converters with max sample rate of 1 million samples per second
- and lots, lots more…
- Don’t panic! This is just an overview. We have a whole semester
to understand its key functionality.
Lecture #2 11
TM4C123GH6MP Block Diagram
So, where
is the CPU?
Lecture #2 12
TM4C123GH6MP Block Diagram
CPU
Lecture #2 13
Embedded System
- A product that uses one or more microcontrollers as
controller(s). Also called an embedded product.
- End users are interested in the functionality of the
product, not the microcontroller itself.
- Cell phones, home security systems, and modern
automobiles are examples of embedded products.
Others you know of?
Lecture #2 14
Samsung Gear Fit Fitness Tracker
STMicroelectronics STM32F439ZI 180
MHz, 32 bit ARM Cortex-M4 CPU
Lecture #2 15
The A6 processor is the first
Apple System-on-Chip (SoC)
to use a custom design,
based off the ARMv7
instruction set. It is a
predecessor to the ARM
Cortex-M4 we’ll be using.
This is an iPhone 4. What
processor does the iPhone
4 use?
iPhone 4 Teardown
Lecture #2 16
Semiconductor Memory - Random access memory (RAM): same amount of time is
required to access any location on the same chip. Read/write.
- Read-only memory (ROM): can only be read; cannot be
written to directly by the processor
Random Access Memory - Dynamic Random Access Memory (DRAM): periodic
refresh is required to maintain the contents of a DRAM chip
- Static Random Access Memory (SRAM): no periodic
refresh is required. Always more predictable and usually
faster than DRAM.
- So what the heck is an SDRAM, used nowadays?
Read-Only Memory - Mask-programmed read-only memory (MROM):
programmed when being manufactured
- Programmable read-only memory (PROM): the memory
chip can be programmed by the end user
Lecture #2 17
Erasable Programmable ROM (EPROM)
1. Electrically programmable many times
2. Erased by ultraviolet light (through a window)
3. Erasable in bulk (whole chip in one erasure operation)
Electrically Erasable Programmable ROM (EEPROM) 1. Electrically programmable many times
2. Electrically erasable many times
3. Can be erased one location, one row, or whole chip in one operation
Flash Memory 1. Electrically programmable many times
2. Electrically erasable many times
3. Can only be erased in bulk
Lecture #2 18
Computer Software - Computer programs (programs) are known as software
- A program is a sequence of instructions
Machine Instruction - A sequence of binary digits that can be executed by the processor
- Hard to understand, program, and debug for human being
- E.g. in the ARM Cortex M4, instruction 0010 0010 0110 0100 puts the
number 100 in register #2. How many bytes long is this instruction?
- OK, the instruction is also 0x2264. Does that help much? What is 0x64
in base 10?
So what might 0x22 be? That’s 0010 0010 or 00100 010. OK, 001002 is move
immediate and 0102 is register #2. QED
Assembly Language - Defined by machine instructions
- An assembly instruction is a mnemonic representation of a machine instruction, e.g. ADD represents a register add (0001100…)
- Assembly programs must be translated to binary before it can be executed:
Assembler does this translation: ADD R2 R1 R0 0001100 010 001 000 = 0x1888
- In this course we’ll be dealing with Assembly Language almost exclusively.
Lecture #2 19
High-level Language
- Syntax of a high-level language is similar to English
- A translator is required to translate the program written in a
high-level language -- done by a compiler
- High-level languages allow the user to work on the program logic
at a more conceptual level (e.g. you don’t have to worry about
what’s in register R2).
- Our textbook uses some C language examples, which are helpful if
you understand C, but is not necessary to this course.
Source Code
- A program written in assembly or high-level language
Object Code
- The output of an assembler or compiler--machine instructions
and data in binary (ones and zeroes) form.
Lecture #2 20
So Why Use Assembly Language in 251?
Writing software in a higher level language is more “efficient”
Employers want new engineers who are good with higher level
language coding
BUT
The goal of ECE251 is understanding how processors work,
not writing large programs to do complex tasks
Assembly Language is a readable version of the instructions the
processor understands
Programming things like register bit manipulation is actually more
straightforward in assembly language than in a high level
language (arguable point, but we aren’t going to argue about it!)
Employers also usually prefer engineers who understand well the
inner workings of the computers they are using
Lecture #2 21
ARM Cortex-M4 Registers
This is important!
Learn it!
Lecture #2 23
Memory Addressing
- Memory consists of a sequence of directly addressable locations.
- A location is referred to as an information unit.
- A memory location can be used to store data and instructions.
- A memory location has two components: an address and its contents.
We will represent number bases with these prefixes
Base
binary
octal
decimal
hexadecimal or hex
Prefix Example
0b
@
$
0b10001010
@1234567
12345678
0x5678
Contents Address
The components of a memory location
0x
Lecture #2 24
Data transfers between the CPU and the memory are done over the
common buses: address bus and data bus.
Notations: [addr] represents the contents of a memory location,
[register name] refers to the contents of the specified register.
E.g. [0x20] refers to the contents of memory location at address 0x20, i.e. at address 32.
E.g. [R1] refers to the contents of register R1; similarly with other registers.
Value Address means that the data value “Value” is stored at memory or register
address “Address”. E.g. 0x20 R1 means that the value 0x20 is placed in register R1.
What does 0xAB 0x2000 mean?
Transferring Data between CPU and Memory
Lecture #2 25
Operation of a Computer (see Section 1.4 in text)
Computers execute programs instruction-by-instruction. Let’s look at the execution of
instructions in detail:
0. Program counter register PC “points to” (i.e. contains the address of) the memory
location containing the next instruction to be executed. This counter will be updated to
“point to” the following instruction during or after execution of the current instruction.
1. Instruction Fetch: Using the current value of PC, read the next instruction to execute
from memory. Store this data in the instruction register, IR. That is: [[PC]] IR
PC is the name of the register;
[PC] is the address of the instruction to be executed;
[[PC]] is the instruction itself, contained at the memory address [PC].
Note that IR is an internal register, not accessible with computer instructions.
2. Decode Instruction: Determine which instruction is to be executed using the
contents of the IR.
3. Execute Instruction: Activate appropriate control lines in processor sequentially to
perform the action specified by the Instruction at particular clock ticks. This is a
classic Moore machine operation.
Let’s go over a simple example on the next slide.
Lecture #2 26
Instruction Execution Example
Let’s execute the instruction ADD R4,R3,R0 and assume this instruction begins at
address 0x1000. This instruction means: add contents of register R0 to the contents of
register R3, and store the results into register R4. Here’s what happens:
1. Fetch instruction (read) from memory addresses 0x1000 and 0x1001. The contents
of these are the computer’s bit pattern for ‘ADD R4,R3,R0’. Store these 16 bits in
instruction register, IR.
2. Decode the instruction in IR. Determine that it is the ADD instruction.
3. Connect register R0 to input 1 of the ALU.
4. Connect register R3 to input 2 of the ALU.
5. Set controls to ALU to do a 32-bit add operation.
6. Store the outputs of the ALU into register R4.
7. Increment the program counter and store that value back in the program counter:
[PC] + 2 PC. Why 2? This operation can (does) actually occur after step 1, in parallel
with steps 2-6. Why?
8. Go back to step 1, using the new value of PC. This can occur during steps 3-6. Why?
See a more complete example in Sections 1.4.2-1.4.3 in text.
Understand this example!
Lecture #2 27
Questions?
Next Lecture: Moving Data From Memory (load)
and To Memory (store) with ARM
These are basic concepts we’ll use throughout
the semester. Understand them!
Read Chapter 5 in text (Load and Store)
Lab 2 is next week. Do prework beforehand.