USB low-full-high speed peripherals Forum Discussions
First, a doc error. The help says that OverlapSignalAllocSize is a public read-only Property of the CyUSB class. This is not true. It is actually a member of CyUSBEndPoint. This is unfortunate, because it means we need an actual instance of a CyUSBEndPoint in order to call OverlapSignalAllocSize. It would be better if it was a static method as part of the CyConst class, so that it could be called without an instance to any objects.
Second, I want to know if there's a reason that the data transfer buffers are all ref'd. I believe they are ref'd because, in the previous C++ implementation, we needed to pass objects by reference to avoid calling the copy constructor. This is not necessary in C#, because the caller passes the callee a copy of the reference. What the ref keyword does is pass the caller's original reference instead of a copy.
I think this was an honest mistake made by a C++ programmer who was learning .NET and didn't know that the ref keyword is very different from the & symbol in a C++ parameter list. However, by forcing the buffers to be ref, the CyAPI.NET library becomes much more awkward to use, as there are severe limitations on what you can pass to a ref parameter.
Finally, and most seriously, I believe there is a major bug involving passing buffers from Managed to Unmanaged code. This bug could be why everyone has such problems with calling the asynchronous Begin/Wait/FinishDataXfer methods.
First, a brief review of garbage collection. To keep the heap from becoming too fragmented, the CLR is allowed to re-arrange the contents of memory on a whim. It then updates all the Managed references to point to the re-arranged contents accurately. However, the CLR has no way to tell Unmanaged pointers that it has moved the contents of memory around.
Now, I suggest pulling up the help file for BeginDataXfer() and looking at the example. Note the use of the fixed { } block surrounding the creation of the Overlapped's hEvent member. That fixed block is there likely because the compiler complains otherwise, but there's a good reason why we need it.
The fixed keyword tells the CLR that the parameter (in this case, the ovLaps buffer) must be pinned in memory, so that the unmanaged code in the block doesn't get burned by the CLR's garbage collector. This is important because otherwise ovLaps could move somewhere else between the cast to an OVERLAPPED* and the call to CreateEvent, causing CreateEvent to write into memory that might be owned by another process.
Finally, the problem. I was transferring back and forth between the device using worker threads, and noticed that if I used the menu bar, the application would lock up or crash the main thread. I believe that the menu bar was causing a lot of small objects to be created and then freed, which fragmented the heap, causing the CLR to re-arrange memory, moving my buffer while the driver was in the middle of transferring.
This would cause all sorts of problems. Sometimes, my app would lock up. Not even Visual Studio's stop button would end the process. Other times, the main thread (NOT the worker thread!) would throw a NullReferenceException, or even the exotic ExecutionEngineException; I believe this was because the driver was running in the main thread's context while the garbage collector moved the buffer. While somewhat random, the crashes were easy to reproduce and typically happened after only a few seconds. The exceptions and freezing would stop if I commented out the transfer.
The solution is to pin the buffers for the duration of the transfer. ALL of the buffers; the single transfer, the overlapped, and the data buffer. You could do this by using three fixed blocks, however I prefer the GCHandle class for pinning objects.
I created a class called PinnedBuffer and, in the constructor, I used GCHandle to pin the buffer. I then use this PinnedBuffer class for all three buffers. The byte[] needs to be a public field so that you can use it with the data transfer methods' ref parameters (see the previous issue). I haven't had any problems since I started pinning all my buffers.
I don't know whether the XferData method pins all of its buffers for the duration. I do know that their example code for their asynchronous methods only momentarily pins the overlap buffer and that is probably why people have so many problems with the asynch code. All three byte[] buffers need to be pinned before the transfer begins until after it finishes. Show Less
Hi all,
We've been using EZ-USB for many years to build applications for our products without any problem. Recently we've switched to Windows 7 (32-bit), and even after installing CYUSB to replace EZ-USB, are having intermittent problems running hex2bix under windows 7.
When I run HEX2BIX from a command prompt it fails (as reported by windows) about 25% of the time (once or twice out of five or six tries). Has anyone else seen this behavior? I've tried changing the program's compatibility mode, but this causes Windows to ask if it's OK to let the program make changes to the system every time it runs (a typical build compiles a dozen modules, so that's a PIA).
Thanks,
Scott
Show Lesshi
how to make icc file to make 3684 development board work in slave fifo.
I know I should write a program to set some registers like
IFCNFG = 0x3
. . .
but how to convert the code to icc.
i have uvision installed on my pc.
Show LessHi,
I am trying to measure the FX2LP USB chip througput in bulk mode. In order to do so, I have modified bulk example firmware so it continiously fills the two output endpoints (0x86, 0x88) with 512 data bytes. I have also changed the BulkLoop C# application to read the data from those two endpoints. I have measured the time between start and stop commands and the number of bytes I was able to read from the device in this time. My result was about 0.8 MBytes/s, but I was expecting much higher throughput.
I am using Win7-64. How can I verify that the system operates in high speed and not in fast speed (0.8MBytes/s seems like fast speed mode to me)? Is there another possible reason for such low speed?
Thanks, Alexey.
Show Lesshi
this is my first time with the USB controller.i am implementing a design in which i have to read data from the FIFO placed in the FPGA and send data to the PC through USB controller
i need to know a few things regarding the data rate that is achiveable on the USB interface. acc to datasheet there are two data rates achiveable
1. Full Speed 12Mbps
2. High speed 48Mbps
i want to know are these data rates are actually achived? if not what throughput is that i get on the interface between the USB controller and the PC?
can anyone help me on this??
Regards
Usama Aslam
Show LessDear sir,
We choose CY7C68013A to implement our project. And the firmware is based on BulkLoop. Of course, we have added the needed code what will help us. But the problem is that: while we burning the iic file(C2 load) into our lardge eeprom(24C128), the CyConsole can not recognise our board. So, we cut some code and retry the front steps, Oh....it can recognise our board!
We have no idea about it! Why? The CY7C68013A restrict the code size ? But, the <EZ-USB TRM> has specified that it has 16KB internal RAM which is Program&Data(We set EA=0).
So, help me please! Thanks so much!
Josh Wei
Show LessHow can I tell that the CY7C68013 is enumerated? I need to send notification to the hardware (via firmware) that the USB cable has been unplugged.
Show LessDear Sir.
We choose CY7C64356 and use the BootLdrUSBFS module to implement our project.
BootLdrUSBFS module has bootloader and application parts.
We have two targets.
A. Device has 2 USB interfaces and bootloader functionality.
This 2 USB interfaces are used to control 2 device.
B. Device has 3 USB interfaces and bootloader functionality.
This third USB interface is used to control another device.
First we have finished the part A. It works well.
And then we use part A to add another interface.
We use bootloader tool to update the firmware of CY7C64356 from part A to part B.
We found a situation.
After bootloader tool is finished, the CY7C64356 will auto reset continually.
We make some experiments.
We use PSoC Programmer and Mini-Prog tool to make the samples like (1) and (2).
(1) The firmware of CY7C64356 is part A.
(2) The firmware of CY7C64356 is part B.
(3) Use booloader tool to update the firmware of CY7C64356 from part A to part B.
And then on, we use PSoC Programmer and Mini-Prog tool to read the firmware of CY7C64356 from above samples.
We found there are some differences.
About the bootloader code part.
(2) and (3) is not equal.
(1) and (3) is equal.
About the application code part.
(1) and (3) is not equal.
(2) and (3) is equal.
We survey the .mp file and found some thing.
There are functions and global variables are allocated into the bootloader part, like BootLdrUSBFS_Start, BootLdrUSBFS_LoadInEP, BootLdrUSBFS_IdleReload, BootLdrUSBFS_Protocol, etc.
Can we fiexd the bootloader code in our firmware? or other suggections. Thanks so much.
Show LessSomeone has made his own board ?? So he can share his schematics as guide for make my own ??
My senior engineer who was responsible for completing the C code for the CY7C68013A to interface between an AD ADAU1442 DSP to a Windows XP system and then to Android has fallen ill (long term). So, I have to take over and start again. Is there C code for this Cypress controller that I can download? Are there any application notes/examples for using the Cypres USB peripheral controller to talk to an Analog Devices' audio DSP Sigma Studio development software? Anyone want a contract to get this done? Schematic of CY7C68013A on the DSP board is attached.
Show Less