PTP, USB, and the Samsung Galaxy S3
Pages: 1 2
Dave Higton (1515) 3526 posts |
A couple of years or so ago, I wrote a Picture Transfer Protocol host app for RISC OS and sent it to a few people for beta test, but it failed for (IIRC) all of them in different ways, so I shelved it. Recently I got a Samsung Galaxy S3 phone, which sadly doesn’t appear as a Mass Storage device – it only does PTP and MTP. So, over the last few days, I’ve rewritten a large part of it. But it doesn’t work reliably on the S3. I have access to a USB analyser – sadly full speed and low speed only, but I own a USB 1.1 hub, so I can restrict any device to full speed so I can use the analyser, which shows me that, very often, RISC OS attempts to send the same message to the S3 hundreds or even thousands of times, always receiving a NAK from the S3. Needless to say, this is a blocking call on RISC OS, so the machine freezes at that point. Although the mouse cursor and the num lock LED work, not even Alt-Break will get control back; it has to be a reset or a power cycle. The good news is that I’ve never seen it corrupt any disc when this happens. When I use the same app with a Nikon Cooolpix 3100, it simply works. No problem. I get the same result with my Iyonix (RO 5.18) or my BBxM (RO 5.19 of 2012 August 23). Running the S3 direct into the Iyonix or the BBxM has never worked, not even once – yet the Nikon never fails. USBInfo can see the device, so it’s clear that control transfers work in both directions. The transfer that doesn’t is bulk OUT. One thing that does appear to be important is to wait for bulk OUT data transfers to complete before requesting a bulk IN transfer that gets the data or status requested by the bulk OUT, so I’ve amended the bulk OUT procedure to wait until the transfer completes or there’s a timeout. In the hope that someone somewhere is able and willing to try it, and shed some light on why it’s failing, I’ve put the code up on my web site at http://davehigton.me.uk/Progs/PTP.htm (note: this is not linked from the main page). If I can get it to work reliably, I hope to expand its facilities and release it at my usual price :-) So please, if you can help, download it and try it. If it works for some devices, that makes it worth working on further. |
Jess Hampshire (158) 865 posts |
N8 locks the iyonix, as described for your phone |
Dave Higton (1515) 3526 posts |
Not the answer I was hoping for, of course, but thank you for trying, Jess. |
Dave Higton (1515) 3526 posts |
I should add that I’ve had exactly the same results on the Raspberry Pi as on the Iyonix and BBxM: the Nikon camera (which is full speed only) is fine; the S3 (which is high speed) locks all apps and needs the RPi to be power cycled. |
Chris Johnson (125) 825 posts |
@Dave I have tried !PTP on an Iyonix with a Canon EOS40D. It is shown in *usbdevices, but running !PTP opens the ‘filer’ window and then stiffs the machine (finger on blue button required). The window shows the partially corrupted text ‘No images’ in what looks like system font at the top. Could try on BB or RPi, but I guess it’s not likely to work. Edit: I should add that the Canon does not appear as a mass storage device. |
Dave Higton (1515) 3526 posts |
Thanks, Chris.
That’s already clear, thank you anyway. !PTP will only run if it sees a PTP device, otherwise it will quit immediately telling the user it hasn’t found one. |
Dave Higton (1515) 3526 posts |
Jess and Chris, can you use the USBInfo app to find the speed of your phone/camera and post the result here, please? It’s curious that using the device at full speed works for me, whereas using it at high speed doesn’t. There should be no difference in how the devices are opened, read or written. I’ve been looking at some of the RISC OS source code, and it appears that EtherUSB doesn’t open pipes in the way documented on the Iyonix.com web site. The latter shows: port% = OPENIN"devices#interrupt;endpoint1:usbd3" But the EtherUSB source appears to call DeviceFS_CallDevice with parameters including: Devices#bulk;size2049:$.%s and it appears that the reason code is &80000007. (I don’t know where to look for what operation that is.) Note the “$.” in the device name in EtherUSB, and note the apparent lack of an endpoint specification. Am I using an incorrect string to open the endpoints? They appear to open, but the bulk OUT only appears to work at full speed; it always returns NAK at high speed. I’m in despair here. Help would be appreciated – though I know there are very few people who know enough to help. |
Chris Johnson (125) 825 posts |
Class: 0, Subclass: 0, Protocol: 0 Hope that helps. |
Dave Higton (1515) 3526 posts |
Yes, thanks, Chris, that’s as I expected. |
Jess Hampshire (158) 865 posts |
Class: 0 |
Greg Race (1437) 5 posts |
On my Galaxy SII I can connect it to my IYONIX in two different ways :- This second way works fine on my GSII in that I get two icons on icon bar, one for phone and one for external sd card. I can browse all files. I havnt tried reading and writing because I had a bad experience a couple of years ago and my Iyonix trampled all over the operating system and phone would not work after this so had to get fixed. Good Luck |
Dave Higton (1515) 3526 posts |
@Greg: Sadly the GS3 doesn’t have a mass storage mode. If you Google, you’ll find lots of other people complaining about Samsung having removed it. It does PTP or Media Transfer (maybe MTP, I haven’t really looked). There are add-ons to enable mass storage mode, and I’ve tried one, but I think it needs another hack applied first, which I haven’t done. Certainly the add-on I’ve tried doesn’t work for me. Are you running RO of at least version 5.18, or something older? |
Dave Higton (1515) 3526 posts |
@Jess: USBInfo tells you the speed of each device. What does it say for your N8? |
Ronald May (387) 407 posts |
Iyonix and Konica in PTP Mode: Using Devices# with the serial port I found once that setting timeout to 0 got things moving. I set this in line 810 of USBCastle and now I get an error: Just some observations for you, Dave. |
Chris Johnson (125) 825 posts |
@Dave I was going to have another play tonight but got sidetracked. However, I did notice that in the Basic file USBCastle, there is a function reading DEF FNhex2(x%) = “0” +STR$~x%, 2) Should that not be DEF FNhex2(x%) = RIGHT$(“0” + STR$~x%, 2) |
Ronald May (387) 407 posts |
“Computer freezes with files window opened.” Edit: I have just found my Coolpix 5200 works with !PTP so I can now see what the logfile should look like. |
Chris Johnson (125) 825 posts |
Looking at the log generated on my machine, there are 17 lines of genuine log, finishing with Write bulk: R3 = 0, R4 = 1 and then the garbage starts. It looks as if there are other files incorporated. Eg part of one of my mail fetch log files, some emails, including the encoded attachments, and parts that look like binary files. Length of this about 2MB. |
Dave Higton (1515) 3526 posts |
@Ronald: I’m delighted to hear that your Coolpix 5200 works. It makes it worthwhile updating the version on my web site, which is now able to delete objects as well as getting them. What speed is the USB interface of your Coolpix? The USBInfo application will tell you. |
Dave Higton (1515) 3526 posts |
@Chris: I also get these long logs containing all sorts of stuff they shouldn’t. However, the log function is only capable of logging strings. I wonder whether opening a file allocates a lump of space for the file, and this is what we see when the machine is restarted? |
Ronald May (387) 407 posts |
@Dave DEF PROClog(log$) and the file closes cleanly, it probably closes after every write. I have narrowed down the point of the crash to line 1090 of USBCastle. |
Dave Higton (1515) 3526 posts |
Yes, this is the line that gets the data input from the USB Bulk IN endpoint. No data, no crash – but no progress either :-( I simply don’t understand why the calls appear to behave differently with full speed and high speed endpoints. It shouldn’t be possible. |
Ronald May (387) 407 posts |
@Dave The model is Konica Minolta Dimage A2 and I’m expecting my Minolta 7D of the same era will be OK also. |
Dave Higton (1515) 3526 posts |
Buoyed up by reports of success when devices are limited to full speed, I’ve updated the version on my web site to add the Delete function. @Ronald: Thank you for trying it with a full speed hub. We see the same thing: when devices are limited to full speed, they work. I don’t think that can be down to timing in the devices themselves, since we’re talking about entirely different devices that exhibit the same behaviour. There has to be something about the RISC OS USB stack. @Chris: Thank you for pointing out the error in FNhex2. I can only imagine that was caused by some editing accident. It’s fixed in the version currently on my web site. |
Dave Higton (1515) 3526 posts |
We know that RISC OS communicates reliably with bulk endpoints of high speed devices in the form of USB sticks and hard drives. But it looks as if it doesn’t communicate reliably with cameras and phones at high speed. What’s the difference? Is it possible that the USB stack reacts differently when called from user and system space? |
Rick Murray (539) 13840 posts |
Just out of interest – is there a version/build-option for the USB stack that is capable of outputting some low-level debug data, perhaps to the serial port? If so, maybe looking at this could help shed some light on the different behaviour? FWIW – I have had no end of problems with MTP on my XP-SP3 setup. The usual one is a message that the sort of media I’m attempting to copy is not supported, which is complete rubbish as MXPlayer copes with alsorts, not to mention just plain bizarre quirks like WMA is accepted but MP3 rejected (!), seemingly each device behaves differently. |
Pages: 1 2