USB bulk write sample

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

USB bulk write sample

Post by septem »

Can anybody give an example of bulk writing on psp? I've been searching net for hours and I haven't found anything useful. What I'd like to know is: how to start connection, send some data with bulk mode and close connection.
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

*bump*

Anybody? I really need this... :(
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

did you have a look at psplink?
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

Yep, I did, but it's pretty hard to get the code I needed and it didn't work... Take a look:

Code: Select all

/* Main USB event flags */
enum UsbEvents
{
	USB_EVENT_ATTACH = 1,
	USB_EVENT_DETACH = 2,
	USB_EVENT_ASYNC  = 4,
	USB_EVENT_CONNECT = 8,
	USB_EVENT_ALL = 0xFFFFFFFF
};

/* USB transfer event flags */
enum UsbTransEvents
{
	USB_TRANSEVENT_BULKOUT_DONE = 1,
	USB_TRANSEVENT_BULKIN_DONE = 2,
};

/* String descriptor */
unsigned char strp[] = 
{
	0x8, 0x3, '<', 0, '>', 0, 0, 0
&#125;;

/* Intefaces */
struct UsbInterface intp = &#123;
	0xFFFFFFFF, 0, 1,
&#125;;

/* Main USB transfer event flag */
static SceUID g_transevent = -1;
/* Static bulkin request structure */
static struct UsbdDeviceReq g_bulkin_req;
/* Forward define the driver structure */
extern struct UsbDriver g_driver;
/* Async request */
//static struct UsbdDeviceReq g_async_req;
/* Buffers for async data */
//static struct AsyncEndpoint *g_async_chan&#91;MAX_ASYNC_CHANNELS&#93;;

/* Endpoint blocks */
struct UsbEndpoint endp&#91;4&#93; = &#123;
	&#123; 0, 0, 0 &#125;,
	&#123; 1, 0, 0 &#125;,
	&#123; 2, 0, 0 &#125;,
	&#123; 3, 0, 0 &#125;,
&#125;;

/* Setup a bulkin request */
int set_bulkin_req&#40;void *data, int size&#41;
&#123;
	sceKernelDcacheWritebackRange&#40;data, size&#41;;
	memset&#40;&g_bulkin_req, 0, sizeof&#40;g_bulkin_req&#41;&#41;;
	g_bulkin_req.endp = &endp&#91;1&#93;;
	g_bulkin_req.data = data;
	g_bulkin_req.size = size;
	g_bulkin_req.func = NULL;
	sceKernelClearEventFlag&#40;g_transevent, ~USB_TRANSEVENT_BULKIN_DONE&#41;;
	return sceUsbbdReqSend&#40;&g_bulkin_req&#41;;
&#125;
Activating USB:

Code: Select all

LoadStartModule&#40;"flash0&#58;/kd/semawm.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstor.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstormgr.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstorms.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstorboot.prx"&#41;;
    
    retVal = sceUsbStart&#40;PSP_USBBUS_DRIVERNAME, 0, 0&#41;;
    if &#40;retVal != 0&#41; &#123;
         debug_file&#40;0x04&#41;;
         sceKernelSleepThread&#40;&#41;;
    &#125;

        int ret;
	ret = sceUsbbdRegister&#40;&g_driver&#41;;
        if &#40;!&#40;state & PSP_USB_ACTIVATED&#41;&#41;&#123;
	                               retVal = sceUsbActivate&#40;0x1d2&#41;;
                                       &#125;
I'm sending it:

Code: Select all

if&#40;sceUsbGetState&#40;&#41; & PSP_USB_ACTIVATED&#41;&#123;
                          retVal= set_bulkin_req&#40;&buf, 192&#41;;
                          if&#40;retVal<0&#41;&#123;
                            broadcast= 0x00;
                            debug_file&#40;retVal&#41;;                        
                          &#125;                               
		          &#125;
I tried to send three 64-byte buffers, but it doesn't work either...
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

What in dear fucking god.... if you dont know how this works dont touch it :)
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

How am I supposed to learn it if you tell me to don't touch it? :>
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

septem wrote:How am I supposed to learn it if you tell me to don't touch it? :>
Go to your PC and look up PC examples of USB to learn how USB works. Once you're a PC USB wiz, come back and look at the PSP again. Don't try to LEARN anything starting on the PSP. You'll just wind up pulling your hair out.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

This isn't some kindergarten for wannabe usb coders, you have to earn your stripes. Really if you want to do a bulk transfer then it is surely simpler to use psplink's async/bulk transfer mechanism :)
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

Yeah, I guess you're right ;P
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

The code you pasted though would only help if you had all the other USB stuff psplink does, just called the send req without setting up the usb driver wont do alot I am afraid.
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

Hehe, I guess making usb send data isn't as easy as using sockets ;P I was wondering if I can make usb send any data using only pspusbbus.h and not loading any modules like in pspsdk usb sample and not using function like sceUsbActivate, sceUsbDeactivate etc.? I guess they are used while setting usb storage and they're not needed if I want bus to send some bulk data... Also I'd like to know if I have to use all those semaphores if the only thing my prx does is writing (no reading, exchanging commands or nothing like that).
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Yes, using USB stuff is nothing remotely like sockets. I am impressed you can even use those :)

You have to call sceUsbActivate etc because that then creates the device. I guess you dont understand how USB works to be asking a question like this. You can't just "use" the USB bus in any meaningful sense without creating a USB device type and then you still need something on the PC side to interact with it.

With USB mass storage the PSP firmware makes a device which looks like a mass storage device and then handles the interactions between that and the PC. The PC just sees it as a normal USB mass storage device and loads the appropriate driver. Similar with usbhostfs.
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

TyRaNiD wrote:Yes, using USB stuff is nothing remotely like sockets. I am impressed you can even use those :)
Gimme a break... I know I got whole thing the wrong way and I overestimated myself on that, but you don't need to say that kind of shit to me. You haven't been born as a usb-programming god either (correct me if I'm wrong :] ). But I'm sorry for asking so many fuckin' lame questions, this won't happen again.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

I guess the fact there was a smilie was there went over your head ;)

If you really want to use the USB cable to transfer data from PC to PSP or vice versa then really use the stuff already in psplink to provide that very functionality. Look at the echo sample, all you need to do is write a simple "server" on the PSP and a socket client on the PC and you are done. usbhostfs handles the rest for you. Oh and note you dont actually need the rest of psplink to use it, just usbhostfs and usbhostfs_pc
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

Ok, let's say I use usbhostfs:
1. can usbhostfs guarantee that I get maximum speed? And I don't mean 480 mb/s or nothing like that cause it's almost impossible because of hardware issues. I want to know if it sends any packets other than my prx wants it to e.g some commands packets or something like that, that may slow whole the transmission.
2. what if I want to write pc application which will read what psp writes in language other than c/c++? Do I have to translate whole usbhostfs_pc or make some kind of library of it (dll maybe), or can I use just libusb usb_bulk_read and not pay any attention to packets that usbhostfs may send other than my prx does?
3. if I want to change Pid I have to change it in usbhostfs.h, right?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Go on just for curiosity what are you actually trying to do?
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

I won't tell you cause you'll stop taking whole this thing for real (if you ever have :] )
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Fine be like that then, I wont help you at all. If you are so cagey about it is probably warez related so I dont much care :)
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

Oh man... you won. I'm trying to make video streamer.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

What type of video? Something akin to remotejoy or different? In my tests I have only been able to get the data transfer up to around 18 Megabytes/s and that is an artificial test with no extra framing and literally just pushing out large bulk data transfers. You might be better off trying to use isochronous transfers but I have no idea if the PSP actually supports that anyway.

Good luck on this, you will need it :P
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

remotejoy isn't enough? i can do videos from it without problems
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

I want to make my own app. I'm trying to stream video buffer, so that pc user sees, what psp user does. I got a question: if I use usbhostfs I have to use my app with psplink or can I just throw it in seplugins and it will work.
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

without psplink, just like remotejoy which doesn't need psplink either
septem
Posts: 21
Joined: Wed Aug 29, 2007 7:44 am

Post by septem »

For some reason it doesn't work. It's not even detected by pc. I guess i should do something before starting streaming like starting hostfs driver, but I'm not sure what...
Post Reply