CSE190 Winter 2020 Lecture 2 MCUs and IO Wireless Embedded Systems
29 Slides3.22 MB
CSE190 Winter 2020 Lecture 2 MCUs and IO Wireless Embedded Systems Aaron Schulman
Reading for next week Posted on Website – Please skim. – “ARM Cortex-M for Beginners”
Introduction to Microcontrollers
Introduction to Microcontrollers A microcontroller (MCU) is a small computer on a single integrated circuit consisting of a relatively simple central processing unit (CPU) combined with peripheral devices such as memories, I/O devices, and timers. – By some accounts, more than half of all CPUs sold worldwide are microcontrollers
Die shot of a microcontroller
Microcontroller VS Microprocessor A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. A microprocessor incorporates the functions of a computer’s central processing unit (CPU) on a single integrated circuit.
Microcontroller VS Microprocessor
Types of Processors In general-purpose computing, the variety of instruction set architectures today is limited, with the Intel x86 architecture overwhelmingly dominating all. There is no such dominance in embedded computing. On the contrary, the variety of processors can be daunting to a system designer. Things that matter – Peripherals, Concurrency & Timing, Clock Rates, Memory sizes (SRAM & flash), Package sizes
Types of Microcontrollers
How to choose MCU for our project? What metrics we need to consider? – Power consumption – Clock frequency – IO pins – Memory – Internal functions – Others
How to choose MCU for our project? What metrics we need to consider? – Power consumption We cannot afford mA MCU because the power budget of the system is 3.47mA. – Clock frequency (speed that instructions are executed) kHz is too slow 100MHz is over kill. – IO pins Lots of peripherals - Image sensor, UART debugger, SD card, DAC, ADC, microphone, LED
How to choose MCU for our project? What metrics we need to consider? – Memory We need to have sufficient memory to store: – Program (Non-volatile): Logic to read from sensors, communicate – Stack: Function calls are now expensive (no recursion) – Data: Constants (time periods), Sensor history, Communication state – Internal functions Migrating data from the sensor to the radio (DMA)
How to choose MCU for our project? Memory – Store accelerometer history data 12bits each for X,Y,Z acceleration sampled 2 thousand times a second (2 KHz) 12*3*2,000 bits per second (72kbits or 9 kBytes) How many seconds can we hold if we have only 100 kBytes of storage – What types of memory are available on an MCU? Internal memory: RAM, 0.5 128 kBytes External memory: Flash, high power consumption, 5mA for read and 10mA for erase
How to choose MCU for our project? Clock frequency – kHz is too slow Smartphone camera frame rate is 60fps (1 KHz clock would leave only 60 clock cycles per frame) – 100MHz is too fast Power consumption is high – Several MHz would be ideal
How to choose MCU for our project? IO pins (interface for external peripherals) – Interfacing sensors, UART debugger, LEDs, Bluetooth – We need a large number of IO pins – We need various types of IO pins Analog pins (input/output analog signals e.g., audio) Digital pins (input/output digital signals e.g., busses, GPIOs)
The MCU used in our projects
Input and Output (I/O)
I/O Devices (sensors) Keyboard, mouse, microphone, scanner, video/photo camera, etc. Large diversity – Many widely differing device types – Devices within each type also differs Speed – varying, often slow access & transfer compared to CPU – Some device-types require very fast access & transfer Access – Sequential VS random – read, write, read & write
What operations does software need to perform on peripherals? 1. Get and set parameters 2. Receive and transmit data 3. Enable and disable functions
How can we imagine providing an interface to hardware from software? 1. Specialized CPU instructions (x86 in/out)
Port I/O Port I /O Devices mapped onto “ports”; a Devicesregisters registers mapped onto “ports”; separate address a separate addressspace space memory I/O ports Use special I/O instructions to read/write ports Use special I/O instructions to read/write ports Protected by making I/O instructions available Protected by making I/O instructions only in kernel/supervisor mode available only in kernel/supervisor mode Used for example by IBM 360 and successors Used for example by IBM 360 and successors
How can we imagine providing an interface to hardware from software? 1. Specialized CPU instructions (x86 in/out) 2. Treating devices like they are memory (MMIO)
Memory Mapped IO Memory Mapped I/ O Device registers mapped into regular address space Device registers mapped into regular address space memory memory mapped I/O Use regular move (assignment) instructions to Use read/ writemove registers regular (assignment) instructions to read/ write a device’s hardware “registers” Use memoryprotection protection mechanism mechanism to Use memory toprotect protect device registers device registers Used for example by PDP-11
MMIO is used for embedded systems Why not Ports I/O? – special I/O instructions would be instruction set dependent (x86, ARM Thumb, MIPS) Bad if there are many different instruction sets out there – Need special hardware to execute and protect instructions Memory mapped I/O: – Can use all existing memory reference instructions for I/O Can reuse code for reading and writing (e.g., memcpy) – Memory protection mechanism allows greater flexibility than protected instructions (protect specific registers) – Can reuse memory management / protection hardware to interface with hardware (saves space and power)
Reading and writing with MMIO is not like talking to RAM MMIO reads and writes hardware device registers Reads and write to registers can cause peripherals to begin or end an operation By reading data, it may cause the hardware to do something!!! – E.g., Clear an interrupt flag, get the next byte on a bus By writing data, it may cause the hardware to do something with it – E.g., Send this data over the UART bus
GPIOs are the general digital I/O device Each GPIO pin represents one bit in memory: if the pin is on it’s a 1, off it’s a 0 That bit can be an input or an output GPIOs can be used to control lights (light on or off), but even more Indicating that an event just happened – Interrupt the radio to tell it to transmit data – Interrupt the CPU to tell it a button was pressed – Read pin status to receive configuration messages Debugging – Did this one part of my code actually execute? – Is the timer firing at the interval that I expect it to fire (connect GPIO to oscilloscope)? – Why using GPIO? GPIO ops are lightweight
Topology of a GPIO pin
GPIO Configurations
A fun extra feature: Drive Strength