EE 319K Introduction to Microcontrollers

Slides:



Advertisements
Similar presentations
EE 319K Introduction to Embedded Systems
Advertisements

4-1 EE 319K Introduction to Embedded Systems Lecture 4: Arithmetic overflow, Branches, Control Structures, Abstraction & Refinement Bard, Erez, Gerstlauer,
Chapter 5 The LC-3 Instruction Set Architecture l ISA Overview l Operate instructions l Data Movement instructions l Control Instructions l LC-3 data path.
CS25410 Memory Machine Code. Common types of non-rotating memory (1) RAMRandom Access Memory In reality, read/write memory This is usually volatile, meaning.
1-1 Bard, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Microcontrollers Lecture 1: Introduction, Embedded Systems, Product Life-Cycle, ARM Programming.
© 2010 Kettering University, All rights reserved..
Spring 2008, Jan. 14 ELEC / Lecture 2 1 ELEC / Computer Architecture and Design Spring 2007 Introduction Vishwani D. Agrawal.
S. Barua – CPSC 240 CHAPTER 5 THE LC-3 Topics Memory organization Registers Instruction set Opcodes.
CHAPTER 4 COMPUTER SYSTEM – Von Neumann Model
COMP3221: Microprocessors and Embedded Systems Lecture 2: Instruction Set Architecture (ISA) Lecturer: Hui Wu Session.
LC-3 Instruction Set Architecture (Textbook’s Chapter 5)
Chapter 6 Programming in Machine Language The LC-3 Simulator
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
Chapter 9 & 10 Subroutines and Interrupts. JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7, JMP Offset Jump to Subroutine at offset.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
11-1 Bard, Tiwari, Telang, Janapa Reddi, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Embedded Systems Lecture 11: Data Acquisition, Numerical.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 29: Microcontroller intro.
1-1 Ramesh Yerraballi EE 319K Introduction to Microcontrollers Lecture 1: Introduction, Embedded Sys, Product Life- Cycle, 9S12 Programming.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Overview von Neumann Model Components of a Computer Some Computer Organization Models The Computer Bus An Example Organization: The LC-3.
6-1 EE 319K Introduction to Embedded Systems Lecture 6: SysTick Timer, Exam 1 Review Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi,
Chapter 17 Microprocessor Fundamentals William Kleitz Digital Electronics with VHDL, Quartus® II Version Copyright ©2006 by Pearson Education, Inc. Upper.
2-1 EE 319K Introduction to Embedded Systems Lecture 2: I/O, Logic/Shift Operations, Addressing modes, Memory Operations, Subroutines, Introduction to.
Computer Organization and Assembly language
Chapter 5 The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Instruction Set Architecture ISA.
1-1 EE 319K Introduction to Microcontrollers Lecture 1: Introduction, Embedded Systems, ARM Programming.
Spring 2007W. Rhett Davis with slight modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 11: Memories,
Fall 2015, Aug 17 ELEC / Lecture 1 1 ELEC / Computer Architecture and Design Fall 2015 Introduction Vishwani D. Agrawal.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-2 Instruction Set Architecture Operate instructions Data Movement instructions.
Microcontroller Presented by Hasnain Heickal (07), Sabbir Ahmed(08) and Zakia Afroze Abedin(19)
Housekeeping 1.teams—end of class 2.Example verilog code (alter) 3.Example altera report 4.Lab Monday: you will be asked to show: -- one or more reports.
Introduction to AVR Chapter 1
Chapter 5 The LC Instruction Set Architecture ISA = All of the programmer-visible components and operations of the computer memory organization.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Instruction Set Architecture ISA = All of the.
ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Lecture 7: Overview Microprocessors / microcontrollers.
Spring 20067W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 Design of Complex Digital Systems Lecture 11: Data Converter,
Spring 2016, Jan 13 ELEC / Lecture 1 1 ELEC / Computer Architecture and Design Spring 2016 Introduction Vishwani D. Agrawal.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 12: Intro to the LC-3 Micro-architecture.
Introduction to Computing Systems and Programming The LC-2.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
Chapter 9 TRAP Routines and Subroutines
EE 319K Introduction to Embedded Systems
EE 319K Introduction to Microcontrollers
EE 319K Introduction to Embedded Systems
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
Chapter 5 The LC-3.
Chapter 9 TRAP Routines and Subroutines
T Computer Architecture, Autumn 2005
Computer Science 210 Computer Organization
Introduction to Computer Engineering
TRAP Routines Subroutines Privileged Instructions
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
LC-2: The Little Computer 2
Chapter 9 TRAP Routines and Subroutines
ECE 3430 – Intro to Microcomputer Systems
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Introduction to Assembly Chapter 2
ELEC / Computer Architecture and Design Fall 2014 Introduction
An Introduction to the ARM CORTEX M0+ Instructions
Chapter 4 The Von Neumann Model
Presentation transcript:

EE 319K Introduction to Microcontrollers Lecture 1: Introduction, Embedded Systems, Product Life-Cycle, ARM Programming Great class, combines concepts, skills, and experience. Build real systems, bridge physical and virtual. Embedded systems critical to everyone, knowledge gained goes way beyond that. Learn to how a system works and development flow, learn how a computer and embedded system works practically, learn how to program, learn how to use programming tools and mixed environments, learn about interfacing and design Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Agenda Course Description Embedded Systems Product Life Cycle Book, Labs, Equipment Grading Criteria Expectations/Responsibilities Prerequisites Embedded Systems Microcontrollers Product Life Cycle Analysis, Design, Implementation, Testing Flowcharts, Data-Flow and Call Graphs ARM Architecture Programming Integrated Development Environment (IDE) To do this week: get book, order a board, {read chapters 1 and 2 of the book or ebook 2 3 4}, do ws01, do HW1, install Keil uVision 4.73 on laptop Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Useful Info No labs this week! Lab lectures start the Friday before Lab 2 F 4 – 5 CPE 2.212, M 6:30 – 7:30 CPE 2.216, 7:30-8:30 CPE 2.216(not required) 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/26 7–8:30 (15%) 4/9 7–9 (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 users.ece.utexas.edu/~valvano/Volume1/ Slides available, but will try to use blackboard Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

AIs Come introduce yourselves Fill in survey Order board Install SW Read Chapters 1 & 2 of book Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

DOs and DON’Ts DO DON’T RTFM! Try N times before seeking help Book, lab, datasheets Try N times before seeking help Follow Piazza/Canvas Discuss material with others Homework (not labs) in groups Consult the web Track due dates Don’t cheat! Never look at another student’s code (current or previous) Don’t let your partner do all the work Don’t copy software from book or web without attribution Don’t expect handholding Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

EE306 Recap: Digital Logic AND, OR, NOT Flip flops Registers Positive logic: Negative logic : True is higher voltage True is lower voltage False is lower voltage False is higher voltage Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

EE306, Also Problem solving Programming Debugging Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

EE302 Recap: Ohm’s Law V = I * R Voltage = Current * Resistance I = V / R Current = Voltage / Resistance R = V / I Resistance = Voltage / Current P = V * I Power = Voltage * Current P = V2 / R Power = Voltage2 / Resistance P = I2 * R Power = Current2 * Resistance 1 amp is 6.241×1018 electrons per second = 1 coulomb/sec Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Embedded System Embedded Systems are everywhere MicroProcessor Ubiquitous, invisible Hidden (computer inside) Dedicated purpose MicroProcessor Intel: 4004, ..8080,.. x86 Freescale: 6800, .. 9S12,.. PowerPC ARM, DEC, SPARC, MIPS, PowerPC, Natl. Semi.,… MicroController Processor+Memory+ I/O Ports (Interfaces) Consumer electronics: Washing machine, Exercise equipment, Remote controls, Clocks and watches, Games and toys, Audio/video electronics, Set-back thermostats, Camera, Camcoder, Television, VCR, cable box Communication systems: Answering machines, Telephones, Fax machines, Radios, Cellular phones, pagers Automotive systems: Automatic breaking, Noise cancellation, Locks, Electronic ignition, Power windows and seats, Cruise control, Collision avoidance, Climate control, Emission control, Instrumentation Military hardware: Smart weapons, Missile guidance systems, Global positioning systems, Surveillance systems Business applications: Cash registers, Vending machines, ATM machines, Traffic controllers, Industrial robots, Bar code readers and writers, Automatic sprinklers, Elevator controllers, RFID systems, Lighting and heating systems Medical devices: Monitors, Drug delivery systems, Cancer treatments, Pacemakers, Prosthetic devices, Dialysis machines Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Embedded Systems A reactive system continuously A real time system accepts inputs performs calculations generates outputs A real time system Specifies an upper bound on the time required to perform the input/calculation/output in reaction to external events Interacts with physical environment Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Microcontroller Processor – Instruction Set + memory + accelerators Ecosystem Memory Non-Volatile ROM EPROM, EEPROM, Flash Volatile RAM (DRAM, SRAM) Interfaces H/W: Ports S/W: Device Driver Parallel, Serial, Analog, Time I/O Memory-mapped vs. I/O-instructions (I/O-mapped) Processor There are two classifications of computers: complex instruction set computer (CISC) and reduced instruction set computer (RISC). In reality, there is a spectrum of architectures that we can classify as CISC or RISC. We make these general observations when deciding whether to call a computer CISC or RISC: Complex instruction set computers (CISC) Early computers offered CPUs that were much faster than available memories. Fetching instructions limited performance A single complex instruction could perform many operations Example: Find the zeros of a polynomial Complex instructions require many processor clock cycles to complete and most instructions can access memory A program running on a CISC computer employed a relatively small number of complex instructions High code density, many instruction types w/ varying length, fewer and specialized registers, many addressing modes Complexity is embedded in the processor hardware (overhead) Examples: Intel (x86), Freescal 9S12 Reduced Instruction Set Computers (RISC) Memories match CPU speed No large penalty for instruction fetch Instructions simplified Example: dedicated load/store instructions, regular instructions can not access memory but only registers Single processor clock cycle per instruction (pipelined) A program running on a RISC computer employs a relatively larger number of simplified instructions Reduced code density, few instructions w/ fixed delay (pipeline!), many identical general-purpose registers, few addressing modes Complexity exists in the assembly code generated by the programmer or compiler, hardware is simple (low overhead/low power) Examples: LC3, MIPS, ARM, SPARC, PowerPC Which architecture is best is beyond the scope of this class, but it is important to recognize the terminology. It is very difficult to compare the execution speed of two computers, especially between a CISC and a RISC. One way to compare is to run a benchmark program on both, and measure the time it takes to execute. Time to execute benchmark = Instructions/program * Average cycles/instruction * Seconds/cycle For example, the 50 MHz ARM Cortex M has one bus cycle every 20ns. One average it may require 1.5 cycles per instruction. If the benchmark program executes 10,000,000 assembly instructions, then the time to execute the benchmark will be 0.3 seconds. Memory: EPROMs are Erasable Programmable ROMs. The mechanism used to erase and write is UV light EEPROMs are Electrically Erasable Flash memory is like EEPROM however writes are performed in large blocks as opposed to single bytes. Cheaper hence popular DRAMs require a periodic refresh SRAMs don’t. Both are volatile therefore are lost when powered down. Interfaces: Parallel - binary data is available simultaneously on groups of lines Serial - binary data is available one bit at a time on a single line Analog - data is encoded as a variable voltage Time - data is encoded as a period, frequency, pulse width or phase shift I/O Memory-mapped I/O I/O ports/registers appear as addresses on common bus with memory I/O ports/registers are accessed as though they are locations in memory Employed on the ARM, Freescale and TI processors I/O-mapped I/O I/O ports/registers have separate control signals from those used with memory Special instructions are used to access I/O ports/registers Employed on Intel x86 processors Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Texas Instruments TM4C123 ARM Cortex-M4 + 256K EEPROM + 32K RAM + JTAG + Ports + SysTick + ADC + UART Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Product Life Cycle Analysis (What?) Implementation(Real) Requirements -> Specifications Design (How?) High-Level: Block Diagrams Engineering: Algorithms, Data Structures, Interfacing Implementation(Real) Hardware, Software Testing (Works?) Validation:Correctness Performance: Efficiency Maintenance (Improve) Requirements are broad and Specifications go into the details. Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Lab 8: Position Measurement System Data Flow Graph Lab 8: Position Measurement System A data flow-graph showing how the position signal passes through the system Rectangles represent h/w components and Ovals represent s/w modules Data flow-graphs give a high-level design of the system showing the flow of “information” Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Position Measurement System Call Flow Graph Position Measurement System Call Flow-Graphs give a high-level detail of the various modules (hardware and software) and their interactions. Normally h/w is passive and software initiates communication between the h/w and s/w. However it is possible for the h/w to initiate communication by using interrupts. The h/w causes an interrupt in response to which an ISR (interrupt service routine) is executed. The Timer ISR in this system gets the next sample from the ADC driver, converts it to a position value and sends it to the LCD driver for display on the LCD h/w. Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Structured Programming Common Constructs (as Flowcharts) The Fork-Join construct is used in Parallel programming. This is different from multi-threading used in concurrent (Distributed) programming. In multi- threading there may be multiple threads that are active but at any given instant only one of them is being executed. In desktop systems that have multiple cores and parallel computers with several processors, multiple threads can be simultaneously executed. Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Flowchart Toaster oven: Coding in assembly and/or high-level language (C) Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

Flowchart 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. < : Hardware Interrupt causing the main program to be suspended and the corresponding ISR to execute > : Return from Interrupt causing the control to be returned to the point where the main program was suspended. The execution sequence of this simple system might be something like: ABCDB<E>CDBC<E>DBCD<E>BCD… We say this code is multi-threaded because we have two threads: The foreground thread computes the primes and the background thread issues a pulse. They are both active at the same time. Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari 18

ARM Cortex M4-based System The LC3 computer from EE 306 had an address space of 64Ki and an addressability of 16-bit for a total of 128KiB. The Memory Address Register (MAR) is 16 bits and the Memory Data Register (MDR) is also 16-bits. Vs. On the ARM, the MAR is still 32-bits. Total addressable memory is 4GiB. It has flexible addressability (bit,byte-8bits,halfword-16bits,word-32bits) ARM Cortex-M4 processor Harvard architecture Different busses for instructions and data Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

ARM Cortex M4-based System RISC machine Pipelining effectively provides single cycle operation for many instructions Thumb-2 configuration employs both 16 and 32 bit instructions The LC3 computer from EE 306 had an address space of 64Ki and an addressability of 16-bit for a total of 128KiB. The Memory Address Register (MAR) is 16 bits and the Memory Data Register (MDR) is also 16-bits. Vs. On the ARM, the MAR is still 32-bits. Total addressable memory is 4GiB. It has flexible addressability (bit,byte-8bits,halfword-16bits,word-32bits) Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

ARM ISA: Thumb2 Instruction Set Variable-length instructions ARM instructions are a fixed length of 32 bits Thumb instructions are a fixed length of 16 bits Thumb-2 instructions can be either 16-bit or 32-bit Thumb-2 gives approximately 26% improvement in code density over ARM Thumb-2 gives approximately 25% improvement in performance over Thumb Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

ARM ISA: Registers, Memory-map The PC points to the address of the current instruction (Program Counter) The Link Register is akin to Register R7 in LC3 used to store the return address on subroutine calls. The stack is a temporary storage implemented in the RAM. We push and pop elements onto and off the stack as we desire. The stack pointer (SP) keeps track of the current location of the “top” of the stack. The CC (condition-code) bits contains codes that reflect the results of the most recent instruction. Many “branch” type instructions “test” these bits for their operation. The Program Status Register (PSR) has them. Condition Code Bit s Indicates N negative Result is negative Z zero Result is zero V overflow Signed overflow C carry Unsigned overflow TI TM4C123 Microcontroller Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

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]] Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

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 Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

LC3 to ARM – Control BR Target ; PC <- Address of Target B Target BRnzp Target ; PC <- Address of 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 Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari

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] Bard, Erez, Gerstlauer, Valvano, Yerraballi

SW Development Environment Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari