Bug in Wiki (or) in "PowerSwitch" [solved]
Posted: Tue Jul 27, 2010 1:33 am
Hi, I'am trying to understand V-USB, so I have started with PowerSwitch as it is said to be "pure basics".
On my board I have an LCD, so I included (original) lcd.h/lcd.c (after configuring pins - works OK).
(my "target" is something like lcd2usb but this project does NOT work for me... )
Now the PowerSwitch: control transfers work OK (can send wIndex, wValue, even wLength is transferred to device), receive: works (at least default 2 byte return).
Now I want to send more data (4-8bytes). According to Wiki changed:
USB_CFG_IMPLEMENT_FN_READ to 1,
added:
usbMsgLen_t usbFunctionSetup(uchar setupData[8])
...
currentPosition = 0; // initialize position index
bytesRemaining = rq->wLength.word; // store the amount of data requested
if(bytesRemaining > sizeof(buffer)) // limit to buffer size
bytesRemaining = sizeof(buffer);
return USB_NO_MSG; // tell driver to use usbFunctionWrite()
...
added:
uchar usbFunctionWrite(uchar *data, uchar len)
{
uchar i;
if(len > bytesRemaining) // if this is the last incomplete chunk
len = bytesRemaining; // limit to the amount we can store
bytesRemaining -= len;
for(i = 0; i < len; i++)
buffer[currentPosition++] = data[i];
...
"blinkLED()"
...
return bytesRemaining == 0; // return 1 if we have all data
}
Problem #1: compiler says: there is NO USB_NO_MSG defined. After a quic search in other downloader project I have found it's declaraction. Copied to usbdrv.h.
So bug is in (current?) usbdrv.h or in Wiki?
Problem #2:
compile OK, but "blinkLED" NEVER get called.
I have located, that in this fragment of usbdv.c:
" /* 1: CLEAR_FEATURE, 3: SET_FEATURE, 7: SET_DESCRIPTOR */
/* 12: SYNCH_FRAME */
}
#undef SET_REPLY_LEN
}else{ /* not a standard request -- must be vendor or class request */
replyLen = usbFunctionSetup(data);
}
#if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE
if(replyLen == 0xff){ /* use user-supplied read/write function */
if((rq->bmRequestType & USBRQ_DIR_MASK) == USBRQ_DIR_DEVICE_TO_HOST){
replyLen = rq->wLength.bytes[0]; /* IN transfers only */
}
flags &= ~USB_FLG_USE_DEFAULT_RW; /* we have no valid msg, use user supplied read/write functions */
}else /* The 'else' prevents that we limit a replyLen of 0xff to the maximum transfer len. */
#endif
if(!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0]) /* limit length to max */
replyLen = rq->wLength.bytes[0];
}
/* make sure that data packets which are sent as ACK to an OUT transfer are always zero sized */
}else{ /* DATA packet from out request */
blinkLED();
#if USB_CFG_IMPLEMENT_FN_WRITE
if(!(usbMsgFlags & USB_FLG_USE_DEFAULT_RW)){
uchar rval = usbFunctionWrite(data, len);
replyLen = 0xff;
if(rval == 0xff){ /* an error occurred */
usbMsgLen = 0xff; /* cancel potentially pending data packet for ACK */
usbTxLen = USBPID_STALL;
}else if(rval != 0){ /* This was the final package */
replyLen = 0; /* answer with a zero-sized data packet */
}
flags = 0; /* start with a DATA1 package, stay with user supplied write() function */
}
#endif
}
usbMsgFlags = flags;"
control NEVER reaches " }else{ /* DATA packet from out request */"
What is the problem, and what can I do to make it work?
On my board I have an LCD, so I included (original) lcd.h/lcd.c (after configuring pins - works OK).
(my "target" is something like lcd2usb but this project does NOT work for me... )
Now the PowerSwitch: control transfers work OK (can send wIndex, wValue, even wLength is transferred to device), receive: works (at least default 2 byte return).
Now I want to send more data (4-8bytes). According to Wiki changed:
USB_CFG_IMPLEMENT_FN_READ to 1,
added:
usbMsgLen_t usbFunctionSetup(uchar setupData[8])
...
currentPosition = 0; // initialize position index
bytesRemaining = rq->wLength.word; // store the amount of data requested
if(bytesRemaining > sizeof(buffer)) // limit to buffer size
bytesRemaining = sizeof(buffer);
return USB_NO_MSG; // tell driver to use usbFunctionWrite()
...
added:
uchar usbFunctionWrite(uchar *data, uchar len)
{
uchar i;
if(len > bytesRemaining) // if this is the last incomplete chunk
len = bytesRemaining; // limit to the amount we can store
bytesRemaining -= len;
for(i = 0; i < len; i++)
buffer[currentPosition++] = data[i];
...
"blinkLED()"
...
return bytesRemaining == 0; // return 1 if we have all data
}
Problem #1: compiler says: there is NO USB_NO_MSG defined. After a quic search in other downloader project I have found it's declaraction. Copied to usbdrv.h.
So bug is in (current?) usbdrv.h or in Wiki?
Problem #2:
compile OK, but "blinkLED" NEVER get called.
I have located, that in this fragment of usbdv.c:
" /* 1: CLEAR_FEATURE, 3: SET_FEATURE, 7: SET_DESCRIPTOR */
/* 12: SYNCH_FRAME */
}
#undef SET_REPLY_LEN
}else{ /* not a standard request -- must be vendor or class request */
replyLen = usbFunctionSetup(data);
}
#if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE
if(replyLen == 0xff){ /* use user-supplied read/write function */
if((rq->bmRequestType & USBRQ_DIR_MASK) == USBRQ_DIR_DEVICE_TO_HOST){
replyLen = rq->wLength.bytes[0]; /* IN transfers only */
}
flags &= ~USB_FLG_USE_DEFAULT_RW; /* we have no valid msg, use user supplied read/write functions */
}else /* The 'else' prevents that we limit a replyLen of 0xff to the maximum transfer len. */
#endif
if(!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0]) /* limit length to max */
replyLen = rq->wLength.bytes[0];
}
/* make sure that data packets which are sent as ACK to an OUT transfer are always zero sized */
}else{ /* DATA packet from out request */
blinkLED();
#if USB_CFG_IMPLEMENT_FN_WRITE
if(!(usbMsgFlags & USB_FLG_USE_DEFAULT_RW)){
uchar rval = usbFunctionWrite(data, len);
replyLen = 0xff;
if(rval == 0xff){ /* an error occurred */
usbMsgLen = 0xff; /* cancel potentially pending data packet for ACK */
usbTxLen = USBPID_STALL;
}else if(rval != 0){ /* This was the final package */
replyLen = 0; /* answer with a zero-sized data packet */
}
flags = 0; /* start with a DATA1 package, stay with user supplied write() function */
}
#endif
}
usbMsgFlags = flags;"
control NEVER reaches " }else{ /* DATA packet from out request */"
What is the problem, and what can I do to make it work?