ESD Merged CS 01-11
ESD Merged CS 01-11
ESD Merged CS 01-11
Embedded Systems
Design Dept. of Electrical & Devesh Samaiya
BITS Pilani Electronics Engg
Pilani Campus Pilani Campus
BITS Pilani
Pilani Campus
EEE ZG512
Contact Session – I
Purpose of Contact Session
● Performance Evaluation.
A small computing system embedded inside a bigger electro-mechanical system, doing a specific
job, often with real time constraints.
16-bit Microcontrollers
MSP430 by Texas Instruments
32-bit Microcontrollers
AVR32, PIC32, ARM7, ARM Cortex M0, M4, M0+ etc.
Requirement
Analysis
Requirement Definitions
Specifications
Functional Specifications
System
Hardware Design Hardware Architecture Architecture Software Architecture
Software Design
Hardware Software
Implementation Implementation
System Integration
System Validation
WHY?
EEE ZG512
Contact Session – 2
Pre Contact Hour Content
Source - http://www.arachnidlabs.com/blog/2013/02/05/introducing-re-load/
● STM8S003F3P6
● N76E003AT20
● ATmega8A-PU
● and many more…
● Power
○ Voltage ranges in ES.
○ Power Saving Schemes. (Frequency, Idle and Sleep Modes)
● Clock Source
○ Crystal
○ Ceramic Resonators
○ External IC clock generator
● Reset
○ Power on Reset (H/W), External Reset
○ Invalid instructions
○ Clock Monitor
○ Watchdog Timer
libraries
User Level
Kernel Level
system call interface
Hardware Level
actual hardware
● Challenges in ESD
● Application Specific System on Chip
○ Network Connectivity
○ Encryption Requirements
○ Bluetooth / NFC requirements
○
EEE ZG512
Contact Session – 3
ARM Architecture
Comparisons 13%
Logical operations 5%
Other 1%
http://infocenter.arm.com/help/topic/com.arm.doc.ddi0210c/DDI0210B.pdf
BITS Pilani, Pilani Campus
Datapath Activities during Data Processing Instructions
All ARM instructions are four bytes long (one 32-bit word) and are
always aligned on a word boundary. This means that the bottom two
bits of the PC are always zero, and therefore the PC contains only
30 non-constant bits.
Most application programs execute in User mode. While the processor is in User mode,
the program being executed is unable to access some protected system resources or to
change mode, other than by causing an exception to occur.
This allows a suitably written operating system to control the use of system resources
EEE ZG512
Contact Session – 4
ARM assembly Language Programming
ARM instruction types
n = i ROR ( 2* r)
AND r0, r1, r2 implies r0[i] = r1[i] AND r2[i] for i ranging from 0 to 31.
Register Movement Operations
Register Movement Operations
Comparison Operations
LSL - Logical Shift Left; fill the vacated bits with zeros
LSR - Logical Shift Right; fill the vacated bits with zeros
ASR - Arithmetic Shift Right; fill the vacated bits with 0 if operand was positive else with 1
ROR - Rotate Right by 0 to 32 places; the bit which falls off the LSB will fill the vacated bits
RRX - Rotate Right extended by 1 place; the vacated bit (bit 31) is filled with the old value of
the C flag and the operand is shifted one place to the right. With appropriate use of the
condition codes (see below) a 33-bit rotate of the operand and the C flag is performed.
Data Transfer Instructions
Restoring context
LDMFD r13!, {r0 - r2, pc}
Block Data Transfer
Rn tmp
2 3
Rm
Rd
Binary Semaphore Using SWP
spin
mov r1, =semaphore
mov r2, #1
swp r3, r2, [r1] ; hold the bus until complete
cmp r3, #1
beq spin
Exceptions
The ARM architecture supports a range of interrupts, traps and supervisor calls,
all grouped under the general heading of exceptions. They are all handled in
similar way :
1. The current state is saved by copying the PC into R14_exc and the CPSR into
SPSR_exc (where exc stands for the exception type).
2. The processor operating mode is changed to the appropriate mode. ARM
processor mode can also be changed by changing the CPSR.
3. The PC is forced to a value between 0x00 to 0x1C, the particular value
depending on the type of exception. Usually the address of an exception
handler will be located into those values.
4. It disables IRQs by setting bit 7 of the CPSR and if it’s FIQ, disables further
FIQs by setting bit 6 of CPSR.
When an exception occurs the ARM processor always switches to ARM state.
VECTOR TABLE
Once the exception has been handled, the user task is normally
resumed. This requires the handler code to restore the user state
exactly as it was when the exception first arose:
EEE ZG512
Contact Session – 5
Keil ARM MDK Demo for ARM assembly
Language Programming
ASM Example Code
One should use 32-bit data type and avoid using char or short
wherever possible. If you requires modulo arithmetic of the form
255+1 = 0, then use the char type.
Compiler Output with ‘i’ as char
Compiler output with ‘i’ as integer
Expressions in C
EEE ZG512
Contact Session – 5
LPC2xxx
Analog to Digital Demo
ADC in LPC2xxx Series
#define CLKDIV 6
return(val>>6);
Timer Demo -1 Accurate Delay Function
◆ Toggle on match.
◆ Do nothing on match
STEP- 1 Understanding Timer Modes
EEE ZG512
Contact Session – 6
Serial Peripheral Interface
LPC2xxx SoC
Introduction
SPI is a full duplex serial interface.
It can handle multiple masters and slaves being connected to a given bus.
Only a single master and a single slave can communicate on the interface during a given
data transfer.
During a data transfer the master always sends 8 to 16 bits of data to the slave, and the
slave always sends a byte of data to the master.
Ring Buffer
SPI data to CPOL, CPHA relationship
SPI CPOL, CPHA Significance (AT93C46 EEPROM)
http://ww1.microchip.com/downloads/en/DeviceDoc/doc5140.pdf
The Read (READ) instruction contains the address code for the memory location to be read.
After the instruction and address are decoded, data from the selected memory location is
available at the serial output pin DO. Output data changes are synchronized with the rising
edges of serial clock SK.
SPI CPOL, CPHA Significance (W25Q64 FLASH)
https://www.winbond.com/resource-files/w25q64fw_revk%2007012
READ instruction (03h) is initiated by driving the CS pin low and shifting out instruction (03h)
and 24-bit address (A23-A0) on DI pin.The instruction code and address bits are latched on the
rising edge of the CLK input. Data is shifted out on DO at falling edge of the CLK pin.
016%20sfdp.pdf
SPI0 Registers in LPC2148
MASTER OPERATION
The following sequence describes how one should process a data transfer with the SPI block when it
is set up to be the master. This process assumes that any prior data transfer has already completed
1. Set the SPI clock counter register to the desired clock rate.
2. Set the SPI control register to the desired settings.
3. Write the data to transmitted to the SPI data register. This write starts the SPI data
transfer.
4. Wait for the SPIF bit in the SPI status register to be set to 1. The SPIF bit will be set
after the last cycle of the SPI data transfer.
5. Read the SPI status register.
6. Read the received data from the SPI data register (optional).
7. Go to step 3 if more data is required to transmit.
SLAVE OPERATION
The following sequence describes how one should process a data transfer with the SPI block when it
is set up to be a slave. This process assumes that any prior data transfer has already completed. It is
required that the system clock driving the SPI logic be at least 8X faster than the SPI.
Source - https://www.diodes.com/assets/Datasheets/74HC595.pdf
2
I C Protocol
[email protected]
I2C
Developed by Philips Semiconductor (now NXP) as a simple bidirectional two wire bus
protocol for efficient inter-IC data communication. Originally, the I2 C bus was designed to
link a small number of devices on a single card, such as to manage the tuning of a car radio
or TV.
This bus is called the Inter IC or I2C-bus. All I2C-bus compatible devices incorporate an
on-chip interface which allows them to communicate directly with each other via the
I2C-bus.
Features
➔ Only two bus lines are required; a serial data line (SDA) and a serial clock line (SCL).
➔ Each device connected to the bus is software addressable by a unique address and
simple master/slave relationships exist at all times; masters can operate as
master-transmitters or as master-receivers.
➔ It is a true multi-master bus including collision detection and arbitration to prevent
data corruption if two or more masters simultaneously initiate data transfer.
➔ Serial, 8-bit oriented, bidirectional data transfers can be made at up to 100 kbit/s in
the Standard-mode, up to 400 kbit/s in the Fast-mode, up to 1 Mbit/s in Fast-mode
Plus, or up to 3.4 Mbit/s in the High-speed mode.
Pg. 4 https://www.nxp.com/docs/en/user-guide/UM10204.pdf
SDA & SCL Signals
Both SDA and SCL are bidirectional lines, connected to a positive supply voltage via a
current-source or pull-up resistor. When the bus is free, both lines are HIGH.
SDA & SCL Signal Levels
➔ Due to the variety of different technology devices (CMOS, NMOS, bipolar)
that can be connected to the I2C-bus, the levels of the logical ‘0’ (LOW) and
‘1’ (HIGH) are not fixed and depend on the associated level of VDD.
➔ Input reference levels are set as 30 % and 70 % of VDD; VIL is 0.3VDD and
VIH is 0.7VDD.
START & STOP conditions
➔ All transactions begin with a START (S) and are terminated by a STOP (P).
➔ A HIGH to LOW transition on the SDA line while SCL is HIGH defines a START
condition.
➔ A LOW to HIGH transition on the SDA line while SCL is HIGH defines a STOP
condition.
DATA Validity
➔ The data on the SDA line must be stable during the HIGH period of the clock.
➔ The HIGH or LOW state of the data line can only change when the clock signal on
the SCL line is LOW .
➔ One clock pulse is generated for each data bit transferred.
Byte format
➔ Every byte put on the SDA line must be eight bits long.
➔ The number of bytes that can be transmitted per transfer is unrestricted.
➔ Each byte must be followed by an Acknowledge bit.
➔ Data is transferred with the Most Significant Bit (MSB) first.
➔ If a slave cannot receive or transmit another complete byte of data until it has
performed some other function, for example servicing an internal interrupt, it can
hold the clock line SCL LOW to force the master into a wait state. Data transfer then
continues when the slave is ready for another byte of data and releases clock line
SCL.
ACK / NACK
➔ The acknowledge takes place after every byte. The acknowledge bit allows the
receiver to signal the transmitter that the byte was successfully received and another
byte may be sent. The master generates all clock pulses, including the acknowledge
ninth clock pulse.
➔ The transmitter releases the SDA line during the acknowledge clock pulse so the
receiver can pull the SDA line LOW and it remains stable LOW during the HIGH
period of this clock pulse.
➔ When SDA remains HIGH during this ninth clock pulse, this is defined as the Not
Acknowledge signal. The master can then generate either a STOP condition to abort
the transfer, or a repeated START condition to start a new transfer.
ACK / NACK
There are five conditions that lead to the generation of a NACK:
1. No receiver is present on the bus with the transmitted address so there is no device to
respond with an acknowledge.
3. During the transfer, the receiver gets data or commands that it does not understand.
4. During the transfer, the receiver cannot receive any more data bytes.
5. A master-receiver must signal the end of the transfer to the slave transmitter.
Slave address and R/W’ bit
After the START condition (S), a slave address is sent. This address is seven bits long
followed by an eighth bit which is a data direction bit (R/W) — a ‘zero’ indicates a
transmission (WRITE), a ‘one’ indicates a request for data (READ).
Master Transmitter
Master Receiver
Master Transceiver
Arbitration
Arbitration, refers to a portion of the protocol required only if more than one master is
used in the system.
A master may start a transfer only if the bus is free. Two masters may generate a START
condition on the bus at the same time. Arbitration is then required to determine which
master will complete its transmission.
Arbitration
Arbitration proceeds bit by bit. During every bit, while SCL is HIGH, each master checks
to see if the SDA level matches what it has sent.
This process may take many bits. Two masters can actually complete an entire transaction
without error, as long as the transmissions are identical.
The first time a master tries to send a HIGH, but detects that the SDA level is LOW, the
master knows that it has lost the arbitration and turns off its SDA output driver. The other
master goes on to complete its transaction.
I2C Protocol Summary
I2C in LPC2xxx
➔ Standard I2C compliant bus interfaces that may be configured as Master or Slave.
➔ Arbitration between simultaneously transmitting masters without corruption of serial
data on the bus.
➔ Programmable clock to allow adjustment of I2C transfer rates.
➔ Serial clock synchronization allows devices with different bit rates to communicate
via one serial bus.
I2C Bus configuration
I2C Operating Modes
➔ In a given application, the I2C block may operate as a master, a slave or both.
➔ If processor wishes to become the bus master, the hardware waits until the bus is free
before the master mode is entered so that a possible slave operation is not interrupted.
➔ If bus arbitration is lost in the master mode, the I2C block switches to the slave mode
immediately and can detect its own slave address or general call address in the same
serial transfer.
Master Transmitter Mode
http://www.usb.org/developers/defined_class
Master Slave
➔ USB is a master slave protocol.
➔ Host is the master and all the communication on the bus is initiated by the Host.
➔ There can be no communication directly between 2 USB devices.
➔ A device cannot initiate a transfer, but must wait to be asked to transfer data by the
host. The only exception to this is when a device has been put into 'suspend' (a low
power state) by the host then the device can signal a 'remote wakeup'.
Bus enumeration
➔ The host regularly polls hubs for their status.
➔ When a new device is plugged into a hub, the hub advises the host of its
change of state.
➔ The host controller in turn issues a command to enable and reset the port.
➔ Device responds and host collects information about the device.
➔ Based on the retrieved information, the host operating system determines the
device driver to be used for the device.
➔ The process of detection and identification of USB devices by a host is called
bus enumeration.
Transactions
REF : http://www.usbmadesimple.co.uk/ums_3.htm
Packet Formats 1/4
Packet ID (PID) : The first byte in every
packet is a Packet Identifier (PID) byte.
This byte needs to be recognised quickly
by the USB engine and so is not included
in any CRC checks. It therefore has its
own validity check. The PID itself is 4
bits long, and the 4 bits are repeated in an
complimented form.
Packet Formats 2/4
Token Packet : Used for SETUP, OUT and IN packets. They are always the first packet in
a transaction, identifying the targeted endpoint, and the purpose of the transaction
8 bits
CONTROL
INTERRUPT
BULK
ISOCHRONOUS
CONTROL ENDPOINT
➔ Control endpoints are used to allow access to different parts of the USB
device.
➔ They are commonly used for configuring the device, retrieving information
about the device, sending commands to the device, or retrieving status reports
about the device.
➔ Every USB device has a control endpoint called "endpoint 0" that is used by
the USB core to configure the device at insertion time.
➔ These transfers are guaranteed by the USB protocol to always have enough
reserved bandwidth to make it through to the device.
CONTROL TRANSFER
It is divided into three stages.
1. The SETUP stage carries 8 bytes called the Setup packet. This defines the request,
and specifies whether and how much data should be transferred in the DATA stage.
2. The DATA stage is optional. If present, it always starts with a transaction containing a
DATA1. The type of transaction then alternates between DATA0 and DATA1 until all
the required data has been transferred.
3. The STATUS stage is a transaction containing a zero-length DATA1 packet. If the
DATA stage was IN then the STATUS stage is OUT, and vice versa.
Control transfers are used for initial configuration of the device by the host, using Endpoint 0 OUT and Endpoint 0
IN, which are reserved for this purpose. They may be used (on the same endpoints) after configuration as part of the
device-specific control protocol, if required.
CONTROL TRANSFER
REF : http://www.usbmadesimple.co.uk/ums_3.htm
SETUP PACKET
Possible bRequest types in control transaction
INTERRUPT ENDPOINT
➔ They have nothing to do with interrupts.
➔ Interrupt endpoints transfer small amounts of data at a fixed rate every time the
USB host asks the device for data.
➔ These endpoints are the primary transport method for USB keyboards and
mice.
➔ They are also commonly used to send data to USB devices to control the
device, but are not generally used to transfer large amounts of data.
➔ These transfers are guaranteed by the USB protocol to always have enough
reserved bandwidth to make it through.
BULK ENDPOINTS
➔ Bulk endpoints transfer large amounts of data.
➔ These endpoints are usually much larger (they can hold more characters at
once) than interrupt endpoints.
➔ They are common for devices that need to transfer any data that must get
through with no data loss. These transfers are not guaranteed by the USB
protocol to always make it through in a specific amount of time.
➔ If there is not enough room on the bus to send the whole BULK packet, it is
split up across multiple transfers to or from the device. These endpoints are
common on printers, storage, and network devices.
ISOCHRONOUS ENDPOINT
➔ Interfaces usually have one or more settings which are specified in the
Interface descriptor.
➔ Finally Interfaces have zero or more endpoint and each endpoint is described
using Endpoint descriptor structure.
USB
DEVICE DESCRIPTOR
STRUCTURE
USB Configuration Descriptor Format
USB Interface Descriptor
USB
ENDPOINT
DESCRIPTOR
FORMAT
USB Frames and Microframes
➔ USB defines a full-speed 1 ms frame time indicated by a Start Of Frame (SOF)
packet each and every 1ms period.
➔ USB also defines a high-speed microframe with a 125 μs frame time
➔ SOF packets are generated (by the host controller) every 1ms for full-speed
links.
USB is a host controlled protocol. Irrespective of whether the data transfer is from device
to host or host to device, transfer sequence is always initiated by the host.
During data transfer from device to the host, the host sends an IN token to the device,
following which the device responds with the data.
USB device peripheral in LPC2148
• Fully compliant with USB 2.0 Full Speed specification
• Supports 32 physical (16 logical) endpoints
• Supports Control, Bulk, Interrupt and Isochronous endpoints
• Endpoint Maximum packet size selection (up to USB maximum specification) by software at run time
• RAM message buffer size based on endpoint realization and maximum packet size
• Supports Soft Connect feature and Good Link LED indicator
• Supports bus-powered capability with low suspend current
• Support DMA transfer with the DMA RAM of 8 kB on all non-control endpoints (LPC2146/8 only)
• One Duplex DMA channel serves all endpoints
• Allows dynamic switching between CPU controlled and DMA modes
• Double buffer implementation for Bulk & Isochronous endpoints
LPC2148: USB Device Controller
➔ The device controller enables 12 Mb/s data exchange with a USB host controller.
➔ It consists of register interface, serial interface engine, endpoint buffer memory and
DMA controller.
➔ The serial interface engine decodes the USB data stream and writes data to the
appropriate endpoint buffer memory.
➔ The status of a completed USB transfer or error condition is indicated via status
registers. An interrupt is also generated if enabled.
➔ The DMA controller when enabled transfers data between the endpoint buffer and the
USB RAM.
Pre-fixed Endpoint Configuration
Pre-fixed Endpoint Configuration
USB Peripheral Device Block
Data flow from Host to Device
➔ The USB device protocol engine receives the serial data from the USB analog
transceiver and converts it into a parallel data stream.
➔ The parallel data is sent to the RAM interface which in turn transfers the data to the
endpoint buffer.
➔ The endpoint buffer is implemented as an SRAM based FIFO. Each realized endpoint
will have a reserved space in the RAM.
➔ So the total RAM space required depends on the number of realized endpoints,
maximum packet size of the endpoint and whether the endpoint supports double
buffering.
Data Flow
➔ For non-isochronous endpoints, when a full data packet is received without any
errors, the endpoint generates a request for data transfer from its FIFO by generating
an interrupt to the system.
➔ Isochronous endpoint will have one packet of data to be transferred in every frame. So
the data transfer has to be synchronized to the USB frame rather than packet arrival.
So, for every 1 ms there will be an interrupt to the system.
➔ The data transfer follows the little endian format. The first byte received from the
USB bus will be available in the least significant byte of the receive data register.
Data Flow from Device to Host
➔ For data transfer from an endpoint to the host, the host will send an IN token to that
endpoint. If the FIFO corresponding to the endpoint is empty, the device will return a
NAK and will raise an interrupt to the system.
➔ On this interrupt the CPU fills a packet of data in the endpoint FIFO. The next IN
token that comes after filling this packet will transfer this packet to the host.
➔ The data transfer follows the little endian format. The first byte sent on the USB bus
will be the least significant byte of the transmit data register.
Software Interface
Software interface of the USB device block consists of a register view and the format
definitions for the endpoint descriptors.
A few important registers
USB Endpoint Interrupt Status register (USBEpIntSt - 0xE009 0030)
Each physical non-isochronous endpoint is represented by one bit in this register to
indicate that it has generated the interrupt.
USB Endpoint Interrupt Status register (USBEpIntSt - 0xE009 0030)
➔ All non-isochronous OUT endpoints give an interrupt when they receive a packet
without any error.
➔ All non-isochronous IN endpoints will give an interrupt when a packet is successfully
transmitted or a NAK handshake is sent on the bus provided that the interrupt on
NAK feature is enabled.
➔ Isochronous endpoint transfer takes place with respect to frame interrupt. The
USBEpIntSt is a read only register.
➔ All these interrupts can be enabled or disabled using USBEpIntEn and USBEpIntClr
registers respectively
USB Realize Endpoint register (USBReEp - 0xE009 0044)
➔ Though fixed-endpoint configuration implements 32 endpoints, it is not a must that all
have to be used. If the endpoint has to be used, it should have buffer space in the
EP_RAM.
➔ The EP_RAM space can be optimized by realizing a subset of endpoints.
➔ This is done through programming the Realize Endpoint register. Each physical
endpoint has one bit as shown below. The USBReEp is a read/write register
Virtual COM Port Device (Vendor Specific)
Virtual COM port driver allows your PC to recognize and communicate with the remote
target as a COM port regardless the under-layer hardware connection between the PC and
target system.
For example, if the LPC2148 is programmed as a COM port device, actual connection is
through USB but it will appear to the PC as a COM port. When the USB cable is
connected, the target looks like a real serial port communicating with the PC Hyper
Terminal Software on the Windows platform.
1. Reset,
2. Enumeration, and
3. Operation phase.
USB reset phase
➔ The USB device will be in the reset phase after power-on reset.
➔ When the USB device is attached to the PC USB host, the host will issue a reset
signal.
➔ When a USB reset signal is detected on the bus, on the device side, the DEV_STAT
bit in the Device Interrupt Register is set and a USB interrupt will be generated.
➔ The USB device will process the RESET interrupt and set itself to the default
configuration state. The initial address of the USB device is set to zero at reset phase.
➔ After the reset signal is released and RESET interrupt has been processed, the device
will enter the enumeration phase.
USB enumeration and standard requests
➔ During the enumeration phase, the host performs a bus enumeration to identify the
attached devices by sending a series of requests on the control pipe (endpoint 0 OUT)
using standard device request to get the device information and configuration, and
then, assign a unique address to it.
➔ Based on the information it gets, if necessary, send SET_FEATURE,
SET_CONFIGURATION, and/or SET_INTERFACE requests to reconfigure the
device.
➔ The device responds to the host requests on its default control pipe (endpoint 0 IN).
Endpoint configuration for virtual COM port
In the virtual COM port device driver implementation, more than one interface descriptors
can be created to accommodate multiple virtual COM ports.
Under each interface descriptor, vendor specific class code (0xFF) has been chosen.
Endpoint configuration for virtual COM port
Interface number EP Number (Physical Description
Endpoint, type)
As seen in the second column of above table, 0x41 indicates the direction of the setup
request is from host to device (bit 7 is 0), the type is “vendor” (bit 6 and 5 is 10b), and the
recipient is “interface” (bit 4 through 0 is 00001b). Finally, the SETUP request is to set the
baud rate of the COM port 0 at 9600.
The index and length fields in the vendor specific interface request table are defined but not
used. They are reserved for future expansion.
Initialization
➔ After the power up, the USB initialization should include below steps:
➔ Turn on USB PCLK
➔ Configure 48Mhz PLL1 for USB clock
➔ Setup Vectored Interrupt Controller (VIC) for USB
➔ Set up minimum numbers of USB registers including index and packet size register
for Control OUT (0) and Control IN (1) endpoints.
➔ Set USB Device Interrupt Enable register
➔ Use protocol engine commands SET_ADDRESS to reset device address to zero, and
SET_DEVICE_STATUS to make a soft connection
LPC2148 USB Command Code register (USBCmdCode - 0xE009 0010)
➔ This is a read-only register which will carry the data retrieved after executing a
command.
➔ When this register is ready, the “CD_FULL” bit of the Device Interrupt Status register
is set. The CPU can poll this bit or enable an interrupt corresponding to this to sense
the arrival of the data.The data is always one-byte wide
LPC2148 Protocol Engine Commands
➔ The protocol engine operates based on the commands issued from the CPU.
➔ These commands have to be written into the Command Code register
➔ The read data when present will be available in the Command Data register after the
successful execution of the command.
When the CPU has written data into an IN buffer, it should set the buffer full flag by
the Validate Buffer command. This indicates that the data in the buffer is valid and
can be sent to the host when the next IN token is received
Set Address (Command: 0xD0, Data: write 1 byte)
➔ The Set Address command is used to set the USB assigned address and enable the
(embedded) function.
➔ The address set in the device will take effect after the status phase of the setup token.
(Alternately, issuing the Set Address command twice will set the address in the
device).
➔ At power on reset, the DEV_EN is set to 0. After bus reset, the address is reset to
0x00. The enable bit is set to 1. The device will respond on packets for function
address 0x00, endpoint 0 (default endpoint).
Configure Device (Command: 0xD8, Data: write 1 byte)
A value of 1 written to the register indicates that the device is configured and all the
enabled non-control endpoints will respond. Control endpoints are always enabled and
respond even if the device is not configured, in the default state.
Refer to section 14.9 in UM10139 document for all the different command codes and their purposes.
LPC2148 USB LAB Demo :Class Specific Drivers
➔ To implement a CDC (Communication Device Class) with subclass 0x02
device.
➔ Windows has inbuilt USB Serial driver called USBSer.sys.
➔ USBSer.sys enumerates with the attached device as per the USB CDC
subclass 2 protocol.
➔ Our device must be programmed to respond to those requests.
So, for class specific device drivers, our device must respond to both standard requests and
class specific requests. It must provide class specific descriptors when asked to and
respond to class specific request coming via setup packet.
USB CDC Class
The Communication Device Class (CDC) supports a wide range
of devices that can perform telecommunications and networking
functions. Examples for communications equipment are:
● Telecommunications devices, such as analog phones and
modems, ISDN terminal adapters, digital phones, as well as
COM-port devices
● Networking devices, such as ADSL and cable modems, as well
as Ethernet adapters and hubs
CDC Subclasses
Class Specific Descriptors
Class-Specific Device Descriptor
This descriptor contains information applying to the entire communication device. The
Communication Device Class does not currently use any class-specific descriptor
information at the Device level.
➔ The host sends and receives data by sending and requesting reports in control or
interrupt transfers. The report format is flexible and can handle just about any type of
data.
➔ A HID must have an interrupt IN endpoint for sending Input reports.
➔ A HID can have at most one interrupt IN endpoint and one interrupt OUT endpoint. A
device that requires more interrupt endpoints can be a composite device with multiple
HID interfaces. An application obtains separate handles for each HID in the device
➔ The interrupt IN endpoint enables the HID to send information to the host at
unpredictable times. For example, there’s no way for the host computer to
know when a user will press a key on the keyboard, so the host’s driver uses
interrupt transactions to poll the device periodically to obtain new data.
HID Class Descriptor
HID Report Descriptor 1/3
A report descriptor is a class-specific descriptor. The host
retrieves the descriptor by sending a Get Descriptor request
to the interface with the wValue field containing 22h in the
high byte.
● The Report Size item indicates how many bits are in each
reported data item. In the example, each data item is eight
bits. The Report Count item indicates how many data
items the report contains. In the example, each report
contains two data items
HID Report Descriptor 3/3
● In the final item, the first byte specifies whether the report
is an Input report (81h), Output report (91h), or Feature
report (B1h). The second byte contains additional
information about the report data, such as whether the
values are relative or absolute.
Table below shows supported values for Input, Output, and Feature items. Each
item has a 1-byte prefix followed by 1 or 2 bytes that describe the report data.
Similar tables
are there for
output and
feature report
data.
Data | Constant. Data means that the contents of the item are modifiable (read/write).
Constant means the contents are not modifiable (read-only).
Array | Variable. This bit specifies whether the data reports the state of every control
(Variable) or just reports the states of controls that are asserted, or active (Array).
Reporting only the asserted controls results in a more compact report for devices such as
keyboards that have many controls (keys) but where only one or a few controls are
asserted at the same time.
Absolute | Relative. Absolute means that the value is based on a fixed origin. Relative
means that the data indicates the change from the last reading. A joystick normally reports
absolute data (the joystick’s current position), while a mouse reports relative data (how far
the mouse has moved since the last report).
Example from USB Lab
HID Specific Requests
That’s all !
Motion, Mechanisms &
Human Interface Devices
Interfacing Motion Related Devices
➔ Linear
➔ Rotational
Linear motion can be generated using rotational motion using arrangement of gears.
Solenoid based magnetic devices can also be used to generate short range linear motion.
Linear Motor
Kind of Motors usually found in electronic systems
DC Motors
Useful when continuous rotation at high torque, high RPM is required.
Stepper Motors
Useful for applications where precise angular motion is required in equal size steps.
Comes in variety of torque and step angles.
Servo Motors
Feedback based motor control, used to design highly accurate movements.
DC Motor Interfacing
➔ Works on DC voltages with RPM proportional to applied voltage.
➔ Direction can be controlled by changing the polarity of applied voltage.
➔ Require high current to drive and act as inductive load.
DC Motor Interfacing
➔ Microcontroller pins can not supply current required to drive different variety of DC
motors. Depending on the RPM and torque of the motor it may require current of up
to 10s of Amps to drive.
➔ Special motor driver circuits are required to drive these motors.
➔ Driver can control direction and speed of the motor.
➔ How to design motor drivers?
Direction Control
Speed control using PWM
Stepper Motor
Translates electrical pulses into mechanical movement. Provides precise motion control
but no awareness of shaft position. Open loop control. You can control how many step you
want to rotate but you can not control the absolute angle of the shaft from where the
rotation will begin.
Servo Motor
➔ DC motor with shaft position feedback.
➔ Closed loop control.
Typical Servo control PWM pulse
Human Interface Devices
Touch Panels
● Single touch (resistive) or multitouch (capacitive)
● Resistive touch screen are easy to interface. Can be driven using 2 or more
ADC channels.
● Capacitive touch panels are more complex to interface and often required
specialized driver ICs for integration into the system.
● Validation Algorithm
● Validation Algorithm
● Validation Algorithm
● Communication
● LCD display
● User Buttons
● Dial Wheel
● Remote Control IR
● Bluetooth App control
Design Example - 2 Customized MP3 players
● Music Selection
● Music Selection
Example - JQ6500
WTV020-SD etc.
Example - JQ6500