Vous êtes sur la page 1sur 39

FACULTÉ DES

SCIENCES DE
TUNIS

SYSTÈME
EMBARQUÉ
PÉRIPHÈRIQUE
USB
Cha i ma KHALUAOUI
V1.0
OBJECTIFS

Rappeler CONNAITRE COMPRENDRE ETRE CAPABLE DE

l’hystorique de l’usb et Les notions de base La procédure Programmer des


quelques notions de d’un stm32 USB de programmation exemple
base . d’un USB applicatifs du USB

2
UNIVERSAL SERIAL BUS

Universal Serial Bus ( USB ) est une norme industrielle créée en


1996 , elle permet :
• la connexion
• la communication
• l'alimentation des périphériques électroniques

L'USB simplifie la connectivité entre les ordinateurs et une large


gamme de périphériques.
• (les claviers, les souris, les disques durs, les imprimantes, les
caméras, les smartphones ... .)

3
CARACTÉRISTIQUES

Hot Pluggable OUI

Protocol Serial,Pooled,Host-Centric

Bitrate 1.5/12/480/5,000/10,000/20,000 Mbit/s

Max length 5m

MAX Voltage 5v(without pd)

0.5A genral
0.1A from usb-powre HUB
Max Current
5A charging device
Up to 100W over USB-c power delivery

Max Devices 127

4-5 (USB 2.0)


Pins 1 supply , 2 data , 1 ground
(optional ID )
4
Topologie Tired Star
HISTORIQUE DE L’USB

1996 2000 2008


USB 1.0 / 1.1 USB 2.0 USB 3.0 / 3.1 Gen 1
1.5 Mbit/s (Low-Speed) 480 Mbit/s (High-Speed) 5 Gbit/s (SuperSpeed)
12 Mbit/s (Full-Speed)

2019 2017 2013


USB 4.0 USB 3.2 USB 3.1 Gen 2
10 Gbit/s (SuperSpeed+) 20 Gbit/s (SuperSpeed+) 40 Gbit/s (SuperSpeed+)

5
TIRED STAR TOPOLOGY

HOST

Device Device

HUB

Device Device HUB

6
Device Device Device
FLUX DE LA COUCHE
PHYSIQUE

Otput packet Bit stuffing NRZI Output Driver

USB cable

Input Driver Reverse NRZI Reverse Bit stuffing Input packet

8
BIT STUFFING

• Insérer 0 après six 1 consécutifs

0 1 0 0 1 1 1 1 1 1 0 1 1

0 1 0 0 1 1 1 1 1 0 1 0 1 1

9
NRZI(NO RETURN TO ZERO
INVERTED)

• Basculer la valeur de tension pour 1

• Garder la valeur de tension pour 0

0 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0
Data

NRZI J
k
10
NRZI(NO RETURN TO ZERO
INVERTED)

• Basculer la valeur de tension pour 1

• Garder la valeur de tension pour 0

0 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0
Data

NRZI J
k

11
ÉLECTRIQUEMENT

• USB c’est un protocol série qui comporte 4 fils (pour le USB 2.0)
*2 pour l’alimentation (VBUS et GND)
*2 pour les données (D+ et D-)

VBUS VBUS
D+ D+
D- D-
GND GND

12
USB BUS
State

1 Differetiel 1 5 Data J 9 Disconnect


D+ High, D- low low Speed :Differetiel 0 SE0 for mor
Full Speed :Differetiel 1
than 2us

2 Differetiel 0 6 Data K
D- High, D+ low low Speed :Differetiel 1 10 Connect
Full Speed :Differetiel 0
idle for more
than 2.5 us
3 Singal Ended zero 7 start of packet
D+ and D- low switching from idle to k
state 11 Reset
SE0 for more
4 Singal Ended One 8 End of packet than
D+ and D-High
SE0 for 2 bit times fellowed acceptable
by J state for 1 bit time (required >=10us) 13
USB LS/FS +3.3V

Rpu

D+ D+
USB Wire

D- D-

Rpu
Rpd Rpd

Host Device 12
+3.3V
USB LS/FS +3.3V

Rpu

D+ D+
USB Wire

Rpd dans les les deux D- D-


modes connecté en D+ et
D-
Rpu
Rpd Rpd

Host Device 12
+3.3V
USB LS/FS +3.3V

Full Speed
Rpu
PU doit etre connecté
D+

D+ D+
USB Wire

Rpd dans les les deux D- D-


modes connecté en D+ et
D-
Rpu
Rpd Rpd

Host Device 12
+3.3V
USB LS/FS +3.3V

Rpu

D+ D+
USB Wire

Rpd dans les les deux D- D-


modes connecté en D+ et
D- LOW Speed
Rpu PU doit etre connecté
Rpd Rpd en D-

Host Device 12
+3.3V
USB LS/FS

LS/FS Driver Transmit differentiel data +3.3V LS/FS Driver


LS/FS Driver Enable over bus LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu

D+ D+
USB Wire
D- D-

Rpu

+3.3V
Rpd Rpd

Host Device 13
USB LS/FS

LS/FS Driver Transmit differentiel data +3.3V LS/FS Driver


LS/FS Driver Enable over bus LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu
Recive differentiel
data from bus

LS/FS Diffrientiel reciver


D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

Rpu

+3.3V
Rpd Rpd

Assert Signal Ended


Host Device 13
Reciver
USB LS/FS

LS/FS Driver Transmit differentiel data +3.3V LS/FS Driver


LS/FS Driver Enable LS/FS Driver Enable
over bus
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu
Recive differentiel
data from bus

LS/FS Diffrientiel reciver


D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-
Give information about
SE data+ Reciver
Rpu D+ et D- State

SE data- Reciver SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd SE data- Reciver

Assert Signal Ended


Host Device 13
Reciver
USB LS/FS

LS/FS Driver Transmit differentiel data +3.3V LS/FS Driver


LS/FS Driver Enable LS/FS Driver Enable
over bus
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu
Recive differentiel
data from bus

LS/FS Diffrientiel reciver


D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-
Give information about
SE data+ Reciver
Rpu D+ et D- State

SE data- Reciver SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd SE data- Reciver

Assert Signal Ended


Host Device 13
Reciver
USB LS

LS/FS Driver +3.3V LS/FS Driver


LS/FS Driver Enable LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu

J J
LS/FS Diffrientiel reciver D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 0
Rpu

SE data- Reciver 1 0 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 1 SE data- Reciver

Assert Signal Ended


Host Device 14
Reciver
USB FS

LS/FS Driver
LS/FS
LS/FS Driver
Driver +3.3V
LS/FS Driver Enable LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu

J J
LS/FS Diffrientiel reciver
D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 1
Rpu

SE data- Reciver 0 1 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver

Assert Signal Ended


Host Device 14
Reciver
J-STATE (FS)

ENABLE
+3.3V LS/FS Driver
LS/FS Driver Enable LS/FS Driver LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu

J J
LS/FS Diffrientiel reciver
D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 1
Rpu

SE data- Reciver 0 1 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver

Assert Signal Ended


Host Device 15
Reciver
K-STATE (FS)

ENABLE
+3.3V LS/FS Driver
LS/FS Driver Enable LS/FS Driver LS/FS Driver Enable
le type de
LS/FS Data K communi
cation sta LS/FS Data
with k-sa rt
Assert Signal Ended Zero tate is sop Assert Signal Ended Zero
or resume
Rpu

K K
LS/FS Diffrientiel reciver
D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 0
Rpu

SE data- Reciver 1 1 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver

Assert Signal Ended


Host Device 16
Reciver
CONNECT (FS)

+3.3V LS/FS Driver


LS/FS Driver Enable LS/FS Driver LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu

J J
D+ D+
LS/FS Diffrientiel reciver USB USB LS/FS Diffrientiel reciver
LS/FS Diffrientiel Dta reciver Wire Wire LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 1
Rpu

SE data- Reciver 0 1 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver

Assert Signal Ended


Host Device 17
Reciver
CONNECT (FS)

+3.3V LS/FS Driver


LS/FS Driver Enable LS/FS Driver LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu

J J
LS/FS Diffrientiel reciver
D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 1
Host detect la connection par
la présence de 1 sur D+ Rpu

SE data- Reciver 0 1 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver

Assert Signal Ended


Host Device 17
Reciver
CONNECT (FS)
Device detect la connection
par la présence de 5V sur
VBUS
+3.3V LS/FS Driver
LS/FS Driver Enable LS/FS Driver LS/FS Driver Enable
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu

J J
LS/FS Diffrientiel reciver
D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 1
Host detect la connection par
la présence de 1 sur D+ Rpu

SE data- Reciver 0 1 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver

Assert Signal Ended


Host Device 17
Reciver
RESET (FS)

ENABL +3.3V LS/FS Driver


LS/FS Driver Enable LS/FS Driver LS/FS Driver Enable
E
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu
ENABL
E
J
LS/FS Diffrientiel reciver D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 0
Rpu

SE data- Reciver 0 0 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver
Le device prend l’etet SE0 pour
10 ms
Assert Signal Ended
Host Device 18
Reciver
RESET (FS)

ENABL +3.3V LS/FS Driver


LS/FS Driver Enable LS/FS Driver LS/FS Driver Enable
E
LS/FS Data LS/FS Data

Assert Signal Ended Zero Assert Signal Ended Zero


Rpu
ENABL
E
J
LS/FS Diffrientiel reciver D+ D+
LS/FS Diffrientiel reciver
USB Wire
LS/FS Diffrientiel Dta reciver
LS/FS Diffrientiel Dta reciver
D- D-

SE data+ Reciver 0
Rpu

SE data- Reciver 0 0 SE data+ Reciver

+3.3V
Assert Signal Ended
Reciver
Rpd Rpd 0 SE data- Reciver
Le device prend l’etet SE0 pour
10 ms
Assert Signal Ended
Host Device 18
Reciver
PIPES & ENDPOINTS

USB USB
Softwer Softwer

Host connection Virtuel Device


EndPoint 15 EndPoint 15
Pipe 15(IN/OUT)

... ...
IN/OUT

EndPoint 1 EndPoint 1
Pipe 1(IN/OUT)

EndPoint 0 EndPoint 0
Default pipe(IN/OUT)

connection physique

Transmiter/Reciver Transmiter/Reciver 19
Wire
PIPES & ENDPOINTS

USB USB
Data from endpoint 1
Softwer Softwer

Host Device
EndPoint 15 EndPoint 15
Pipe 15(IN/OUT)

... ...
IN/OUT

EndPoint 1 EndPoint 1
Pipe 1(IN/OUT)

EndPoint 0 EndPoint 0
Default pipe(IN/OUT)

Transmiter/Reciver Transmiter/Reciver 19
Wire
PIPES & ENDPOINTS

USB USB
Data from endpoint 1
Softwer Softwer

Host Device
EndPoint 15 EndPoint 15
Pipe 15(IN/OUT)

... ...
IN/OUT

EndPoint 1 EndPoint 1
Pipe 1(IN/OUT)

EndPoint 0 EndPoint 0
Default pipe(IN/OUT)

Transmiter/Reciver Transmiter/Reciver 19
Wire
PIPES & ENDPOINTS

USB USB
Data from endpoint 1
Softwer Softwer

Host Device
EndPoint 15 EndPoint 15
Pipe 15(IN/OUT)

... ...
IN/OUT

EndPoint 1 EndPoint 1
Pipe 1(IN/OUT)

EndPoint 0 EndPoint 0
Default pipe(IN/OUT)

Transmiter/Reciver Transmiter/Reciver 19
Wire
PIPES & ENDPOINTS

(setup
endpoints)
La route
de contrôle

(Interrupt La route en mode La route (Isochrone


USB isochrone
endpoints) de transfert interrupteur endpoints)

La route en mode
de transfert en bloc
20
(Bulk endpoints)
PACKETS & STRUCTURE

8 LS
32-FS/HS Bits 8 bits 11 bits 5 bits
SYN Synchronisation filed
Start of Frame Packet SYNC PID FRAME CRC EOP
C
PI Packet Identifier
8 bits 7 bits 4 bits 5 bits
D
FRAM
E
CRC Cyclic Redundancy Check

EOP End of Packet

21
PACKETS & STRUCTURE

8 LS
32-FS/HS Bits 8 bits 11 bits 5 bits
SYNC Synchronisation filed
Start of Frame Packet SYNC PID FRAME CRC EOP
PI Packet Identifier
8 bits 7 bits 4 bits 5 bits
D
Token Packet SYNC PID ADDR ENDP CRC EOP FRAM
E
CRC Cyclic Redundancy Check

EOP End of Packet

DATA

PIDType
Type PID Name
PID Name PID[3:0]
PID[3:0] ADD Destination or source Adress
PID
R
OUT / IN 0001 / 1001 ENDP Destination EndPoint
Token
SOF / SETUP 0101 / 1101

21
PACKETS & STRUCTURE

8 LS
32-FS/HS Bits 8 bits 11 bits 5 bits
SYNC Synchronisation filed
Start of Frame Packet SYNC PID FRAME CRC EOP
PI Packet Identifier
8 bits 7 bits 4 bits 5 bits
D
Token Packet SYNC PID ADDR ENDP CRC EOP FRAM
0 to 1024 bytes 16 bits
E
8 bits
CRC Cyclic Redundancy Check
Data Packet SYNC PID DATA CRC EOP

8 bits EOP End of Packet

SYNC PID EOP


Handshake Packet DATA

PIDType
Type PID Name
PID Name PID[3:0]
PID[3:0] ADD Destination or source Adress
PID
R
OUT / IN 0001 / 1001 ENDP Destination EndPoint
Token
SOF / SETUP 0101 / 1101
Data DATA0 / DATA1 0011 / 1011
0010 1010 21
ACK / NAK /
Handshake
STALL / NYET 1110 / 0110
EXEMPLE DE PROCESSUS
D'ÉNUMÉRATION

Addressed State
Default State

USB Reset Get Device descriptor USB Reset Set Device Adress

Get Device qualifier Get configuration


Get Device descriptor
descriptor descriptor(9 bytes)

Configured State Class


Get configuration specific
Set Configuration
descriptor All bytes operation

21
EXEMPLE DE PROCESSUS
D'ÉNUMÉRATION

bmRequest
Addressed
Type
bmRequest State wValue wIndex WLenght

Descriptor Type Descriptor Index Language ID


Addressed Stat
[15:8] [7:0] (For string)

21

Vous aimerez peut-être aussi