Set up CyUSB3KIT-003 for transfer data to to the PC via USB.

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

cross mob
YeVe_4753746
Level 2
Level 2
10 sign-ins 5 replies posted 5 sign-ins

Hi All!

I am a very new at hardware programming.
I try to solve next task.
Some board continuously generates a 16-bit data and clock. Signal data must be transferred to the PC via USB. This board doesn't have any control signals, any adresses and any flags. Only 16-bit data and clock. I use CyUSB3KIT-003 to connect my board with PC. The board is already connected to CyUSB3KIT-003 via GPIO 0-15 (for data) and GPIO 16 (for clock). It needs set up CyUSB3KIT-003 for transfer data to to the PC via USB.
I think I can use "The synchronous Slave FIFO interface of EZ-USB® FX3™ " example described at AN65974 document to solve my task. But I'm not sure.

Help me please understand next points. First, should I use GPIF in my case or not? Maybe there is some other easier way? And, secondly, If it needs use GPIF, is there some fixed sequence for creating interface?

Also I will be grateful for any advice for solving this task.

0 Likes
1 Solution
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hello,

For a 16 bit parallel data, GPIF must be used ideally. GPIO bus cant be used as the data cant be synchronized.

If using a "synchronous Slave FIFO interface of EZ-USB® FX3", control signals are required(Ex. CS, WR, RD). But as there are no control signals provided for your particular application, GpifToUsb project in the EZ-USB SDK firmware can be used(C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples\cyfxgpiftousb). There is no flow control provided here. This will lead to data loss. 

To avoid data loss, this project needs to be modified by using appropriate control signals from the external peripheral. This will include modification on GPIF II state machine also. Please define and share the custom interface timings so that we can evaluate the possibilities and help you to develop a GPIF II state machine.

Best Regards,

AliAsgar

 

View solution in original post

9 Replies
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hello,

For a 16 bit parallel data, GPIF must be used ideally. GPIO bus cant be used as the data cant be synchronized.

If using a "synchronous Slave FIFO interface of EZ-USB® FX3", control signals are required(Ex. CS, WR, RD). But as there are no control signals provided for your particular application, GpifToUsb project in the EZ-USB SDK firmware can be used(C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples\cyfxgpiftousb). There is no flow control provided here. This will lead to data loss. 

To avoid data loss, this project needs to be modified by using appropriate control signals from the external peripheral. This will include modification on GPIF II state machine also. Please define and share the custom interface timings so that we can evaluate the possibilities and help you to develop a GPIF II state machine.

Best Regards,

AliAsgar

 

Hello, Ali Asgar! Unfortunately I have some issue with this example.  I try to implement some code which download firmware and write some data from external device to file on PC. I use DownloadFw() function like here:

status = m_usbDevice->DownloadFw("D:\\GpifToUsb.img", FX3_FWDWNLOAD_MEDIA_TYPE::RAM);

And I use XferData() function via BulkInEndPt like here:

m_usbDevice->BulkInEndPt->XferData(data, bufferLength);

 But in this place of code the program throws an exception and 

m_usbDevice->BulkInEndPt = nullptr

And when I use the same firmware (GpifToUsb.img) via USB Control Center, then the data is transferred.

Why is it so? What should be done to fix the problem?

0 Likes

Hello,

Could you share with us the host application source. 

Also, Does the device enumerate(in Device Manager) after programming it with gpifToUsb firmware.

Best Regards,

AliAsgar

0 Likes

Yes. The device enumerated after programming it with gpifToUsb firmware. I see that at Control Center and at my application. But now I have FALSE after next operation.

bool XferDataCondition = m_usbDevice->BulkInEndPt->XferData(data, bufferSize);

And I can't get any transactions in my application. There are my application's code:

 

#pragma once

namespace CppCLRWinformsProjekt {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace CyUSB;
	
	/// <summary>
	/// Zusammenfassung fьr Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufьgen.
			//
			usbDevices = gcnew USBDeviceList(CyConst::DEVICES_CYUSB);
			usbDevices->DeviceAttached += gcnew EventHandler(this, &Form1::usbDevices_DeviceAttached);
			usbDevices->DeviceRemoved += gcnew EventHandler(this, &Form1::usbDevices_DeviceRemoved);
		}

		void usbDevices_DeviceAttached(Object^ sender, EventArgs^ e)
		{
			//Add code to handle Device arrival
			usbDevices->Add();
			System::Collections::IEnumerator^ enumerator = usbDevices->GetEnumerator();
			enumerator->MoveNext();
			m_usbDevice = (CyFX3Device^)enumerator->Current;
			FX3_FWDWNLOAD_ERROR_CODE status = m_usbDevice->DownloadFw("D:\\GpifToUsb.img", FX3_FWDWNLOAD_MEDIA_TYPE::RAM);
			textBox1->AppendText("FX3_FWDWNLOAD_ERROR_CODE " + status.ToString() + "\x0D\x0A");
			textBox1->AppendText("Device Attached \x0D\x0A" + enumerator->Current->ToString() + "\x0D\x0A");
		}

		void usbDevices_DeviceRemoved(Object^ sender, EventArgs^ e)
		{
			//Add code to handle Device removal
			textBox1->AppendText("Device Removed" + "\x0D\x0A");
			
		}
	
	protected:
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}

	private:
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		System::ComponentModel::Container ^components;
        
		System::Windows::Forms::Button^ button1;

		
		//GpifUsbConnector^ gpifUsbConnectorInstance = GpifUsbConnector::gpifUsbConnectorInstance;

		USBDeviceList^ usbDevices;
		CyUSBDevice^ myDevice;
	private: System::Windows::Forms::TextBox^ textBox1;
		   CyFX3Device^ m_usbDevice;
		   
#pragma region Windows Form Designer generated code
		/// <summary>
		/// Erforderliche Methode fьr die Designerunterstьtzung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geдndert werden.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(47, 29);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(124, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"SendDataToUsb";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(236, 29);
			this->textBox1->Multiline = true;
			this->textBox1->Name = L"textBox1";
			this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Both;
			this->textBox1->Size = System::Drawing::Size(350, 714);
			this->textBox1->TabIndex = 1;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(697, 789);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
private:
	int bufferSize = 10;
	array <unsigned char>^ data = gcnew array <unsigned char>(bufferSize);

	public:
		System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
				
			for (int i = 0; i < 10; i++) {
				bool XferDataCondition = m_usbDevice->BulkInEndPt->XferData(data, bufferSize);
				textBox1->AppendText("XferDataCondition = " + XferDataCondition + "\x0D\x0A");
				for each (unsigned char var in data)
				{
					textBox1->AppendText(var + "\x0D\x0A");
				}
			}
			textBox1->AppendText("m_usbDevice->BulkInEndPt->LastError " + m_usbDevice->BulkInEndPt->LastError + "\x0D\x0A");
		}
};
}

 

I will so grateful if You help me understand which reason my application doesn't work?

Best Regards,

Yevhen

0 Likes

Hi Yevhen,

You could try this:

int bufferSize = m_usbDevice->BulkInEndPt->MaxPktSize;
array <unsigned char>^ data = gcnew array <unsigned char>(bufferSize);
m_usbDevice->BulkInEndPt->timeout = 2000;
bool XferDataCondition = m_usbDevice->BulkInEndPt->XferData(data, bufferSize);

This is because it is expected that the host requests the data in multiple of maximum packet size

Best Regards,

AliAsgar

 

0 Likes

Hi AliAsgar,

thank you a lot for help. I see some data in my applicaton. But this is a repeating number. Although this number should change over time. I think it becose I need use IsocInEndPoint. But when I try use IsocInEndPoint insted of  BulkInEndPoint I have got exception m_usbDevice->IsocInEndPt = nullptr.

Could You answer me please which reason I have this exception?

Best Regards,

Yevhen

0 Likes

Hi Yevhen,

Could you send us the snippets of the inputs given to the Gpif and outputs at the host side.

Also, it is recommended to keep the endpoint as bulk type.

Best Regards,

AliAsgar.

0 Likes

AliAsgar, sorry for the delay. Could You please explain how I can define the custom interface timings?

0 Likes

Hi Yevhen,

When the data is being sent to the dma buffers,  there maybe data loss during the dma switching time. So flow control has to be taken care of. For the custom interface,                                                               1. Flags like 'Ready' and 'Watermark' can be used.                                                                                                      2. The control signals can be used in the GPIF state machine to control the data transfer.

AN65974 app note can be referred for more information on gpif interface flags.

Best Regards,                                                                                                                                                                                  AliAsgar

 

0 Likes