Handling SET_ADDRESS Requests
This request should come right after the
GET_DESCRIPTOR Devicerequest if you're using Linux, or be the first request sent to the device by Mac OS.
A SET_ADDRESS request has the following fields as defined by Section 9.4.6 Set Address of the USB spec:
bmrequesttypeis 0b00000000brequestis 5 (i.e. the SET_ADDRESS Request Code, see table 9-4 in the USB spec)wValuecontains the address to be used for all subsequent accesseswIndexandwLengthare 0, there is nowData
It should be handled as follows:
-
If the device is in the
Defaultstate, then- if the requested address stored in
wValuewas0(Nonein theusbAPI) then the device should stay in theDefaultstate - otherwise the device should move to the
Addressstate
- if the requested address stored in
-
If the device is in the
Addressstate, then- if the requested address stored in
wValuewas0(Nonein theusbAPI) then the device should return to theDefaultstate - otherwise the device should remain in the
Addressstate but start using the new address
- if the requested address stored in
-
If the device is in the
Configuredstate this request results in "unspecified" behavior according to the USB specification. You should stall the endpoint in this case.
Note: According to the USB specification the device needs to respond to this request with a STATUS stage -- the DATA stage is omitted. The nRF52840 USBD peripheral will automatically issue the STATUS stage and switch to listening to the requested address (see the USBADDR register) so no interaction with the USBD peripheral is required for this request.
For more details, read the introduction of section 6.35.9 of the nRF52840 Product Specification 1.0.