EmbeddedRelated.com
Forums
Memfault Beyond the Launch

How to opena handle to "Cypress EZ-USB FX2 (68613) - EEPROM missing" and download a program to RAM

Started by Bill Davy June 7, 2007
But NOT using EZ-USB which I suspect is messing my programme up.  Perhaps it 
does not allow for the extra memory in the FX2LP.  I have written code to 
download a program (in hex or iic format) to RAM or EEPROM, but that was 
when the FX2 was running vend-ax (or our software, which is derived from 
it).  I just need to get a file handle and then use some library functionto 
send 0xA0 commands to fill memory (bracketed by setting and clearing Reset 
bit in CPUCS).

Or has someone already written this :-)

I tried using
SetupDiGetClassDevs() with various GUID:

static GUID GUID_0xe0317cca = {0xe0317cca, 0xbb7c, 0x4e2a, 0x9f, 0x28, 0xa6, 
0x98, 0xe6, 0x0e, 0xde, 0x99};

static GUID GUID_0x36FC9E60 = {0x36FC9E60, 0xC465, 0x11CF, 0x80, 0x56, 0x44, 
0x45, 0x53, 0x54, 0x00, 0x00};

And keep getting ERROR_NO_MORE_ITEMS even for interface number zero.


hCypress = CreateFile(\\\\.\\ezusb-0,GENERIC_WRITE,

FILE_SHARE_WRITE,

NULL,

OPEN_EXISTING,

0,

NULL);

yields a good handle but then

DeviceIoControl( hCypress, IOCTL_ADAPT_GET_DRIVER_VERSION,

&Ver, sizeof(Ver),

&Ver, sizeof(Ver),

&BytesReturned, NULL)

fails with "The parameter is incorrect".



I also tried the thing I really wanted to do and it failed with "The 
parameter is incorrect":



{

const unsigned iPage = 0;


const size_t BufferLength = 64;


const unsigned __int16 MemoryAddress = BufferLength * iPage;


const size_t InfoBlockSize = sizeof(SINGLE_TRANSFER) + BufferLength;

char InfoBlock[InfoBlockSize];

PSINGLE_TRANSFER pInfoBlock = (PSINGLE_TRANSFER)InfoBlock;

union

{

struct

{

UCHAR Recipient:5;

UCHAR Type:2;

UCHAR Direction:1;

} Bits;


UCHAR Byte;

} Request;

Request.Bits.Recipient = TGT_DEVICE;

Request.Bits.Type = REQ_VENDOR;

Request.Bits.Direction = DIR_FROM_DEVICE;


memset(InfoBlock,0,sizeof(InfoBlock));


pInfoBlock->SetupPacket.bmRequest = Request.Byte;

pInfoBlock->SetupPacket.bRequest = VR_ANCHOR_LOAD_INTERNAL;

pInfoBlock->SetupPacket.wVal.lowByte = LSByte(MemoryAddress);

pInfoBlock->SetupPacket.wVal.hiByte = MSByte(MemoryAddress);

pInfoBlock->SetupPacket.wIndex = 0x0000;

pInfoBlock->SetupPacket.wLen.lowByte = LSByte(BufferLength);

pInfoBlock->SetupPacket.wLen.hiByte = MSByte(BufferLength);

pInfoBlock->SetupPacket.ulTimeOut = 2; // Seconds ?

pInfoBlock->ucEndpointAddress = 0x00; // Endpoint 0

pInfoBlock->IsoPacketOffset = 0;

pInfoBlock->BufferOffset = sizeof(SINGLE_TRANSFER);

pInfoBlock->BufferLength = BufferLength;

DWORD BytesReturned = 0;


if ( ! DeviceIoControl( hCypress, IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER,

pInfoBlock, InfoBlockSize,

pInfoBlock, InfoBlockSize,

&BytesReturned, NULL) )

{

const LastErrorC LastError;

cerr << "DeviceIoControl() returned " << LastError << endl;

return 1;

}

else if ( BytesReturned != InfoBlockSize )

{

cerr << "BytesReturned=" << BytesReturned << ", InfoBlockSize=" << 
InfoBlockSize << endl;

return 1;

}

}


Any suggestions?

Many thanks

    Bill


Hi Bill,

I made a win32 commandline tool to personalize my product.  It starts
from a blank device ("EEPROM missing") and automatically does all the
necessary steps, including what you're looking for.

Download the Cypress developper kit which comes with the source code
to EzMr.  All the code is in there for you to cut&paste.  You have to
use DeviceIoControl() with a VENDOR_OR_CLASS_REQUEST_CONTROL for the
A0-Upload.

Regards,
Marc

"Bill Davy" <Bill@SynectixLtd.com> wrote in message
news:mridnY3yCPM4Q_rbRVnyvAA@bt.com...
> But NOT using EZ-USB which I suspect is messing my programme up. Perhaps
it
> does not allow for the extra memory in the FX2LP. I have written code to > download a program (in hex or iic format) to RAM or EEPROM, but that was > when the FX2 was running vend-ax (or our software, which is derived from > it). I just need to get a file handle and then use some library
functionto
> send 0xA0 commands to fill memory (bracketed by setting and clearing Reset > bit in CPUCS). > > Or has someone already written this :-)
I did that, but i wrote the driver and i don't know much about the development kit from Cypress. I only studied the examples about the firmware. Besides, i don't get what you mean when you say "But NOT using EZ-USB...". Do they provide different drivers for each chip?
"runner" <emb@dded> wrote in message 
news:46694bda$0$4796$4fafbaef@reader4.news.tin.it...
> > "Bill Davy" <Bill@SynectixLtd.com> wrote in message > news:mridnY3yCPM4Q_rbRVnyvAA@bt.com... >> But NOT using EZ-USB which I suspect is messing my programme up. Perhaps > it >> does not allow for the extra memory in the FX2LP. I have written code to >> download a program (in hex or iic format) to RAM or EEPROM, but that was >> when the FX2 was running vend-ax (or our software, which is derived from >> it). I just need to get a file handle and then use some library > functionto >> send 0xA0 commands to fill memory (bracketed by setting and clearing >> Reset >> bit in CPUCS). >> >> Or has someone already written this :-) > > I did that, but i wrote the driver and i don't know much about the > development kit from Cypress. I only studied the examples about the > firmware. Besides, i don't get what you mean when you say "But NOT > using EZ-USB...". Do they provide different drivers for each chip? > > > >
EZ-USB seems to be truncating the program at 8K when the FX2LP goes to 16 K. However, Marc's uggestion I look at EZMR may help (the wrapping is there too, but accessible). I too am now writng a command line (console) application to bring a chip up from the "No EEPROM" state. Hey ho Bill
> EZ-USB seems to be truncating the program at 8K when the FX2LP goes to 16
K.
> > However, Marc's uggestion I look at EZMR may help (the wrapping is there > too, but accessible). I too am now writng a command line (console) > application to bring a chip up from the "No EEPROM" state. >
There is no way you can upload the higher 8K by an "A0 Request". It is written somewhere in the manual. Don't ask me where. The last time i checked i had a hard time. The solution is to upload a small relocator first. It loads the higher 8K by relocating. Then you upload the lower 8K.
> There is no way you can upload the higher 8K by an > "A0 Request". It is written somewhere in the manual. > Don't ask me where. The last time i checked i had a > hard time. The solution is to upload a small relocator > first. It loads the higher 8K by relocating. Then you > upload the lower 8K.
An additional note for Bill: The Cypress devkit includes a source- code example called "a3load" which is basically what you describe above. Once loaded to the FX2, you can use A3 as opcode instead of A0. It has similar semantics, but is interpreted in software and has less limitations. The only thing to beware of is not to overwrite it while using it. Regards, Marc
"runner" <emb@dded> wrote in message 
news:46699ea3$0$17946$4fafbaef@reader1.news.tin.it...
>> EZ-USB seems to be truncating the program at 8K when the FX2LP goes to 16 > K. >> >> However, Marc's uggestion I look at EZMR may help (the wrapping is there >> too, but accessible). I too am now writng a command line (console) >> application to bring a chip up from the "No EEPROM" state. >> > > There is no way you can upload the higher 8K by an > "A0 Request". It is written somewhere in the manual. > Don't ask me where. The last time i checked i had a > hard time. The solution is to upload a small relocator > first. It loads the higher 8K by relocating. Then you > upload the lower 8K. > > >
The FX2LP core seems to load the 16K fine using A0 command. At least, I load 8K+ bytes and then verify they are as written. Sadly, some of the Cypress utilities hardwire the 8K limit so do not work for FX2LP. I found data intended for 8K+X was ending up in X Sadly, there is no easy way to find out what the processor is. If it was in a register it could be read using A0 command and a decision could be taken. By looking at the USB traffic (using http://sysnucleus.com/ which is really neat, and soon I will find out how to interpret the log and capture data in), I find CyConsole downloads its own loader to RAM before loading (large) EEPROM. I've copied the salient partsof vend_ax into my program and now Imust find out why it does not work. Hey ho. Thanks for the help and suggestions. Bill
"Bill Davy" <Bill@SynectixLtd.com> wrote in message
news:_IidnQhcvPQ36PPbnZ2dnUVZ8taknZ2d@bt.com...
> > "runner" <emb@dded> wrote in message > news:46699ea3$0$17946$4fafbaef@reader1.news.tin.it... > >> EZ-USB seems to be truncating the program at 8K when the FX2LP goes to
16
> > K. > >> > >> However, Marc's uggestion I look at EZMR may help (the wrapping is
there
> >> too, but accessible). I too am now writng a command line (console) > >> application to bring a chip up from the "No EEPROM" state. > >> > > > > There is no way you can upload the higher 8K by an > > "A0 Request". It is written somewhere in the manual. > > Don't ask me where. The last time i checked i had a > > hard time. The solution is to upload a small relocator > > first. It loads the higher 8K by relocating. Then you > > upload the lower 8K. > > > > > > > > The FX2LP core seems to load the 16K fine using A0 command. At least, I > load 8K+ bytes and then verify they are as written.
How do you show that?
"runner" <emb@dded> wrote in message 
news:466eb097$0$37205$4fafbaef@reader3.news.tin.it...
> > "Bill Davy" <Bill@SynectixLtd.com> wrote in message > news:_IidnQhcvPQ36PPbnZ2dnUVZ8taknZ2d@bt.com... >> >> "runner" <emb@dded> wrote in message >> news:46699ea3$0$17946$4fafbaef@reader1.news.tin.it... >> >> EZ-USB seems to be truncating the program at 8K when the FX2LP goes to > 16 >> > K. >> >> >> >> However, Marc's uggestion I look at EZMR may help (the wrapping is > there >> >> too, but accessible). I too am now writng a command line (console) >> >> application to bring a chip up from the "No EEPROM" state. >> >> >> > >> > There is no way you can upload the higher 8K by an >> > "A0 Request". It is written somewhere in the manual. >> > Don't ask me where. The last time i checked i had a >> > hard time. The solution is to upload a small relocator >> > first. It loads the higher 8K by relocating. Then you >> > upload the lower 8K. >> > >> > >> > >> >> The FX2LP core seems to load the 16K fine using A0 command. At least, I >> load 8K+ bytes and then verify they are as written. > > How do you show that? > >
By loading all 9K into RAM and then checking. Had there been wrap around, the bottom 1K would not verify, though the top 1K would, spuriously. That's why I load all 9K in and then verify all 9K. Simple read-after-write verification provides spurious reassurance.
> > How do you show that? > > > > > > By loading all 9K into RAM and then checking. Had there been wrap around, > the bottom 1K would not verify, though the top 1K would, spuriously.
That's
> why I load all 9K in and then verify all 9K. Simple read-after-write > verification provides spurious reassurance. >
What i don't understand is... you said: "I just need to get a file handle and then use some library function to send 0xA0 commands to fill memory". And then you said that you have troubles in doing so. So i ask you "how could you issue an 0xA0 request and see it working?" Is 0xA0 request working? Is your vend-ax derived code working? As i told you i don't remember where i read about the 8K limitation. (Perhaps i had a vision). But i remember that John Hyde used the "mover code trick" in a loader driver. I didn't base my driver on that so i can't tell you more. Note: the driver was for the older version of the ez-usb chip, AN21xx.

Memfault Beyond the Launch