Linux to QNX6 conversion

bridged with qdn.public.ddk.usb
Post Reply
Phil Olynyk

Linux to QNX6 conversion

Post by Phil Olynyk » Wed Jan 23, 2002 11:17 pm

Hi -
I have an EZ-USB - based device that requires code to be downloaded
into it to turn it into a useful device. From linux I found a program
called ezusb2131 which acts as a driver and allows one to download an
attached device. This program works under linux; my device is downloaded
and the lights flash as expected, and re-enumeration shows it to be the
expected device. I took the program and rewrote it for the QNX usb
stack, and made some mistake(s) obviously, as all the lights come on
solid and it won't re-enumerate. The key chunk of code, I think, is the
bit that downloads a "line" of code.

From the linux side it looks like this:

/* download the line of code to the board */
i=usb_control_msg(pezusb->usbdev,
usb_sndctrlpipe(pezusb->usbdev, 0),
ANCHOR_LOAD, VEN_REQUEST_OUT,
ihex_record.address, 0, ihex_record.data,
ihex_record.length, 300);
if (i != ihex_record.length)
{
printk(EZUSB_LL "%s: ERROR could not download board, err=%d,
%s,%d\n",
EZUSB_MOD_NAME, i, __FILE__, __LINE__);
return(-1);
}

and my code looks like this:

// download that chunk
memmove( ezu->buffer, hexRec.data, hexRec.length );
if ( EOK != ( err = usbd_setup_vendor( ezu->urb, URB_DIR_OUT,
ANCHOR_LOAD,
USB_RECIPIENT_DEVICE |USB_TYPE_VENDOR,
hexRec.address, 0, ezu->buffer, hexRec.length ) )) {
fprintf( stderr, "EzUsb failed setup_vendor: line %d\n", cnt );
return ( err );
}
if ( EOK != ( err = usbd_io( ezu->urb, ezu->ep_cntl, NULL, NULL, 500
)) ) {
fprintf( stderr, "EzUsb failed to load line %d\n", cnt );
return ( err );
}

Can anybody see my error here? Or possibly the usb stack is unhappy with
the instant dis-connect and re-connect - done by the EZ-USB hardware at
the end of the download?
Does anybody know how to make the usb stack display setup packets in
hex? I could compare with what my Windows usb stiffer reports....

Any help will be much appreciated!

Phil Olynyk

Nazim Ali Bharmal

Re: Linux to QNX6 conversion

Post by Nazim Ali Bharmal » Tue Jul 30, 2002 4:22 pm

Phil Olynyk <pholynyk@home.com> wrote:
I have an EZ-USB - based device that requires code to be downloaded
into it to turn it into a useful device. From linux I found a program
called ezusb2131 which acts as a driver and allows one to download an
Here is some code which downloads onto a EZUSB. I can send you the entire tar
file if you want but the driver is unstable (this code is fully working though)

-- start --

// Copyright 2002, Ali Bharmal nab26@mrao.cam.ac.uk derived from QSSL mouse.c
// for devu-mouse

// This source code has been published by Ali Bharmal and the COAST group at
// the Cavendish Laboratory, University of Cambridge. However, any use,
// reproduction, modification, distribution or transfer of this software, or
// any software which includes or is based upon any of this code, is only
// permitted under the terms of the QNX Open Community License version 1.0
// (see licensing.qnx.com for details) or as otherwise expressly authorized
// by a written license agreement from QSSL. For more information, please
// email licensing@qnx.com.

// Module Description: Starlight Xpress class driver

/* sxEZ_dload
* thread to push the new 8051 program into the interface box
*/
void* sxEZ_dload( void *device )
{
int i, j;
ezusb_t *ezusb;

ezusb=usbd_device_extra( device );
ezusb->status &= ~EZUSB_STATE_QUEUED;

if( ezusb->status & EZUSB_STATE_DOWNLOADING ) {
ezusb->cntl_buff=usbd_alloc( sizeof(char)*16 );
(char)ezusb->cntl_buff[0]=CPUCS_RESET;
if( usbd_setup_vendor( ezusb->urb, URB_DIR_OUT, EZUSB_FIRMWARE_LOAD
, USB_TYPE_VENDOR | USB_RECIPIENT_ENDPOINT, CPUCS_REG
, 0, ezusb->cntl_buff, 1)) {
fprintf( stderr, "devu-sx: Cannot setup RESET URB\n" );
ezusb->status &= ~EZUSB_STATE_DOWNLOADING;
usbd_free( ezusb->cntl_buff );
return NULL;
}
if( usbd_io(ezusb->urb, ezusb->cntl_ep, NULL, NULL
, USBD_TIME_INFINITY)) {
fprintf( stderr, "devu-sx: Cannot put 8051 in RESET\n" );
ezusb->status &= ~EZUSB_STATE_DOWNLOADING;
usbd_free( ezusb->cntl_buff );
return NULL;
}
<-- the EZUSB has been put into RESET, ready for the download
}
for( i=0
; i < sizeof(sx_ezusb_code)/sizeof(struct sx_ezusb_download_record)
&& ezusb->status & EZUSB_STATE_DOWNLOADING
; i++ ) {
// Download code record.
j = sx_ezusb_code.len;
memcpy( ezusb->cntl_buff, sx_ezusb_code.data, j );

if( usbd_setup_vendor( ezusb->urb, URB_DIR_OUT, EZUSB_FIRMWARE_LOAD
, USB_TYPE_VENDOR | USB_RECIPIENT_ENDPOINT
, sx_ezusb_code.addr, 0, ezusb->cntl_buff, j))
{
fprintf( stderr, "devu-sx: Cannot setup download URB %d\n", i );
ezusb->status &= ~EZUSB_STATE_DOWNLOADING;
usbd_free( ezusb->cntl_buff );
return NULL;
}
if( usbd_io( ezusb->urb, ezusb->cntl_ep, NULL, NULL
, USBD_TIME_INFINITY ) ) {
fprintf( stderr, "devu-sx: Cannot download URB\n" );
ezusb->status &= ~EZUSB_STATE_DOWNLOADING;
usbd_free( ezusb->cntl_buff );
return NULL;
}
}
<-- end of for loop for downloading the actual data
if( ezusb->status & EZUSB_STATE_DOWNLOADING ) {
// Take 8051 out of RESET.
(char)ezusb->cntl_buff[0]=CPUCS_RUN;

// Put 8051 into RESET
if( usbd_setup_vendor( ezusb->urb, URB_DIR_OUT, EZUSB_FIRMWARE_LOAD
, USB_TYPE_VENDOR | USB_RECIPIENT_ENDPOINT, CPUCS_REG
, 0, ezusb->cntl_buff, 1 ) ) {
fprintf( stderr, "devu-sx: Cannot setup unRESET URB\n" );
ezusb->status &= ~EZUSB_STATE_DOWNLOADING;
usbd_free( ezusb->cntl_buff );
return NULL;
}
if( usbd_io( ezusb->urb, ezusb->cntl_ep, NULL, NULL
, USBD_TIME_INFINITY ) ) {
fprintf( stderr, "devu-sx: Cannot put 8051 in unRESET\n" );
ezusb->status &= ~EZUSB_STATE_DOWNLOADING;
usbd_free( ezusb->cntl_buff );
return NULL;
}
usbd_free( ezusb->cntl_buff );
}
<-- get the EZUSB 8051 running the new code, will reenumerate itself
return NULL;
}

-- end --

--
nab26@mrao.cam.ac.uk
development system email / NOT ARCHIVED

Phil Olynyk

Re: Linux to QNX6 conversion

Post by Phil Olynyk » Tue Aug 06, 2002 12:52 am

Thank you, Nazim.
I will have to compare your code to mine when I have more time. Yours
looks quite clean. It turns out that my code works as long as I plug the
midi adapter directly into the computer - around the back.... This took
a while to discover, since I have a usb hub sitting in front of the
computer where I can easily play with things... And - of course - it
works with Windows either way! I don't know if _all_ hubs have this
problem, but both of mine do.

Phil

Nazim Ali Bharmal wrote:
Phil Olynyk <pholynyk@home.com> wrote:

I have an EZ-USB - based device that requires code to be downloaded
into it to turn it into a useful device. From linux I found a program
called ezusb2131 which acts as a driver and allows one to download an

Here is some code which downloads onto a EZUSB. I can send you the entire tar
file if you want but the driver is unstable (this code is fully working though)

-- start --
code snipped to save bw

Post Reply

Return to “qdn.public.ddk.usb”