0% found this document useful (0 votes)
10 views30 pages

Chapter 1 - Embedded and Microcontroller - Compatibility Mode

The document outlines the agenda for a lecture on embedded systems, covering course details, product life cycle, and ARM programming. It includes important information on lab schedules, grading criteria, and resources for students. Key topics discussed include microcontrollers, product life cycle stages, and programming fundamentals using ARM architecture.

Uploaded by

tai.diep21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views30 pages

Chapter 1 - Embedded and Microcontroller - Compatibility Mode

The document outlines the agenda for a lecture on embedded systems, covering course details, product life cycle, and ARM programming. It includes important information on lab schedules, grading criteria, and resources for students. Key topics discussed include microcontrollers, product life cycle stages, and programming fundamentals using ARM architecture.

Uploaded by

tai.diep21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lecture 1: Introduction,

Embedded Systems, Product


Life-Cycle, ARM Programming

Dr. Nguyen Chi Ngoc 1-1


Agenda
qCourse Description
vBook, Labs, Equipment
vGrading Criteria
vExpectations/Responsibilities
vPrerequisites
qEmbedded Systems
qMicrocontrollers
qProduct Life Cycle
vAnalysis, Design, Implementation, Testing
vFlowcharts, Data-Flow and Call Graphs
qARM Architecture
qProgramming
qIntegrated Development Environment (IDE)

1-2
Useful Info
• No labs this week!
• Lab lectures start this Friday
• F 4–5, M 6:30–7:30 and 7:30-8:30 (ECJ 1.202)
• Office hours: see Canvas for most recent?
• TAs have office hours too
• They are not there to do your work for you
• One course == common exams and HW
• 2/23 7–8:30 (15%) 4/6 7–8:30 (20%) Final TBD (25%)
• Most of the learning is in the labs
• 10 labs 30% of grade
• HW is important too so 10% for motivation
• Read the book and lab manual!
• Canvas, Piazza, and
[Link]/~valvano/Volume1/

1-3
Action Items

• Come introduce yourselves


• Take stock of resources
• Class Website (Volume1)
• Piazza for class discussions
• Email to reach TAs+Me
• E-Book: Search “Valvano e-book”
• Order board
• Install SW
• Read Chapters 1 & 2 of book

1-4
DOs and DON’Ts
DO DON’T
•Read •Don’t cheat!
• Book, lab, datasheets •Never look at
•Try before seeking help another student’s
•Follow Piazza/Canvas code (current or
previous)
•Discuss material with
others •Don’t let your partner
do all the work
•Homework (not labs) in
groups •Don’t copy software
from book or web
•Consult the web without attribution
•Track due dates •Don’t expect
handholding
1-5
EE306 Recap: Digital Logic
()*)H
%"#$%& !"#$%& ! "!
,,,!,,,,,56/752,,86/752,,,"!
'()& *$(+, #A%C'A
,,,',H,,,-./012,,,,344,,,,,()*)H
()*)H,,,,,344,,,,,-./012,,'H ! !"#$%&
"! ! "!
*$(+,
' ,,V
'()& !"#$%&
V ,,'

q AND, OR, NOT


q Flip flops
q Registers
Positive logic: Negative logic :
True is higher voltage True is lower voltage
False is lower voltage False is higher voltage

1-6
EE306, Also

• Problem solving
• Programming
• Debugging

1-7
EE302 Recap: Ohm’s Law
V=I*R Voltage = Current * Resistance
I=V/R Current = Voltage / Resistance
R=V/I Resistance = Voltage / Current

*"#"'()+I
"
!"##$B&
# ! &#'()& !"#"A%!
'$()(#*B

•P = V * I Power = Voltage * Current


•P = V2 / R Power = Voltage2 / Resistance 1 amp is 6.241×1018
•P = I2 * R Power = Current2 * Resistance electrons per second =
1 coulomb/sec
1-8
!"#A%C'
Embedded System
()*+I+*A-"

q Embedded Systems are


.+II)/A%C*A+/M
!A'A*C13
everywhere
v Ubiquitous, invisible
v Hidden (computer inside)
v Dedicated purpose
q Microprocessor
2/#)M*1AC'
.+IM)I"1
v Intel: 4004, ..8080,..
x86
v Freescale: 6800, ..
MP8LSSLSA)9)ELP 9S12,.. PowerPC
*+IDCIC-EDC..LD =*>?ACDA@*A<
v ARM, DEC, SPARC, MIPS,
[Link]+I1.O
PLI41-+I1.O PowerPC, Natl. Semi.,…
%DCIL))CD I4LP+I1.O
CD
q Microcontroller
!"#A%CDE)
B:* CRE+I1. v Processor+Memory+
SLT+IL)
B#* ;:<
I/O Ports (Interfaces)
AB&'()
!"# :;< #*)B&'#

1-9
Microcontroller
q Processor – Instruction Set + memory + accelerators
q Ecosystem
q Memory
v Non-Volatile
o ROM
o EPROM, EEPROM, Flash
v Volatile
o RAM (DRAM, SRAM)
q Interfaces
v H/W: Ports
v S/W: Device Driver
v Parallel, Serial, Analog, Time
q I/O
v Memory-mapped vs. I/O-instructions (I/O-mapped)

1-10
Texas Instruments TM4C123
!"#$%C'() =mPERJb
=mPENTBkTPB#MENDuLJN no#H

!"#AB"CDEBG !"#AB"CDEBk
"GV
"GW
hRMKE aCTD
"kV
"kW ARM Cortex-M4
"G;<==#>?@ #IHP "k;
"GA<==#>B@
"GC<==#>aPP
cGB?P "kA
"kC<#IH>=FG
+ 256K EEPROM
"GI<==#>HOb
"G4<c>?@
"G><c>B@
aCTD
==#P
HGnBIl>
"kI<#IH>=Hg
"k4
"k>
+ 32K RAM
"HV !"#AB"CDEBH !"#AB"CDEBF "FV + JTAG
"HW "FW
"H;
"HA
c=kBIl> ?pNOsN
?RTNDP
"F;
"FA
+ Ports
"HC<?FA<=dA "FC
"HI<?F#
"H4<?e=<=dF#A
i?G! =R@
WAtUREBpRrN
"FI
"F4
+ SysTick
"H><?Hf<=dHgf "F>
+ ADC
"h;
!"#AB"CDEBh !"#AB"CDEBa
+ UART
"hA GFH ?pCBGMLOCM "aA
"hC IBJKLMMNOP HCTSLDLECDP "aC
"hI 4IBRMSTEP "aI
"h4 4IBUREP ?pCB"de "a4
"h> eCrTONP "a>

GrsLMJNrBvRMKB"NDuCDTLMJNBkTP GrsLMJNrB"NDRSKNDLOBkTP

1-11
LaunchPad Switches and LEDs
! ,C!+!
"#ABCDE FG+
FGA
!"#$B& F>C ,CE!+! 4R
F>+ ST//8
,D= 12P/ ,/M
?4 F1C
+!
FV4 EE+! EE+! EE+!
'!( ,CD -.C -.D
,D4 FVA FGE
F1+ +!
+!
FV+ ,CC
,= +!
F1; FGD
+!
,C+ +!
FVC ,D V"BCCAWW"CS
F1< FGC
+!

q The switches on the LaunchPad


vNegative logic
vRequire internal pull-up (set bits in PUR)
q The PF3-1 LEDs are positive logic
1-12
I/O Ports and Control Registers
7061(8+*9(#*+B(611+0QQ
" " GPIO_PORTF_DATA_R
)+*O0QQ*+
" "
I(- !"#$B&D$B#$B()*+B

.+/B0(B*(#*+B(611+0QQ
I/+0OB/*"(R/BQ
GPIO_PORTF_DIR_R
" !"#$%&'"()*+)*
I(- ,"#$%&'"-&+)*
W$Q .+/B0(B*(#*+B(1/+0OB/*"(+0P/QB0+

The input/output direction of a bidirectional port


is specified by its direction register.
GPIO_PORTF_DIR_R , specify if
corresponding pin is input or output:
v 0 means input
v 1 means output
1-13
I/O Ports and Control Registers
Address 7 6 5 4 3 2 1 0 Name
400F.E608 - - GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA SYSCTL_RCGCGPIO_R
4002.53FC - - - DATA DATA DATA DATA DATA GPIO_PORTF_DATA_R
4002.5400 - - - DIR DIR DIR DIR DIR GPIO_PORTF_DIR_R
4002.5420 - - - SEL SEL SEL SEL SEL GPIO_PORTF_AFSEL_R
4002.551C - - - DEN DEN DEN DEN DEN GPIO_PORTF_DEN_R

• Initialization (executed once at beginning)


1. Turn on clock in SYSCTL_RCGCGPIO_R
2. Wait two bus cycles (two NOP instructions)
3. Unlock PF0 (PD7 also needs unlocking)
4. Set DIR to 1 for output or 0 for input
5. Clear AFSEL bits to 0 to select regular I/O
6. Set PUE bits to 1 to enable internal pull-up
7. Set DEN bits to 1 to enable data pins
• Input/output from pin
6. Read/write GPIO_PORTF_DATA_R 1-14
Product Life Cycle
BCB,/A0N-N0(.N"#2
BCB3"#2.)(N#.2
BCB@R"0AB*N(>)(:2
4#(RSTA !A2N># BCB!(.(B-R"HB>)(/82
;A<=N)A:A#.2
.8A
3"#2.)(N#.2
/)"9RA:
!ACAR"/:A#.
BAHB)A<=N)A:A#.2
BAHB0"#2.)(N#.2
BCBD()*H()A
!A/R"S:A#. ?A2.N#> BCB,"-.H()A
!"#A

Analysis (What?) Implementation(Real)


vRequirements -> vHardware, Software
Specifications Testing (Works?)
Design (How?) vValidation:Correctness
vHigh-Level: Block Diagrams vPerformance: Efficiency
vEngineering: Algorithms, Maintenance (Improve)
Data Structures, Interfacing

1-15
Data Flow Graph

Lab 8: Position Measurement System

!"#A%A"C *"+%I-( DI:;+(


.L%"LILA: .L%"L0121* .L%"L<.=>
DI:;+(
!"#A%A"C P4R P4R .L%"L<.=>
D(C#"F SIFT8IF( TFAV(F
D?#@AAB
CDa
D?#@AAB
SIFT8IF( !"#$%&'

ER4 ER4 :IAC


TA#;+I? TFAV(F cAd(Te;"AC%
.L%"LI2...

1-16
Call Flow Graph

Position Measurement System

%CD(#)*
!"#A R%S

%CD(#)* T32 123


#A#0 -I#4LI -I#4LI

%CD(#)* T32 123


+"I-."IL +"I-."IL +"I-."IL

1-17
Structured Programming
Common Constructs (as Flowcharts)
!"#$"%C" '(%)*+*(%,- ./*-"0-((1

!"#$B&'

!"#$B&' !"#$B&( !"#$B


!"#$B&(

-"."//0/ 1#2D.#P4D0* &$D0..45D6*.#70$89)$94..0$D


!"#$ !"#$ (#&FF*#
!"#$B !"#$I &'+*##,J+

&$#DB &$#DI &$#D

%"&' ()*+B ()*+I ()*+


.*+,#'/0#"1
/&'+*##,J+

1-18
Flowchart
Toaster oven:

!"#$ :CC;

-.%/.%(0+"%
4$/.%(5IC! #'(C$
'S#%O0 NCC(OCP*

8C%(/I+''+* 4$/.%(%C"'%
T%"I% %+!/+I"%.I+
9I+''+*
%C"'%()(*+'#I+*
:CC; %C"'%(!(*+'#I+*
-.%/.%(0+"%
#'(C55

I+%.I$

Coding in assembly and/or high-level language (C)

1-19
Flowchart
q Example 1.3. Design a flowchart for a system that performs two independent
tasks. The first task is to output a 20 kHz square wave on PORTA in real time
(period is 50 ms). The second task is to read a value from PORTB, divide the
value by 4, add 12, and output the result on PORTD. This second task is repeated
over and over.

C'() D
void SysTick_Handler(void){
*)+I-.)./0#C A !"#$% PORTA = PORTA^0x01; >
" } #
PORTB
PORTA 1 > void main(void){ D
PORTA:7 unsigned long n;
).1.O)345678 B while(1){
# n = PORTB; A
n = (n/4)+12; B
PORTD = n; C
9I-+I-.).-# }
PORTD C
}

1-20
ARM Cortex M4-based System
ITP-#P#S.-#99B- >?F.B@CD(F
*+I!C"#-.B/MI1I
O-#PBFF#-
RSO(.
<<= O#-.F
RS.B-S49
!AA4SPBA
OB-TO:B-49F "TB:1OB-C ;(.O(.
#(F O#-.F
RSF.-(P.T#SF
894F:C+;I !4.4
R"#ABCD(F !"#ABCD(F +*I

q ARM Cortex-M4 processor


q Harvard architecture
v Different busses for instructions and data

1-21
ARM Cortex M4-based System
q RISC machine
v Pipelining effectively provides single cycle operation for many instructions
v Thumb-2 configuration employs both 16 and 32 bit instructions

!"#!$ %"#!$
!"#$%&#'(F*+(&I#'% -.L%&#'(F*+(&I#'%
M#'(F*+(&I#'%N"2.%2"F$&#3%4.#3(N'% M#'(F*+(&I#'%N"2.%5&S.7%4.#3(N'%
M#'(F*+(&I#'%.S.+*(.%&#%2"F$&#3%(&8.'% M#'(F*+(&I#'%.S.+*(.%&#%9%IF%:%;*'%+$+4.'%
!"#$%&#'(F*+(&I#'%+"#%"++.''%8.8IF$% -.L%&#'(F*+(&I#'%+"#%"++.''%8.8IF$%
•! <I"7%5FI8%8.8IF$%(I%"%F.3&'(.F%
•! =(IF.%5FI8%F.3&'(.F%(I%8.8IF$%
M#%I#.%&#'(F*+(&I#>%(N.%?FI+.''IF%+"#%;I(N%% @I%I#.%&#'(F*+(&I#%+"#%;I(N%F."7%"#7%LF&(.%
•! F."7%8.8IF$%"#7%% 8.8IF$%&#%(N.%'"8.%&#'(F*+(&I#%
•! LF&(.%8.8IF$%%
-.L.F%"#7%8IF.%'?.+&"4&A.7%F.3&'(.F'B%% !"#$%&7.#(&+"4%3.#.F"4%?*F?I'.%F.3&'(.F'%
•! 'I8.%F.3&'(.F'%+I#("&#%7"(">%%
•! I(N.F'%+I#("&#%"77F.''.'%
!"#$%7&55.F.#(%($?.'%I5%"77F.''&#3%8I7.'% <&8&(.7%#*8;.F%I5%"77F.''&#3%8I7.'%
•! F.3&'(.F>%%
•! &88.7&"(.>%"#7%%
•! &#7.S.7B%
1-22
ARM ISA: Thumb2 Instruction Set

q Variable-length instructions
vARM instructions are a fixed
length of 32 bits
vThumb instructions are a fixed
length of 16 bits
vThumb-2 instructions can be
either 16-bit or 32-bit
q Thumb-2 gives approximately 26%
improvement in code density over
ARM
q Thumb-2 gives approximately 25%
improvement in performance over
Thumb

1-23
ARM ISA: Registers, Memory-map
!" :;::::<::::
!# !"#AB&'EF*
!$ +I- :;:::.<&&&&
!%
!C :;!:::<::::
B<;<=RC !' .!AB+/-
8A=89?< !( :;!:::<=&&&
=<>:?4<=? !)
!G
!+ :;>:::<::::
M1IBOP4RF
!#"
!## :;>::&<&&&&
!#$
L4RS7,89:;4<= !#%,-.LM1 :;?:::<::::
2:;7,=<>:?4<= !#C,-2!1 M6R746E'BM1I
M=9>=R@,S9A;4<= !#',-MP1 889 :;?::><@&&&

Condition Code Bit s Indicates


N negative Result is negative TI TM4C123
Z zero Result is zero
V overflow Signed overflow Microcontroller
C carry Unsigned overflow
1-24
LC3 to ARM - Data Movement
LEA R0, Label ;R0 <- PC + Offset to Label
ADR R0,Label or LDR R0,=Label
LD R1,Label ; R1 <- M[PC + Offset]
LDR R0,=Label ; Two steps: (i) Get address into R0
LDRH R1,[R0] ; (ii) Get content of address [R0] into R1
LDR R1,R0,n ; R1 <- M[R0+n]
LDRH R1,[R0,#n]
LDI R1,Label ; R1 <- M[M[PC + Offset]]
; Three steps!!
ST R1,Label ; R1 -> M[PC + Offset]
LDR R0,=Label ; Two steps: (i)Get address into R0
STRH R1,[R0] ; (ii) Put R1 contents into address in R0
STR R1,R0,n ; R1 -> M[R0+n]
STRH R1,[R0,#n]
STI R1,Label ; R1 -> M[M[PC + Offset]]
; Three steps!!

1-25
LC3 to ARM – Arithmetic/Logic

ADD R1, R2, R3 ; R1 <- R2 + R3


ADD R1,R2,R3 ; 32-bit only
ADD R1,R2,#5 ; R1 <- R2 + 5
ADD R1,R2,#5 ; 32-bit only, Immediate is 12-bit
AND R1,R2,R3 ; R1 <- R2 & R3
AND R1, R2, R3 ; 32-bit only
AND R1,R2,#1 ; R1 <- Bit 0 of R2
AND R1, R2, #1 ; 32-bit only
NOT R1,R2 ; R1 -> ~(R2)
EOR R1,R2,#-1 ; -1 is 0xFFFFFFFF,
; so bit XOR with 1 gives complement

1-26
LC3 to ARM – Control
BR Target ; PC <- Address of Target
B Target
BRnzp Target ; PC <- Address of Target
B Target
BRn Target ; PC <- Address of Target if N=1
BMI Target ; Branch on Minus
BRz Target ; PC <- Address of Target if Z=1
BEQ Target
BRp Target ; PC <- Address of Target if P=1
No Equivalent
BRnp Target ; PC <- Address of Target if Z=0
BNE Target
BRzp Target ; PC <- Address of Target if N=0
BPL Target ; Branch on positive or zero (Plus)
BRnz Target ; PC <- Address of Target if P=0
No Equivalent
1-27
LC3 to ARM – Subs,TRAP,Interrupt

JSR Sub ; PC <- Address of Sub, Return address in R7


BL Sub ; PC<-Address of Sub, Ret. Addr in R14 (Link Reg)
JSRR R4 ; PC <- R4, Return address in R7
BLX R4 ; PC <-R4, Return address in R14 (Link Reg)
RET ; PC <- R7 (Implicit JMP to address in R7)
BX LR ; PC <- R14 (Link Reg)
JMP R2 ; PC <- R2
BX R2 ; PC <- R14 (Link Reg)
TRAP x25 ; PC <- M[x0025], Return address in R7
SVC #0x25 ; Similar in concept but not implementation
RTI ; Pop PC and PSR from Supervisor Stack…
BX LR ; PC <- R14 (Link Reg) [same as RET]

1-28
ARM is a Load-Store machine

Code to set (to 1) bit 5 of memory address x400FE608

SYSCTL_RCGCGPIO_R EQU 0x400FE608


; EQU psedo-op allows use of
; symbolic name to represent a constant

LDR R1, =SYSCTL_RCGCGPIO_R ; R1 holds x400FE608


LDR R0, [R1] ; R0 holds contents of
; location x400FE608
ORR R0, R0, #0x20 ; bit5 of R0 is set to 1
STR R0, [R1] ; write R0 contents back to
; location x400FE608

1-29
SW Development Environment
BE*/"A !"#$%& '()#*#+,®
!*=#+-/&E :A"B&;;"A
!"#AB&DB"E& !/-A/ <*BA"B"S/A"++&A
Start
; direction register 4&8#.
LDR R1,=GPIO_PORTD_DIR_R !&;;*"S <&="A>
LDR R0,[R1]
ORR R0,R0,#0x0F
; make PD3-0 output ?@T
STR R0, [R1]

F#*+EDI-A.&/DM1OP

T89&B/DB"E& C&-+ :A"B&;;"A


<*BA"B"S/A"++&A
0x00000142
0x00000144
4912
6808
4"RS+"-E
0x00000146 F040000F <&="A>
0x0000014A 6008 !/-A/
4&8#.
!&;;*"S ?@T
AEEA&;;DDD4-/-

1-30

You might also like