usb is killing me!

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

Moderators: cheriff, TyRaNiD

Post Reply
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

usb is killing me!

Post by Zettablade »

Ok, I was able to get the usb working on my little program. I used the example from the sdk. Anyways, I changed my code around a bit, and now it crashes whenever I load up the game. Here's the code I'm using.

Code: Select all

#include <oslib/oslib.h>
#include "usb.h"

u32 state;
u32 retVal;

__attribute__ &#40;&#40;constructor&#41;&#41;
void loaderInit&#40;&#41;
&#123;
	pspKernelSetKernelPC&#40;&#41;;
	pspSdkInstallNoDeviceCheckPatch&#40;&#41;;
	pspDebugInstallKprintfHandler&#40;NULL&#41;;
&#125;

//helper function to make things easier
int LoadStartModule&#40;char *path&#41;
&#123;
	u32 loadResult;
	u32 startResult;
	int status;

	loadResult = sceKernelLoadModule&#40;path, 0, NULL&#41;;
	if &#40;loadResult & 0x80000000&#41;
	return -1;
	else
	startResult =
		sceKernelStartModule&#40;loadResult, 0, NULL, &status, NULL&#41;;

	if &#40;loadResult != startResult&#41;
	return -2;

	return 0;
&#125;

void StartModules&#40;&#41;
&#123;
	state = 0;
	//start necessary drivers
    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;;

    //setup USB drivers
    retVal = sceUsbStart&#40;PSP_USBBUS_DRIVERNAME, 0, 0&#41;;
    if &#40;retVal != 0&#41; &#123;
	printf&#40;"Error starting USB Bus driver &#40;0x%08X&#41;\n", retVal&#41;;
	sceKernelSleepThread&#40;&#41;;
    &#125;
    retVal = sceUsbStart&#40;PSP_USBSTOR_DRIVERNAME, 0, 0&#41;;
    if &#40;retVal != 0&#41; &#123;
	printf&#40;"Error starting USB Mass Storage driver &#40;0x%08X&#41;\n",
	       retVal&#41;;
	sceKernelSleepThread&#40;&#41;;
    &#125;
    retVal = sceUsbstorBootSetCapacity&#40;0x800000&#41;;
    if &#40;retVal != 0&#41; &#123;
	printf
	    &#40;"Error setting capacity with USB Mass Storage driver &#40;0x%08X&#41;\n",
	     retVal&#41;;
	sceKernelSleepThread&#40;&#41;;
    &#125;
    retVal = 0;
&#125;

void USB&#40;&#41;
&#123;
	state = sceUsbGetState&#40;&#41;;
	if &#40;state & PSP_USB_CABLE_CONNECTED&#41; &#123;
		if &#40;state & PSP_USB_ACTIVATED&#41; &#123;
			//I'll add image blitting later
		&#125; else &#123;
			retVal = sceUsbActivate&#40;0x1c8&#41;;
		&#125;
	&#125; else if &#40;state & !PSP_USB_CABLE_CONNECTED&#41; &#123;
		if &#40;state & !PSP_USB_ACTIVATED&#41; &#123;
			//do nothing!
		&#125; else &#123;
			retVal = sceUsbDeactivate&#40;0x1c8&#41;;
		&#125;
	&#125;
&#125;
I use StartModules(); before my main loop(in my main file), and then USB(); inside of the main loop(also in my main file). I also use

Code: Select all

PSP_MODULE_INFO&#40;"Blah", 0x1000, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;
in my main file.

If you need to see the whole source, I can give it to you, but I'm pretty sure there is something wrong with the usb.cpp file.

Another thing, Is there a quicker way of activating the usb, or is this the fastest way there is?
DocMAX
Posts: 35
Joined: Tue Jun 13, 2006 10:04 am

Post by DocMAX »

how old are you?
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

DocMAX wrote:how old are you?
that is irrelavent to his question ....as anyone
can tell you, discussion on the internet is never
based on age but on problems, please be more
open minded to others you will incounter on the NET
10011011 00101010 11010111 10001001 10111010
Post Reply