2021 CoE2DX4 W0

You might also like

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

Computer

Engineering
2DX4
Embedded Architecture &
The Cortex-M4

Week 0

mcmaster.ca |
Welcome to 2DX4

https://starwarsintrocreator.kassellabs.io/

mcmaster.ca | 2
Instructors

Dr. Thomas Dr. Yaser Dr. Shahram


Doyle Haddara Shirani

For contact details, please see the course outline.

mcmaster.ca | 3
How Does This “Simple” Droid Work?
Specifically, from a Computer Engineer’s point of view, discuss how this system:
• Observes the world around it?
• Makes decisions?
• Actuates commands?

mcmaster.ca | 4
How Does Weather Information Get Collected?
The following map from www.wunderground.com has Hamilton and surrounding area weather
information provided in real-time (temperature, wind direction, and air quality shown). How is this
accomplished?

https://www.wunderground.com/

mcmaster.ca | 5
What Makes a System “Intelligent”?
Architecture vs. Characteristics

• Embedded micro systems have traditionally been taught from the perspective of the
computer architecture and their intelligent nature was derived from those capabilities.
• 2DX4 has been structured to teach the course content from the perspective of what makes
an embedded computing system intelligent.
• An intelligent micro system has three properties:
o Observe – an intelligent system can observe the world around it.
o Reason – an intelligent system can make decisions based upon the observed world
around it.
o Action – an intelligent system can interact with the world around it.

• The course is structured around the properties of an intelligent system.

mcmaster.ca | 6
Introduction Observe

Week 3:
Week 0: Week 1: Week 2:
Timing, I/O, &
Embedded Systems & Signals Around Us Transduction & Analog
Structured Program
Architecture (Digital & Analog) Signal Acquisition
Organization

Reason
Course Organization Week 4:
Week 5: Week 6:

Implementing Signal System Integration &


Peripherals
Transfer Functions & Abstract Data Types
Calibration

Act Overview

Week 7:
Week 8: Week A & B:
Week 9:
Event Based
Communication Embedded Systems &
Programming & Data Visualization
Protocols Architecture + Overview
Interrupts

mcmaster.ca | 7
Course Organization
2DX4 is structured into three core themes: Observe, Reason, and Act. Each theme
is stitched together with knowledge threads. The block flow diagram on the right
illustrates how each thread is structured.

Knowledge
Thread
Block Flow
Lab Prep

mcmaster.ca | 8
Introduction
The Texas Instrument
MSP-EXP432E401Y
LaunchPad

mcmaster.ca | 9
Course Materials
Please review carefully
Required:
Textbook: Valvano, “Embedded Systems: Introduction to ARM Cortex-M Microcontrollers”, 5th edition, 6th printing,
January 2019. Please note the edition, printing, and date! (A Kindle* digital version may be available via Amazon
– confirm version before purchase)
Hardware: A course hardware kit will be required. Information about the kit and purchase procedure will be
available on Avenue.
Software: A free Integrated Development Environment (IDE) will be used for this course. Refer to the course
website for information on obtaining the software.

Optional:
Textbook: Valvano, “Embedded Systems: Real-Time Interfacing to ARM Cortex-M Microcontrollers”, 5th edition,
6th printing, December 2017. Please note the edition, printing, and date! (A Kindle digital version may be
available via Amazon – confirm version before purchase)
*Kindle does not require a hardware
reader. Kindle documents can be
Calculator: None required. Not permitted on exams. read using free software and/or
online.

mcmaster.ca | 10
Frequently Asked Questions
Answers to common questions at the beginning of 2DX4

• Do I need the textbook? Yes


• Do I need the Micro & Hardware kit? Yes – do not buy used equipment because
this is the first year for this micro and hardware kit.
• Can I share the Micro & Hardware kit? Towards the end of the course you will
need more time to work on your device because the project is customized for
each student, our opinion is it is unwise to share a development platform whereby
its failure/configuration could impact your final grade.
• I failed a pre-requisite, can I still take 2DX4? See your instructor -- you may be
invited for an interview.
• I previously failed 2DP4, can I be exempt from labs? No, this is a new course
that is different from 2DP4. See your instructor ASAP to ensure you’re enrolled in
correct course.

mcmaster.ca | 11
Frequently Asked Questions (cont.)

• I previously failed 2DP4, can I be exempt from project? No. See your
instructor ASAP to ensure you’re enrolled in correct course.
• I took 2DI4 x-years ago, do I really need to know it? Yes. 2DX4 assumes you
have a good understanding of logic and its application. Review your notes for
combinational and sequential logic, in additional to register transfer level
design/programming.
• I would like to speak with you in person, how can I schedule that? Please
see the Avenue for office hours.
• To which instructor do I submit MSAFs? Please submit to Dr. Shirani.
• Conflicts/permissions? Please submit to Dr. Shirani.

mcmaster.ca | 12
Microcontroller vs Microprocessor

• Traditionally the definition would have been:

o Microprocessor - single IC focussed sole on data processing. Memory


and peripherals were off-chip. Generally fast clock and more expensive.
Larger systems like desktop or laptop.

o Microcontroller - an IC or a PCB with ICs that have specific application.


Limited memory and peripherals on-chip/on-board. Slower clock speed
and less expensive. Smaller systems like keyboards, mice, appliances,
video screens, etc.

o The traditional definition starts to blur as microcontroller ICs become


faster with more on-chip/board resources. e.g. The Raspberry PI

mcmaster.ca | 13
•Broadcom BCM2711, Quad core Cortex-A72
The Raspberry Pi 4 (ARM v8) 64-bit SoC @ 1.5GHz
•1GB, 2GB or 4GB LPDDR4-3200 SDRAM
(depending on model)
•2.4 GHz and 5.0 GHz IEEE 802.11ac wireless,
Bluetooth 5.0, BLE
•Gigabit Ethernet
•2 USB 3.0 ports; 2 USB 2.0 ports.
•Raspberry Pi standard 40 pin GPIO header (fully
backwards compatible with previous boards)
•2 × micro-HDMI ports (up to 4kp60 supported)
•2-lane MIPI DSI display port
•2-lane MIPI CSI camera port
•4-pole stereo audio and composite video port
•H.265 (4kp60 decode), H264 (1080p60 decode,
1080p30 encode)
•OpenGL ES 3.0 graphics
•Micro-SD card slot for loading operating system
and data storage
•5V DC via USB-C connector (minimum 3A*)
•5V DC via GPIO header (minimum 3A*)
•Power over Ethernet (PoE) enabled (requires
separate PoE HAT)
•Operating temperature: 0 – 50 degrees C
ambient
A good quality 2.5A power supply can be used if
downstream USB peripherals consume less than
500mA in total.
https://www.raspberrypi.org/products/raspberry-pi-4-model-
b/specifications/

mcmaster.ca | 14
Computer Families

• X86, Pentium 4, IA-32, X64 (Intel)

• Digital Signal Processors or “DSP chip”

• The 8048/8051 microcontroller (Intel originally, but now made by many others such as Philips,
Dallas Semiconductor, Siemens, Atmel, Motorola)

• Motorola (now Freescale, now NXP) 6800-based microprocessor and the 68HC11 microcontroller,
plus newer derivatives such as the S12.

• Microchip PIC16/18/24

• ARM CPU/Micro processors 64/32-bit (e.g., Cortex)

• Soft processors (embedded into FPGAs and ASICs such as Altera NIOS II and Xilinx MicroBlaze)

mcmaster.ca | 15
Milestones in Micro Architecture

mcmaster.ca | 16
Milestones in Micro Architecture

mcmaster.ca | 17
What is a Computer?

?
mcmaster.ca | 18
What is a Computer?

Hardware

? Software

mcmaster.ca | 19
To avoid unnecessary complexities at
The von Neumann this stage, we will use this model to
This is how most modern computing systems are structured. represent our micro to simplify
discussion. For those that are
interested to know the differences,
look ahead to the textbook section 3.4.

mcmaster.ca | 20
The von Neumann
This is how most modern computing systems are structured.
• Processor consists of the arithmetic logic unit (ALU), control unit, and registers.
o The ALU handles arithmetic and logic operations
o The Control Unit is the processor’s traffic controller, it decodes and handles machine code and performs the operations
specified
o The Registers are storage locations inside the CPU that are used to hold data or address during the execution of an
instruction.
• Common Bus interfaces between the processor and digital units or peripherals (example, Memory, I/O)
• A microcontroller incorporates the processor and one or more of the following:
o Memory
o Timer functions
o Communication functions
o ADC
o DAC
o Direct Memory Access
o I/O ports
o Software Debug support

mcmaster.ca | 21
Nomenclature

Terms you need to keep straight:

o Cortex-M4 – the family of microprocessor we will be


using in 2DX4 (aka the cpu)

o Texas Instrument MSP-EXP432E401Y LaunchPad – the


name of the microcontroller we will be using in 2DX4

mcmaster.ca | 22
The ENIAC

• One of the first electronic digital


computers developed by the military
to compute ballistic firing tables in
World War II.
• Over thirty tons
• 19,000 vacuum tubes, 1,500 relays,
and hundreds of thousands of
resistors, capacitors, and inductors
• Consumed almost 200 kilowatts

mcmaster.ca | 23
Hardwired vs. “Softwired”

✤ Hardwired ✤ “Softwired”
Data Input Memory Instructions in
A-F Memory

A Send to X
Output from
Computer with
B Send to X stored instructions

C Send to X X
D Send to Y Y
E Send to Y

F Send to Y

X =A+ B + C X =A+ B + C
Y=D+E+F Y=D+E+F

mcmaster.ca | 24
Memory
The two elements of every memory cell:

address contents
• Computer memory is comparable to 0 LDA 14
a collection of mailboxes. 1 ADD 15

2 STA 14
• Each memory cell has two 3 HLT

components: 4 153

5 'A'
o its address, and 6 6.5

o its contents, or value.


7 0.00014

8 gray pixel

• A memory cell has one value and is 9 '!'

never empty.
10 0

11 0

• Also called Random-Access-Memory


12 0

13 0
(RAM) 14 10

15 7
• Volatile memory …

Note - this is a conceptual map of memory contents

mcmaster.ca | 25
Memory continued

• The purpose of memory is to store information that is to be processed or


store instructions on how to process information.
• Information is stored in memory in bits, or binary digits.
• Each bit can hold one of two states:
o On or Off,
o One or Zero,
o True or False.
• A grouping of bits are called a “word”.
• Typically 8-bits are called 1-Byte.

mcmaster.ca | 26
Talk To The Machine

• How do we give a computing machine direction?

• Compiler?

• Interpreter?

mcmaster.ca | 27
Talk To The Machine

• How do we give a computing machine direction?

• Compiler?

• Interpreter?
} Yes, but these are for us

mcmaster.ca | 28
Talk To The Machine

• How do we give a computing machine direction?

• Compiler?

• Interpreter?
} Yes, but these are for us

The machine speaks machine’s language…

010101010101010101101000101010101

mcmaster.ca | 29
How a Basic Computer Works

• Needs a set of basic instructions


for example: Start, Stop, Load, Save, Add, Branch, etc.

• Instructions must be given in a form the computer understands:


o machine language
o 01010101011111000101
o The first “programmers” worked directly in machine language
o Why?

mcmaster.ca | 30
How a Basic Computer Works (cont’d)
For each basic command, an operation code is required.

Commands Operation Code


Start 0000
Notice the order?
Stop 0001
These operation codes
Add 0010 are sequentially
Load 0011 counting in binary:
Save 0100
0-?

Branch if equal 0101


Brach if not equal 0110

mcmaster.ca | 31
How a Basic Computer Works (cont’d)
Using our operation codes, if we wanted to write a program using our Basic
Computer it would resemble:

0000 Start
0011 1110 Load 14
0010 1111 Add 15
0100 1110 Save 14
Stop
0001
Hard to understand, enter, debug, and maintain for human being

Assumes two numbers (data) stored at locations 14 (1110) and 15 (1111).

mcmaster.ca | 32
How a Basic Computer Works (cont’d)
• The usage of operation code (op-codes) is not human friendly, but this is
the language the computer understands (machine language).

• To make machine language more programmer friendly, short words


(mnemonics) were used to represent the operation code.

mcmaster.ca | 33
How a Basic Computer Works (cont’d)
For each basic command, an operation code is required and a mnemonic

Commands Operation Code Mnemonic


Start 0000 ORG
Stop 0001 HLT
Add 0010 ADD
Load 0011 LDA
Save 0100 STA
Branch if equal 0101 BEQ
Brach if not equal 0110 BNE

mcmaster.ca | 34
CPU-Memory Interaction

A computer transforms The program shown in memory is


information from one form loading the value stored in address
to another by a list of 14. Then adding it to the value
instructions called a stored in address 15. The result is
program. then stored into address 14.

0 LDA 14
a = a + b;
1 ADD 15

2 STA 14

3 HLT
Before After

… a 14 10 a 14 17

14 10

15 7 b 15 7 b 15 7

mcmaster.ca | 35
Assembly Language
• Defined by assembler instructions
The two elements of every memory cell:

• An assembly instruction is a mnemonic address contents


representation of a machine instruction
0 LDA 14

1 ADD 15
• Assembly programs must me translated into
2 STA 14
machine language before it can be executed.
3 HLT

• There are two types of translators (assemblers):


o Native assembler (e.g., ARM Cortex-M4 assembly) 14 10

15 7

o Cross assembler (e.g., “C” language to ARM


Cortex-M4 )

• Requires very low level understanding of the logic


and hardware

mcmaster.ca | 36
Example Assembly Code

AREA DATA, ALIGN=2


Num SPACE 4
AREA CODE,READONLY,ALIGN=2
THUMB
EXPORT Start
Ox0000f.\1.13A 4906 LOR rl, [pc, #24] Change LOR Rl,=Num ; 5)
OxOOOOOlBC 6808 LOR rO, [rl,#OxOO] LOR RO, [Rl] 6) .
OxOOOOOlBE F1000019 ADD r0,r0,#0x19 ADD
I

RO,R0,#25 I 7) .
Ox000001C2 6008 STR rO, [rl, #OxOO] STR RO, [Rl] 8) .
Ox000001C4 4770 BX lr BX LR I
I

9) .
Ox000001C6 4903 LOR rl, [pc, #12] Start LOR Rl,=Num ; 1)
Ox000001C8 F04FOOOO MOV rO,#OxOO MOV R0,#0 I 2) .
OxOOOOOlCC 6008 STR rO, [rl,#OxOO] STR RO, [Rl] ; 3)
OxOOOOOlCE F7FFFFF4 BL.W OxOOOOOlBA loop BL Change 4) .
Ox000001D2 E7FC B OxOOOOOlCE B loop
I

I 10) .
Ox000001D4 20000000
Program 3.15. Assemb!J version of Program 3.9. The 1-2-... -10 show the execution sequence.to ARM Cortex-M Microcontrollers”, 6ed., 2019
Valvano, “Introduction

R/W mcmaster.ca
Address
- -
Data Operations | 37
Instruction
Example Assembly Code 1

Source Code
3 2 AREA DATA, ALIGN=2
Num SPACE 4
AREA CODE,READONLY,ALIGN=2
Machine Code Assembly Code THUMB
EXPORT Start
Ox0000f.\1.13A 4906 LOR rl, [pc, #24] Change LOR Rl,=Num ; 5)
OxOOOOOlBC 6808 LOR rO, [rl,#OxOO] LOR RO, [Rl] 6) .
OxOOOOOlBE F1000019 ADD r0,r0,#0x19 ADD
I

RO,R0,#25 I 7) .
Ox000001C2 6008 STR rO, [rl, #OxOO] STR RO, [Rl] 8) .
Ox000001C4 4770 BX lr BX LR I
I

9) .
Ox000001C6 4903 LOR rl, [pc, #12] Start LOR Rl,=Num ; 1)
Ox000001C8 F04FOOOO MOV rO,#OxOO MOV R0,#0 I 2) .
OxOOOOOlCC 6008 STR rO, [rl,#OxOO] STR RO, [Rl] ; 3)
OxOOOOOlCE F7FFFFF4 BL.W OxOOOOOlBA loop BL Change 4) .
Ox000001D2 E7FC B OxOOOOOlCE B loop
I

I 10) .
Ox000001D4 20000000 This is the program you write
Program
This3.15. Assemb!J
is the programversion of Program
translated to3.9. The 1-2-... -10 show the execution
assembler sequence.to ARM Cortex-M Microcontrollers”, 6ed., 2019
Valvano, “Introduction

and then machine code


R/W mcmaster.ca
Address
- -
Data Operations | 38
Instruction
Program 3.15. Assemb!J version of Program 3.9. The 1-2-... -10 show the execution sequence.
Example Assembly Code Explained
R/W
Read
Address
Ox000001C6
- -
Data
Ox4903
Operations
1) PC=Ox000001C8
Instruction
LOR Rl, =Num
Read Ox000001D4 Ox20000000 Rl=Ox20000000
Read Ox000001C8 OxF04FOOOO 2) PC=Ox000001CC,R0=0 MOV R0,#0
Read OxOOOOOlCC Ox6008 3) PC=OxOOOOOlCE STR RO, [Rl]
Write Ox20000000 OxOOOOOOOO Num=O
Read OxOOOOOlCE 0xF7FFFFF4 4) LR=Ox000001D3,PC=Ox000001BA BL Change
Read OxOOOOOlBA Ox4906 5) PC=OxOOOOOlBC LOR Rl, =Num
Read Ox000001D4 Ox20000000 Rl=Ox20000000
Read OxOOOOOlBC Ox6808 6) PC=OxOOOOOlBE LOR RO, [Rl]
Read Ox20000000 OxOOOOOOOO RO=O
Read OxOOOOOlBE OxF1000019 7) PC=Ox000001C2,R0=25 ADD RO,R0,#25
Read Ox000001C2 Ox6008 8) PC=Ox000001C4 STR RO, [Rl]
Write Ox20000000 Ox00000019 Num=25
Read Ox000001C4 Ox4770 9) LR=Ox000001D2 BX LR
Read Ox000001D2 OxE7FC 10) PC=OxOOOOOlCE B Loop

mcmaster.ca | 39
Memory System

• Simplified micro/memory system illustrated

• Recall what two components does every


memory cell contain?

• Recall from 2DI4 - memory is specified by


mxn

o m = number of words (aka locations) in


the chip

o n = number of bits in one word/location


(memory width)

mcmaster.ca | 40
Memory System

• Simplified micro/memory system illustrated

• Recall what two components does every


memory cell contain? Address and Contents

• Recall from 2DI4 - memory is specified by


Address and Contents
mxn
Address and Contents
o m = number of words (aka locations) in Address and Contents
the chip Address and Contents
Address and Contents
o n = number of bits in one word/location
(memory width)

mcmaster.ca | 41
Program Execution

• Where does a program begin?

• How does the micro know where the program should execute?

• How many operations can be executed simultaneously?

mcmaster.ca | 42
Program Execution

• Where does a program begin?


Must be defined. Simplest of micros start at memory location 0 when powered up.
The Cortex-M4 fetches the starting location from interrupt vector table. (User definable)

• How does the micro know where the program should execute?
A circuit referred to as the Program Counter (PC) provides a
pointer the next instruction to be fetched/executed.

• How many operations can be executed simultaneously?


Only one operation can be executed at a time.

mcmaster.ca | 43
Organization of
the Cortex-M4
Micro
High Level Block Diagram:
Processor

mcmaster.ca | 44
Organization of
the Cortex-M4
Micro
High Level Block Diagram:
System Peripherals

mcmaster.ca | 45
Organization of
the Cortex-M4
Micro
High Level Block Diagram:
Serial, Analog, & Motion
Peripherals

mcmaster.ca | 46
2DI4 Recall:
Cortex-M4 Registers What is a register?

The processor has the following What is register


32-bit registers: transfer level (RTL)
programming?
• 13 general-purpose registers,
r0-r12 How is assembly
language
programming
• Stack Pointer (SP) alias of related to RTL?
banked registers, SP_process
and SP_main

• Link Register (LR), r14

• Program Counter (PC), r15

• Special-purpose Program
Status Registers, (xPSR).
mcmaster.ca | 47
Cortex-M4 Registers
The general-purpose registers r0-r12 have no special architecturally-defined uses. Most
instructions that can specify a general-purpose register can specify r0-r12.

Low registers Registers r0-r7 are accessible by all instructions that specify a general-purpose
register.

High registers Registers r8-r12 are accessible by all 32-bit instructions that specify a general-
purpose register. Registers r8-r12 are not accessible by all 16-bit instructions.

Registers r13, r14, and r15 have the following special functions:
• Stack pointer Register r13 is used as the Stack Pointer (SP).
• Link register Register r14 is the subroutine Link Register (LR).
• Program counter Register r15 is the Program Counter (PC).

mcmaster.ca | 48
Looking Forward

• Studios (W0 + W1)

o Introduction

o Installing IDE and related tools

o Simple I/O

• Lab 1 – Simple I/O

mcmaster.ca | 49

You might also like