Question about CYUSB3014 AN84868 C# APP programming

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
KIMI_4749046
Level 2
Level 2
10 replies posted 5 replies posted 5 questions asked

Hello,

I developed to configure FPGA board using FX3.0 chip.

I used the C# application program developed with Form based project.

C# Form based APP program runs well.

I changed the C# Form based program to C# console based program.

My question is below...

In console based programs,  how to operate  two process sequentially runs.

1. download fx3.0 fw program 2. download fpga binary.

I did it.

But after first running...

"myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;" is   NULL...

second running is ok..

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
1 Solution
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

After the firmware download is complete, the device should enumerate correctly and the application should be able to access the device. Only then the FPGA binary can be transferred. If while(true) cannot be used, then please try the following:

            for (i = 0;i<10; i++)
            {
               
                usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

                myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;
                Thread.Sleep(1000);  //important

                if (myDevice != null)
                {
                    break;
                }
            }

In this way, the loop will work for 10 iterations only and will exit if the device is not detected. If the device is not detected, then the same can be printed in the console.  Similar implementation is used in the source code of control center application (where a timeoutCounter is used inside an infinite loop) for checking if the boot programmer device is enumerated or not.

Best Regards,
Jayakrishna

View solution in original post

0 Likes
11 Replies
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

Please find my questions related to the following statements in your description so that we can understand the problem better:

1. "In console based programs,  how to operate  two process sequentially runs"

As per my understanding, the two processes are

a. Download FW to FX3 RAM

b. Download the FPGA binary

Please correct me if my understanding is wrong. If my understanding is correct, FX3 should be enumerated as FX3 Bootloader device (VID: 04B4 and PID: 00F3) on the host side when the host application is started.

2. Please elaborate the following statement in your description:

But after first running...

"myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;" is   NULL...

second running is ok..

What exactly did you mean by first running and second running? 

3. Please elaborate the flow of your host application.

Best Regards,
Jayakrishna
0 Likes
KIMI_4749046
Level 2
Level 2
10 replies posted 5 replies posted 5 questions asked


1. C# form project is modified from "AN84868" FPGA Configuratin Utility. It runs well.

I want to change from the GUI program to console (cmd) program.

The problem is the console program.

<My sequence is >

First turn on the fpga board.

 a. Download FW to FX3 RAM --> ok.

b. Download the FPGA binary --> fail.

Rerun the program (the board is remained to be turned on)

a.  Download FW to FX3 RAM --> pass

b. Download the FPGA binary --> ok.

////////////////////////////////////////////

myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;             
myFX3Device = usbDevices[0x04B4, 0x00F3] as CyFX3Device;

When I firstly turned on the board, I got the myFX3Device with contens and myDevice with NULL.

second running program I got the myDevice with contents.

C# form program is consisted of three button on GUI.

Console based program is only cmd.

I make the 1. Prgram class and several functions.

How to modify the console program.

first turn on the board a. and b. runs well.


 

0 Likes

Overall program is below....

 

    class Program
    {
        CyUSBDevice myDevice;              
        CyUSBDevice myFX3Device;
        USBDeviceList usbDevices;

        CyBulkEndPoint BulkOutEndPt;
        CyControlEndPoint CtrlEndPt;
        .......

        public void GetDevice()
        {
            if (DeviceAttached == true)
            {
                myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;
                myFX3Device = usbDevices[0x04b4, 0x00F3] as CyUSBDevice;

                // Download fw code
                if ((myFX3Device != null) && (myDevice == null))
                {
                    Console.WriteLine("FX3 Bootloader Device connected\n");

                    Download_BootFW();
                }

                // Select bit stream
                else if ((myFX3Device == null) && (myDevice != null))
                {
                    BulkOutEndPt = myDevice.EndPointOf(0x02) as CyBulkEndPoint;   //Assign EP2 as BulkOutEP and EP6 as BulkInEP
                    Console.WriteLine("\nFX3 FW Programmer detected\n");
                }
    ........             
            }
        }

        private void Download_BootFW()
        {
            CyFX3Device fx = myFX3Device as CyFX3Device;
            ;;;
  
            if (fx != null)

 ;;;;}


        private void Download_FpgaBin()
        {  
            if (myDevice != null)      <=======first run: myDevice is null, second run: myDevice has contents and FX3 FW Programmer detected.
            {
                Console.WriteLine("\nWriting data to FPGA.... \n");
                CtrlEndPt = myDevice.ControlEndPt;
                CtrlEndPt.Target = CyConst.TGT_DEVICE;
                CtrlEndPt.XferData(ref buf, ref len);
         .....
}

        public Program()
        {      
                 
            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);                  

            GetDevice();

            Download_FpgaBin();
        }

        static void Main (string[] args)   <=== how to modify this... ......
        {
            new Program();

            Console.WriteLine("\nPress Enter to Exit.\n");
            Console.ReadKey();           
        }   

0 Likes
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

It seems like the list usbDevices is not getting updated after the firmware download is complete.

Can you please try the following logic and check if you are able to perform the two processes sequentially?

1. As done now, perform the FW download.

2. After the firmware download is complete, use the following lines of code to check if the device with VID 0x04B4 and PID 0x00F1 is detected or not:

while(true)

{

       usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

      myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;

      if(myDevice != null)

      {

             break;

      }

If the device is detected, then the control will come out of the while loop. 

3. After this, the second process that is download FPGA binary can be done.

Please try this and let me know the results.

Best Regards,
Jayakrishna
0 Likes
KIMI_4749046
Level 2
Level 2
10 replies posted 5 replies posted 5 questions asked


Writing data to FPGA....

>> NEXT STEP: Wait ...

Configuration data has been sent to FPGA

Configuration Failed

NEXT STEP: Please Repeat the Steps Carefully

///////////////////////////////////////

 

But after setting breakpoint below line , the result is ok ... why?? do you know?????

"    myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;"

I  inserted the code to Program()

 

 public Program()
        {                      
          usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);                     

            GetDevice();

            while (true)
            {
                usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

                myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;

                if (myDevice != null)
                {
                    break;
                }
            }

            usbDevices.DeviceAttached += new EventHandler(UsbDevices_DeviceAttached);  

            usbDevices.DeviceRemoved += new EventHandler(UsbDevices_DeviceRemoved);    

            Console.WriteLine("FPGA Configuration Start\n");

            Download_FpgaBin();
      

        }

0 Likes
KIMI_4749046
Level 2
Level 2
10 replies posted 5 replies posted 5 questions asked

after inserting " Thread.Sleep(1000);  //important" , the result is ok. thank you for your help.....

            while (true)
            {
               
                usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

                myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;
                Thread.Sleep(1000);  //important

                if (myDevice != null)
                {
                    break;
                }
            }

0 Likes
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

Please let me know if the issue is resolved with the addition of Thread.Sleep(1000);?

Best Regards,
Jayakrishna
0 Likes
KIMI_4749046
Level 2
Level 2
10 replies posted 5 replies posted 5 questions asked

Yes,  the problem is resolved with inserting your code and the addition of Thread.Sleep(1000).

But I think inserting "while(true) ..." code is dangerous for PC.

Is there more safe code?

0 Likes
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

After the firmware download is complete, the device should enumerate correctly and the application should be able to access the device. Only then the FPGA binary can be transferred. If while(true) cannot be used, then please try the following:

            for (i = 0;i<10; i++)
            {
               
                usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

                myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;
                Thread.Sleep(1000);  //important

                if (myDevice != null)
                {
                    break;
                }
            }

In this way, the loop will work for 10 iterations only and will exit if the device is not detected. If the device is not detected, then the same can be printed in the console.  Similar implementation is used in the source code of control center application (where a timeoutCounter is used inside an infinite loop) for checking if the boot programmer device is enumerated or not.

Best Regards,
Jayakrishna
0 Likes
KIMI_4749046
Level 2
Level 2
10 replies posted 5 replies posted 5 questions asked

@KIMI_4749046 wrote:

Hello,

I developed to configure FPGA board using FX3.0 chip.

I used the C# application program developed with Form based project.

C# Form based APP program runs well.

I changed the C# Form based program to C# console based program.

My question is below...

In console based programs,  how to operate  two process sequentially runs.

1. download fx3.0 fw program 2. download fpga binary.

I did it.

But after first running...

"myDevice = usbDevices[0x04b4, 0x00F1] as CyUSBDevice;" is   NULL...

second running is ok..

 

 

 

 

 

 

 

 

 

Thank you. the program is more stable.  It runs well.


 

0 Likes
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

We are glad to hear that the issue is resolved.

Best Regards,
Jayakrishna
0 Likes