Вы находитесь на странице: 1из 24

EE 319K

Introduction to Embedded Systems

Lecture 3: Debugging, Arithmetic


Operations, More I/O, Switch and
LED interfacing

Bard, Gerstlauer, Valvano, Yerraballi 3-1


Announcements
Sign up to Piazza and set to receive email
HW2 due next Monday
Before going to lab this week, make sure
to install the drivers
❖ http://users.ece.utexas.edu/~valvano/arm/download.html
Step 3 – Method 1

Bard, Gerstlauer, Valvano, Yerraballi 3-2


Agenda
Recap
❖GPIO
❖Logic and Shift Operations
❖Addressing Modes
❖Subroutines and the Stack
❖Introduction to C
Outline
❖Debugging
❖Arithmetic Operations
o Random Number Generator example
❖Digital Logic
o GPIO TM4C123/LM4F120 Specifics
❖Switch and LED interfacing
Bard, Gerstlauer, Valvano, Yerraballi 3-3
Debugging
 Aka: Testing, Diagnostics, ❖ Performance
Verification measurement, how
 Debugging Actions fast it executes
❖ Functional debugging, ❖ Optimization, make
input/output values
tradeoffs for overall
❖ Performance debugging,
input/output values with good
time o improve speed,
❖ Tracing, measure o improve accuracy,
sequence of operations o reduce memory,
❖ Profiling,
o reduce power,
o measure percentage for
tasks, o reduce size,
o time relationship o reduce cost
between tasks

Bard, Gerstlauer, Valvano, Yerraballi 3-4


Debugging Intrusiveness
 Intrusive Debugging  Minimally intrusive
❖ degree of perturbation
❖ negligible effect on the
caused by the debugging
itself system being
❖ how much the debugging
debugged
slows down execution ❖ e.g.,
 Non-intrusive Debugging dumps(ScanPoint) and
❖ characteristic or quality monitors
of a debugger  Highly intrusive
❖ allows system to operate
❖ print statements,
as if debugger did not
exist
breakpoints and
single-stepping
❖ e.g., logic analyzer, ICE,
BDM

Bard, Gerstlauer, Valvano, Yerraballi 3-5


Debugging Aids in Keil
Interface
 Breakpoints
 Registers including xPSR
 Memory and Watch Windows
 Logic Analyzer, GPIO Panel
 Single Step, StepOver, StepOut, Run, Run to
Cursor
 Watching Variables in Assembly
EXPORT VarName[DATA,SIZE=4]
 Command Interface (Advanced but useful)
WS 1, `VarName,0x10
LA (PORTD & 0x02)>>1
Bard, Gerstlauer, Valvano, Yerraballi 3-6
… Debugging
 Instrumentation: Code we ❖ Use conditional
add to the system that compilation (or
aids in debugging conditional assembly)
❖ E.g., print statements o Keil supports
conditional assembly
❖ Good practice: Define
instruments with specific o Easy to remove all
pattern in their names instruments
❖ Use instruments that test  Visualization: How the
a run time global flag debugging information is
o leaves a permanent displayed
copy of the
debugging code
o causing it to suffer a
runtime overhead
o simplifies “on-site”
customer support.

Bard, Gerstlauer, Valvano, Yerraballi 3-7


ARM ISA : ADD, SUB and CMP

ARITHMETIC INSTRUCTIONS
ADD{S} {Rd,} Rn, <op2> ;Rd = Rn + op2
ADD{S} {Rd,} Rn, #im12 ;Rd = Rn + im12
SUB{S} {Rd,} Rn, <op2> ;Rd = Rn - op2
SUB{S} {Rd,} Rn, #im12 ;Rd = Rn - im12
RSB{S} {Rd,} Rn, <op2> ;Rd = op2 - Rn
RSB{S} {Rd,} Rn, #im12 ;Rd = im12 - Rn
CMP Rn, <op2> ;Rn - op2
CMN Rn, <op2> ;Rn - (-op2)

Addition Subtraction
C bit set if unsigned overflow C bit clear if unsigned overflow
V bit set if signed overflow V bit set if signed overflow

Bard, Gerstlauer, Valvano, Yerraballi 3-8


ARM ISA : Multiply and Divide

32-BIT MULTIPLY/DIVIDE INSTRUCTIONS


MUL{S} {Rd,} Rn, Rm ;Rd = Rn * Rm
MLA Rd, Rn, Rm, Ra ;Rd = Ra + Rn*Rm
MLS Rd, Rn, Rm, Ra ;Rd = Ra - Rn*Rm
UDIV {Rd,} Rn, Rm ;Rd = Rn/Rm unsigned
SDIV {Rd,} Rn, Rm ;Rd = Rn/Rm signed

Multiplication does not set C,V bits

Bard, Gerstlauer, Valvano, Yerraballi 3-9


Random Number Generator
;Program demonstrates Arithmetic operations
; ADD, SUB, MUL and IDIV ;------------Random------------
; LR loss when sub calls sub - Solution ; Return R0= 32-bit random number
Seed EQU 123456789 ; Linear congruential generator
THUMB ; from Numerical Recipes by Press et al.
AREA DATA, ALIGN=2 Random LDR R2,=M ; R2 points to M
EXPORT M [DATA,SIZE=4] LDR R0,[R2] ; R0=M
M SPACE 4 LDR R1,=1664525
ALIGN MUL R0,R0,R1 ; R0 = 1664525*M
AREA |.text|, CODE, READONLY, ALIGN=2 LDR R1,=1013904223
EXPORT Start ADD R0,R1 ; 1664525*M+1013904223
EXPORT M [DATA,SIZE=4] STR R0,[R2] ; store M
; Need this to be able to watch RAM BX LR
; Variable M (in Assembly only)
Start LDR R2,=M ; R2 points to M
LDR R0,=Seed
STR R0,[R2]
; Initial seed
; M=Seed Global variable M
loop BL Random
B loop
; R0 has rand number How it is defined
How it is written
Function Random How it is read
How it is called
How it returns
Bard, Gerstlauer, Valvano, Yerraballi 3-10
Bus Driver

74HC125 74HC244
8 8
Tristate Gate A Y A Y
G G
+3.3V
+3.3V
G
T5
T3
A A
T6
+3.3V
T4
Y
T1
G T7
T2 G
T8

Bard, Gerstlauer, Valvano, Yerraballi 3-11


Open Collector

Vcc Vcc
A B 74LS05 74HC05

8k B
20k
n-type
A Q
A B 2
Q
1
Q2
A Q2 B
4.5k Low off HiZ
High active Low

Used to control current to LED


Low allows current to flow to ground
HiZ prevents current from flowing

Bard, Gerstlauer, Valvano, Yerraballi 3-12


Input/Output: TM4C123
Cortex M4 Systick
System Bus Interface NVIC

GPIO Port A GPIO Port B


PA7 PB7
PA6 Four PB6
PA5/SSI0Tx Eight PB5
UARTs I2Cs
PA4/SSI0Rx PB4
PA3/SSI0Fss PB3/I2C0SDA
PA2/SSI0Clk Four PB2/I2C0SCL
PA1/U0Tx CAN 2.0 PB1
SSIs
PA0/U0Rx PB0

PC7 GPIO Port C GPIO Port D PD7


PC6
PC5 USB 2.0 Twelve
PD6
PD5
6 General-Purpose
PC4
PC3/TDO/SWO
Timers PD4
PD3 I/O (GPIO) ports:
PC2/TDI PD2
• Four 8-bit ports
JTAG Six
PC1/TMS/SWDIO 64-bit wide PD1
PC0/TCK/SWCLK PD0

GPIO Port E GPIO Port F


(A, B, C, D)
PE5
PE4 ADC Two Analog PF4 • One 6-bit port (E)
PE3 2 channels Comparators PF3
PE2
PE1
12 inputs
12 bits Two PWM
PF2
PF1
• One 5-bit port (F)
PE0 Modules PF0

Advanced High Performance Bus Advanced Peripheral Bus

Bard, Gerstlauer, Valvano, Yerraballi 3-13


TM4C123 I/O Pins
I/O Pin Characteristics Set AFSEL to 0
❖Can be employed as an n-bit parallel interface
❖Pins also provide alternative functions:
o UART Universal asynchronous receiver/transmitter
o SSI Synchronous serial interface
o I2 C Inter-integrated circuit
o Timer Periodic interrupts, input capture, and output
compare
o PWM Pulse width modulation
o ADC Analog to digital converter, measure analog
signals
o Analog Compare two analog signals
Comparator
o QEI Quadrature encoder interface
o USB Universal serial bus
o Ethernet High speed network
o CAN Controller area network Set AFSEL to 1

Bard, Gerstlauer, Valvano, Yerraballi 3-14


TM4C123 LaunchPad I/O Pins
IO Ain 0 1 2 3 4 5 6 7 8 9 14
PA2 Port SSI0Clk
PA3 Port SSI0Fss
PA4 Port SSI0Rx
PA5 Port SSI0Tx
PA6 Port I2C1SCL M1PWM2
PA7 Port I2C1SDA M1PWM3
PB0 Port U1Rx T2CCP0
PB1 Port U1Tx T2CCP1
PB2 Port I2C0SCL T3CCP0
PB3 Port I2C0SDA T3CCP1
PB4 Ain10 Port SSI2Clk M0PWM2 T1CCP0 CAN0Rx
PB5 Ain11 Port SSI2Fss M0PWM3 T1CCP1 CAN0Tx
PB6 Port SSI2Rx M0PWM0 T0CCP0
PB7 Port SSI2Tx M0PWM1 T0CCP1
PC4 C1- Port U4Rx U1Rx M0PWM6 IDX1 WT0CCP0 U1RTS
PC5 C1+ Port U4Tx U1Tx M0PWM7 PhA1 WT0CCP1 U1CTS
PC6 C0+ Port U3Rx PhB1 WT1CCP0 USB0epen
PC7 C0- Port U3Tx WT1CCP1 USB0pflt
PD0 Ain7 Port SSI3Clk SSI1Clk I2C3SCL M0PWM6 M1PWM0 WT2CCP0
PD1 Ain6 Port SSI3Fss SSI1Fss I2C3SDA M0PWM7 M1PWM1 WT2CCP1
PD2 Ain5 Port SSI3Rx SSI1Rx M0Fault0 WT3CCP0 USB0epen
PD3 Ain4 Port SSI3Tx SSI1Tx IDX0 WT3CCP1 USB0pflt
PD6 Port U2Rx M0Fault0 PhA0 WT5CCP0
PD7 Port U2Tx PhB0 WT5CCP1 NMI
PE0 Ain3 Port U7Rx
PE1 Ain2 Port U7Tx
PE2 Ain1 Port
PE3 Ain0 Port
PE4 Ain9 Port U5Rx I2C2SCL M0PWM4 M1PWM2 CAN0Rx
PE5 Ain8 Port U5Tx I2C2SDA M0PWM5 M1PWM3 CAN0Tx
PF0 Port U1RTS SSI1Rx CAN0Rx M1PWM4 PhA0 T0CCP0 NMI C0o
PF1 Port U1CTS SSI1Tx M1PWM5 PhB0 T0CCP1 C1o TRD1
PF2 Port SSI1Clk M0Fault0 M1PWM6 T1CCP0 TRD0
PF3 Port SSI1Fss CAN0Tx M1PWM7 T1CCP1 TRCLK
PF4 Port M1Fault0 IDX0 T2CCP0 USB0epen 3-15
TM4C123 I/O registers
Address 7 6 5 4 3 2 1 0 Name
$400F.E608 GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA SYSCTL_RCGCGPIO_R
$400F.EA08 GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA SYSCTL_PRGPIO_R
$4005.8000 PORTA base address
$4005.9000 PORTB base address
$4005.A000 PORTC base address
$4005.B000 PORTD base address
$4005.C000 PORTE base address
$4005.D000 PORTF base address
base+$3FC DATA DATA DATA DATA DATA DATA DATA DATA GPIO_PORTx_DATA_R
base+$400 DIR DIR DIR DIR DIR DIR DIR DIR GPIO_PORTx_DIR_R
base+$420 AFSEL AFSEL AFSEL AFSEL AFSEL AFSEL AFSEL AFSEL GPIO_PORTx_AFSEL_R
base+$510 PUE PUE PUE PUE PUE PUE PUE PUE GPIO_PORTx_PUR_R
base+$51C DEN DEN DEN DEN DEN DEN DEN DEN GPIO_PORTx_DEN_R
base+$524 CR CR CR CR CR CR CR CR GPIO_PORTx_CR_R
base+$528 AMSEL AMSEL AMSEL AMSEL AMSEL AMSEL AMSEL AMSEL GPIO_PORTx_AMSEL_R

31-28 27-24 23-20 19-16 15-12 11-8 7-4 3-0


base+$52C PMC7 PMC6 PMC5 PMC4 PMC3 PMC2 PMC1 PMC0 GPIO_PORTx_PCTL_R
base+$520 LOCK (32 bits) GPIO_PORTx_LOCK_R

• Four 8-bit ports (A, B, C, D) • PA1-0 to COM port


• One 6-bit port (E) • PC3-0 to debugger
• One 5-bit port (F) • PD5-4 to USB device

Bard, Gerstlauer, Valvano, Yerraballi 3-16


Switch Configuration

negative – pressed = ‘0’ positive – pressed = ‘1’

Bard, Gerstlauer, Valvano, Yerraballi 3-17


Switch Configuration
+3.3V +3.3V
TM4C TM4C
10k
s Input port t Input port
10k
Negative logic Positive logic

Negative Logic s Positive Logic t


– pressed, 0V, false – pressed, 3.3V, true
– not pressed, 3.3V, true – not pressed, 0V, false
+3.3V +3.3V +3.3V +3.3V
TM4C TM4C TM4C TM4C
10k 10k
3.3V 0V
s Input port s Input port t Input port t Input port
0.0V 3.3V
10k 10k
Pressed Not pressed Pressed Not pressed

Bard, Gerstlauer, Valvano, Yerraballi 3-18


LED Interfacing

LED current v. voltage


Brightness = power = V*I anode (+)

cathode (1)
“big voltage connects to big pin”

Bard, Gerstlauer, Valvano, Yerraballi 3-19


LED Configuration

Current
high LM3S +3.3V
2 + a Out R
I I or 1mA
R 1mA TM4C
(mA) 1 - k LM3S LED
or
TM4C LED
voltage low
0 Out
1.5 1.6 1.7
V (volts)
(a) LED curve (b) Positive logic interface (c) Negative logic interface

Bard, Gerstlauer, Valvano, Yerraballi 3-20


LED Interfacing

R = (3.3V – 1.6)/0.001 R = (5.0-2-0.5)/0.01


= 1.7 kOhm = 250 Ohm
high LM3S +5V
Out or R 10mA
R 1mA TM4C 7406
LM3S
or +5V LED
TM4C LED
high 0.5V
Out

LED current < 8 ma LED current > 8 ma

LED may contain several diodes in series

Bard, Gerstlauer, Valvano, Yerraballi 3-21


LaunchPad Switches and LEDs
R1 0
TM4C123 PF0
PF4
Serial PA1 R13 0 5V
PA0 Green
R29 Blue Red
+5 PB1
0 330 330 330
USB PD5
PD4 R12 SW1 SW2
R25 PF3
PB0 0
0
PD0 R11
R9 0
PB6 PF2
0
R10 0
PD1 R2 DTC114EET1G
PB7 PF1
0

 The switches on the LaunchPad


❖Negative logic
❖Require internal pull-up (set bits in PUR)
 The PF3-1 LEDs are positive logic
Bard, Gerstlauer, Valvano, Yerraballi 3-22
Initialization Ritual

• Initialization (executed once at beginning)


1. Turn on Port F clock in SYSCTL_RCGCGPIO_R
Wait two bus cycles (two NOP)
2. Unlock PF0 (PD7 also needs unlocking)
3. Clear AMSEL to disable analog
4. Clear PCTL to select GPIO
5. Set DIR to 0 for input, 1 for output
6. Clear AFSEL bits to 0 to select regular I/O
7. Set PUE bits to 1 to enable internal pull-up
8. Set DEN bits to 1 to enable data pins
• Input from switches, output to LED
10. Read/write GPIO_PORTF_DATA_R
Prog 4.1, show PortF_Init function in InputOutput_xxxasm
Bard, Gerstlauer, Valvano, Yerraballi 3-23
I/O Port Bit-Specific
 I/O Port bit-specific
addressing is used to
access port data
register
❖ Define address offset as
4*2b, where b is the
selected bit position Port F = 0x4005.D000
❖ 256 possible bit 0x4005.D000+0x0004+0x0040
combinations (0-8)
= 0x4005.D044
❖ Add offsets for each bit
selected to base
Provides friendly and atomic
address for the port
access to port pins
❖ Example: PF4 and PF0

Show PortF_Input2 function in InputOutput_xxxasm


Bard, Gerstlauer, Valvano, Yerraballi 3-24

Вам также может понравиться