• AVR Freaks

AnsweredHot!Should I implement all USB requests?

Author
pajuhesh80
Super Member
  • Total Posts : 101
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
2020/07/24 03:07:50 (permalink)
4.5 (2)

Should I implement all USB requests?

I'm trying to optimize usb_device.c (...\mla\v2018_11_26\framework\usb\src\usb_device.c) for my application. As these codes are written for general purpose, some parts of code aren't called at all in specific apps (conditions to call those functions never happens) and some parts are useless (eg. disabling USB interrupts while initializing USB while they are disabled by default and USB is initialized just once in code) .
Using some variables, I found some of these useless parts. For example, I commented out not SETUP (DATA) transfers handling and USB_REQUEST_GET_STATUS, USB_REQUEST_CLEAR_FEATURE, USB_REQUEST_SET_FEATURE, USB_REQUEST_SET_INTERFACE, USB_REQUEST_SET_DESCRIPTOR and USB_REQUEST_SYNCH_FRAME parts in SETUP packet handling switch-case on EP0 and device is still working without any problem on both Windows 10 and LinuxMint19 while code size is reduced more than 2000 bytes.
Is it OK or it can cause problems in other systems?
post edited by pajuhesh80 - 2020/07/24 03:18:58

Slow and Steady!
#1
pajuhesh80
Super Member
  • Total Posts : 101
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
Re: Should I implement all USB requests? 2020/07/25 09:18:28 (permalink)
-1 (1)
?

Slow and Steady!
#2
NorthGuy
Super Member
  • Total Posts : 6295
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Should I implement all USB requests? 2020/07/25 14:02:46 (permalink)
+2 (2)
I don't handle any of these in my device except Set/Clear Feature, but even for these it doesn't do anything meaningful. Works fine Win/Linux/Mac.
#3
pajuhesh80
Super Member
  • Total Posts : 101
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
Re: Should I implement all USB requests? 2020/07/26 01:40:25 (permalink)
0
Was it a hobby or commercial project?

Slow and Steady!
#4
ric
Super Member
  • Total Posts : 28386
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Should I implement all USB requests? 2020/07/26 02:06:17 (permalink)
0 (2)
pajuhesh80
Was it a hobby or commercial project?

Have you followed the link in his signature? He sells these products.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#5
pajuhesh80
Super Member
  • Total Posts : 101
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
Re: Should I implement all USB requests? 2020/07/26 02:17:27 (permalink)
+1 (1)
I couldn't open that page. Seems that it is blocked for my country! Will try to bypass block and have a look at it.
Also, even engineers may have some hobby projects for themselves! :-)
 
post edited by pajuhesh80 - 2020/07/26 02:29:34

Slow and Steady!
#6
NorthGuy
Super Member
  • Total Posts : 6295
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Should I implement all USB requests? 2020/07/26 09:26:14 (permalink)
+1 (1)
pajuhesh80
I couldn't open that page. Seems that it is blocked for my country! Will try to bypass block and have a look at it.
Also, even engineers may have some hobby projects for themselves! :-)



I'm sorry our Web site is blocked :( This explains why we didn't have any orders from Iran.
 
I do make hobby projects when I have to. For example, when I switched our house to solar power I had to build a controller to manage the system. There was none you could buy. Surprisingly,  most of off-grid people do lots of things manually.
 
 
#7
pajuhesh80
Super Member
  • Total Posts : 101
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
Re: Should I implement all USB requests? 2020/07/26 22:39:20 (permalink)
+1 (1)
NorthGuy
I'm sorry our Web site is blocked :( This explains why we didn't have any orders from Iran.

You should not be sorry. The person who sets all of these blockings and sanctions must be sorry! Let's not get political!
Also, passing location blockings isn't much hard as I'm doing it now for even this forum (without VPN or proxy). I also checked your website. I'm interested in NSDSP Programmers as my PICkit 3 is strangely slow in MPLAB (latest firmware) mode. It works much faster when I use PICkit 3 v3.01 software and its firmware.
 
However, we still can't buy anything from you because we can't use our credit cards internationally. Even if a company (eg. an Iranian internet electronic parts seller) buy and import your products, it will be very expensive for us to buy. Electronic parts (and almost any other thing) are very very expensive these days here. Again because of sanctions!
before: "Damaged? No problem. We will buy another!"
Now: "Damaged? So we can't work on this project anymore!"
Price of an ATmega32 is now 10-15 times more than 2-3 years ago!

Slow and Steady!
#8
LdB_ECM
Super Member
  • Total Posts : 435
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: Should I implement all USB requests? 2020/07/27 06:23:55 (permalink)
-1 (1)
Try plugging a hub in and I suspect it wont work because from memory it needs some of those.
#9
pajuhesh80
Super Member
  • Total Posts : 101
  • Reward points : 0
  • Joined: 2019/12/08 11:23:37
  • Location: Nowshahr, Mazandaran, Iran
  • Status: offline
Re: Should I implement all USB requests? 2020/07/27 13:33:04 (permalink)
0
I think it will work. I don't have an external USB hub to test it but two of USBs of my laptop (both USB 2 next to each other) are using same board and wires. Looks like an internal hub.
Also, based on my knowledge of USB concepts, all USB hosts have at least an integrated hub to connect to device. Refer to USB 2 specifications.
And a hub shouldn't do anything other than what host requests.

Slow and Steady!
#10
ric
Super Member
  • Total Posts : 28386
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Should I implement all USB requests? 2020/07/27 15:02:19 (permalink)
0
LdB_ECM
Try plugging a hub in and I suspect it wont work because from memory it needs some of those.

Surely this only matters if you are acting as a host, not as a device.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#11
NorthGuy
Super Member
  • Total Posts : 6295
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Should I implement all USB requests? 2020/07/27 16:32:15 (permalink) ☄ Helpfulby pajuhesh80 2020/08/05 01:42:35
+3 (3)
We have many customers who use hubs because they do production programming and need to plug in multiple devices at a time. Nobody ever reported a problem with the device not working through the hub.
 
I'm sorry I lied. I looked at the source more attentively and the device does handle some of these. I handle "set interface" by checking if 0 is supplied. I confirm "set/clear feature" for halts, but I don't do real halts. I also handle "get status" by returning zero.
 
The effects of functionality behind some of these, such as halting endpoints by host's demand, is not very clear. When I thought about implementing these, I came to the conclusion that if the host decided to halt an endpoint, something is already went terribly wrong, and whatever you do is not likely to alleviate the situation.
 
Others, such as setting an interface, may make sense if you have alternative interfaces, but if you don't, there's nothing meaningful you can do if you receive the request.
 
 
#12
LdB_ECM
Super Member
  • Total Posts : 435
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: Should I implement all USB requests? 2020/07/27 21:04:45 (permalink)
0
Yes you need the set and clear feature to be work because you have to reset and power on/off each port on the hub as part of the enumeration. It is the only time the calls are made but they are required. If your hubs are working correctly pretty sure you have got everything you need beyond weird exotic devices.
 
Ric for future reference if you can plug other devices into a device USB and it enumerates them it has to have a root hub (device 0) which can be either a hardware or software. Pajuhesh80 correctly noted that above but didn't realize the root hub enumeration requires those commands. 
post edited by LdB_ECM - 2020/07/27 21:06:01
#13
ric
Super Member
  • Total Posts : 28386
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Should I implement all USB requests? 2020/07/27 21:11:39 (permalink)
+1 (1)
You still seem to be talking about a host. The OP is talking about a device.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#14
LdB_ECM
Super Member
  • Total Posts : 435
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: Should I implement all USB requests? 2020/07/27 21:22:22 (permalink)
0
Yeah I see that now when I asked about the plugging in the hub, he is talking about plugging it into a hub port which is not quite what I meant :-)
 
As a device all he should need to implement is the feature reset (where it dumps the assigned addr) as when the hub begins it's enumeration all it's going to do is feature reset do the slow transaction 8 byte transaction and feature reset again assign address and then do the descriptors and config to complete enumeration.
 
Just for my own edification does the PIC usb implementation allow for newer dual role standard?
post edited by LdB_ECM - 2020/07/27 21:43:45
#15
ggmaster
New Member
  • Total Posts : 14
  • Reward points : 0
  • Status: offline
Re: Should I implement all USB requests? 2020/08/05 01:04:20 (permalink) ☼ Best Answerby pajuhesh80 2020/08/05 01:42:21
+2 (2)
According to the USB specification (Chapter 9), if the device does not implement certain requests, it must STALL the endpoint indicating to the host that these requests are not supported. Without the SET/CLEAR FEATURE, SET/CLEAR INTERFACE, the device will probably enumerate fine as you mentioned but to be compliant to the USB protocol, you must STALL. This is the safest way to design the device software avoiding any breaking conditions. If you do not wish to be compliant to the USB specification, you may wish to remove these requests from the code.
Screen Shot 2020-0.. at 12.59.06 AM.png

Attached Image(s)

#16
Jump to:
© 2020 APG vNext Commercial Version 4.5