FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
5892 Discussions

DE2 115 : Trying to send/receive usb bulk data from ISP1362 to FTDI 232H chip

Altera_Forum
Honored Contributor II
3,727 Views

Hi everyone, 

 

I'm trying to use the isp 1362(host mode) with nios2 to communicate with a FTDI 232H chip (bulk transfer mode supported only). 

Everything is fine, i can get the descriptor of the FTDI chip and i'm connected in full speed mode . (VID, PID, MaxPacketSize etc..) 

VID = 0x403 

PID = 0x6014 

MaxPckt = 0x40 

There is a PTD.c file provided by Terasic with multiple methods to handle all 4 usb transfert modes which are : 

 

-send_iso for isochronous 

-send_int for interrupt 

-send_control for control 

-send_ptl (what is that?) 

 

I just want to send a byte in bulk mode (ie 0xAA) 

What is the right way to do this? 

 

i would say i should make a ptd with "void make_ptd(int *rptr,char token,char ep,int max,char tog,char addr,char port)" 

But what should i put in the rptr[4], rptr[5], rptr[6] and rptr[7]? Is there a special code to put next the ptd to do an OUT transfer like in Control transfer? Or should i just put the data after the ptd? 

 

Well i'm quite lost for now... 

 

If any got the solutions.. 

 

And thanks to you for your concern. :rolleyes: 

 

Ps: it's mandatory for me to use the isp1362 with nios2
0 Kudos
13 Replies
Altera_Forum
Honored Contributor II
471 Views

Hi, 

 

 

--- Quote Start ---  

I'm trying to use the isp 1362(host mode) with nios2 to communicate with a FTDI 232H chip (bulk transfer mode supported only). 

Everything is fine, i can get the descriptor of the FTDI chip and i'm connected in full speed mode .  

--- Quote End ---  

 

 

Then this means you have made good progress.Nice. 

 

 

 

--- Quote Start ---  

 

--- Quote Start ---  

There is a PTD.c file provided by Terasic with multiple methods to handle all 4 usb transfert modes which are : 

 

-send_iso for isochronous 

-send_int for interrupt 

-send_control for control 

-send_ptl (what is that?) 

 

I just want to send a byte in bulk mode (ie 0xAA) 

What is the right way to do this? 

 

i would say i should make a ptd with "void make_ptd(int *rptr,char token,char ep,int max,char tog,char addr,char port)" 

But what should i put in the rptr[4], rptr[5], rptr[6] and rptr[7]? 

--- Quote End ---  

 

 

Sorry but I don't have idea about this. Particularly I don't have file which you are referring. Hence don't know what is the use of rptr.  

 

 

--- Quote Start ---  

Is there a special code to put next the ptd to do an OUT transfer like in Control transfer? 

--- Quote End ---  

 

No. But you should put Bulk OUT request after SET CONFIGURATION request. USB device responds to bulk out after its configuration is set by host using SET CONFIGURATION request. Have you performed this request? Do you have some reference available or are you trying to do this your own? Asking this to know whether you have just got device descriptor or have already enumerated device. 

 

 

--- Quote Start ---  

Or should i just put the data after the ptd? 

--- Quote End ---  

 

Payload offset starts immediately after PTD offset according to ISP1362 datasheet. Are you asking this? 

 

 

 

--- Quote Start ---  

Well i'm quite lost for now... 

--- Quote End ---  

 

Don't worry! Be happy. We will see if we can help you.
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

Hi Mr Bhaumik, 

first of all, thanks for your reply, i appreciate. 

 

I'm sorry i'm at home, so i don't have the files. I will put them on my next reply monday. 

I refered to Terasic example "Nios Host mouse vga" to get the descriptor, via "get_control" "send_control" functions. I set an adress to the FTDI chip on the port on which it's connected. Is that you mean by "set configuration"?  

 

As you said yes i tried to to put the payload just after the ptd. 

I'm surprised because i can see that i got a response with a completion code of 0x0 which means transaction has been successful. But nothing happened on the Led i connected to FTDI out port. I precise that the ftdi works fine because i tested it with a computer. 

 

I'll send you my code as soon as possible. 

 

And thanks again.
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

Hi, 

 

Here are few comments from my side: 

(1) You seems to have performed SET ADDRESS request. This is different from SET CONFIGURATION request. As per my knowledge, host should access endpoints other than default control endpoint only after configuring device using SET CONFIGURATION. Anyway, in general basically atleast following requests are performed ( you might be able to find this in the example which you are using) : 

  1. GET DEVICE DESCRIPTOR with 0x8 bytes ( @ default address ) 

  2. SET ADDRESS ( @ default address ) 

 

 

All requests after this will use new address 

  1. GET DEVICE DESCRIPTOR with 0x12 bytes 

  2. GET CONFIGURATION DESCRIPTOR with 0x9 bytes 

  3. GET CONFIGURATION DESCRIPTOR with full configuration descriptor length 

  4. SET CONFIGURATION 

 

 

 

Now, in your case you can perform Bulk OUT request. 

 

 

 

--- Quote Start ---  

I'm surprised because i can see that i got a response with a completion code of 0x0 which means transaction has been successful. But nothing happened on the Led i connected to FTDI out port. 

--- Quote End ---  

 

 

This would be interesting to see why this is not working. 

 

Please let me know if I am confusing at any point. 

 

Regards, 

Bhaumik
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

Hi again, 

 

i'm now reading chapter 9 of usb 2 manual to understand what i'm doing... 

 

 

here are the arrays you need to put after a setup ptd to get descriptors 

 

--- Quote Start ---  

 

unsigned int get_control(unsigned int *rptr,unsigned int addr,char control_type,unsigned int extra,int port) 

unsigned int cbuf[128]; 

unsigned int rbuf[128]; 

unsigned int cnt=0,lcnt=0; 

unsigned int toggle_cnt=0; 

unsigned int word_size; 

unsigned int DesSize,MaxSize; 

 

unsigned int dev_req[4]={0x0680,0x0100 ,0x0000,0x8}; 

unsigned int cfg_req[4]={0x0680,0x0200 ,0x0000,0x8}; 

unsigned int str_req[4]={0x0680,0x0300 ,0x0000,0x8}; 

unsigned int int_req[4]={0x0680,0x0400 ,0x0000,0x8}; 

unsigned int end_req[4]={0x0680,0x0500 ,0x0000,0x8}; 

unsigned int hid_req[4]={0x0681,0x2100 ,0x0000,0x8}; 

 

--- Quote End ---  

 

 

As you can see, it's a bit confusing cause offsets here are not the same as it's shown in the manual. It's irritating :/ 

 

0x06 = bRequest field => type of request (get_descriptor here) 

0x08 = bmRequestType 

0x0100 = descriptorType = device  

etc.. 

 

i'm just wondering why you put 0x12 bytes in get device descriptor after setting the address and 0x9 for get config descriptor. 

 

arrrgh this thing makes me mad.. 

Pci express was almost easier for me... or i'm not normal
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

Hello, 

 

 

--- Quote Start ---  

As you can see, it's a bit confusing cause offsets here are not the same as it's shown in the manual. It's irritating :/ 

 

0x06 = bRequest field => type of request (get_descriptor here) 

0x08 = bmRequestType 

0x0100 = descriptorType = device  

etc.. 

--- Quote End ---  

 

 

Hope following will help to clear your doubt. 

unsigned int dev_req[4]={0x0680,0x0100 ,0x0000,0x8}; 

dev_req[0] = 0x0680 ( Lower byte is 0x80 which is bmRequestType, Higher byte is 0x06 which is bRequest ) 

dev_req[1] = 0x0100 ( This 2 bytes are for wValue. Lower byte is 0x00 and upper byte is 0x01 which indicates Device descriptor.) 

dev_req[2] = 0x0000 ( This 2 bytes are for wIndex. For device descriptor this field is 0.) 

dev_req[3] = 0x0008 ( This 2 bytes are for wLength. This is 8 means we are expecting device to send 8 bytes in response to this request.) 

 

Reference: 9.4.3 Get Descriptor and Table 9-2 from USB2.0 Specification 

 

 

 

--- Quote Start ---  

i'm just wondering why you put 0x12 bytes in get device descriptor after setting the address and 0x9 for get config descriptor. 

--- Quote End ---  

 

I think, at present, you do not need to worry about this. I will answer later on. 

 

 

--- Quote Start ---  

arrrgh this thing makes me mad.. 

Pci express was almost easier for me... or i'm not normal 

--- Quote End ---  

 

Hey brother, you are absolutely normal. PCI express may be simpler, but USB is also not that much difficult. At initial stage, it seems difficult but then you will love it. 

 

 

Could you share code which you used to perform Bulk Request? I would like to check whether you are using correct endpoint number and device address. 

 

Have a Nice day. 

 

Regards, 

Bhaumik
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

oups sorry i forgot the code, but i'm sure i'm setting address 2 on port 2 (after get descriptor config) and 0 for endpoint (but i don't know how to check if it's good or not). I will give you what i wrote as soon as i'll get in front on my screens tomorrow. 

 

cheers.
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

hi, 

how are you today? 

 

 

here is the file, the main program is "main_prog_BULK_transfer" (at the end) + USB.c with "send_bulk" method i'm trying to do. 

There is a screenshot of what i receive in debug console. 

 

I'm just trying things so don't pay attention to the mess :oops:
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

ok ok ok, i just need to list endpoints of the device, using get descriptor endpoint. Things begin to be more clear.

0 Kudos
Altera_Forum
Honored Contributor II
471 Views

Hi again Bhaumik, 

 

it looks like it's working now. I send the byte to the led with bulk data out to endpoint number 2 (i tried 1 & 2, 0 is for control). I don't know how to get a list of that. 

But i have some questions fo you: 

 

-Why do i receive nothing when i ask a get_configuration? (get_config[] = {0x0880, 0,0,1};) 

-How can I know the endpoint number where i should send data? In the demo program, with interrupt mode for mouse, it's shown it receive data from endpoint 1, what the hell? looks like arbitrary for me.
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

Hi, 

 

I am sorry. I am busy with some other work and have not looked at your code yet. But glad to hear that you made progress. 

 

Here are quick answers to your questions. 

 

 

--- Quote Start ---  

-Why do i receive nothing when i ask a get_configuration? (get_config[] = {0x0880, 0,0,1};) 

--- Quote End ---  

 

You should be getting one byte but its value will be zero. You are interested in Endpoint descriptor. Hence you should perform GET_DESCRIPTOR ( with descriptor type = Configuration ). Please observe difference between GET_CONFIGURATION request and GET_DESCRIPTOR ( with descriptor type = configuration.)  

 

 

--- Quote Start ---  

-How can I know the endpoint number where i should send data? In the demo program, with interrupt mode for mouse, it's shown it receive data from endpoint 1, what the hell? looks like arbitrary for me. 

--- Quote End ---  

 

From previous posts, it seems you are thinking in correct direction. To get list of available endpoints you need to perform GET_DESCRIPTOR ( descriptor type= configuration ).  

 

I will try to elaborate these tonight if I get chance. 

 

Kind Regards, 

Bhaumik
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

In answer to your questions: 

The USB standard does not require that all control operations be implemented. For example, a chip that has only one configuration probably won't implement get configuration because the answer would always be the same. 

 

The usage of each endpoint should be documented in the datasheet or users guide for the device. Some are documented in USB standards, i.e. endpoint 0 is for control.
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

I did not find endpoint description in the datasheet provided by ftdi but now know how to do this. 

 

For someone who whould like to understand usb 2 easily, i give this url : URL="http://www.usbmadesimple.co.uk/ums_4.htm"]http://www.usbmadesimple.co.uk/ums_4.htm[/URL] 

 

especially part 4, very well explained. 

 

Thanks guyz, you helped me quite a lot.
0 Kudos
Altera_Forum
Honored Contributor II
471 Views

Hi people, 

 

i suspended my studies on usb for some weeks but i'm back again, and unsurprisingly i got issues cause i'm not a good boy, hoping you will answer me : 

 

- My system waits 2 bytes of command from isp so i prepare an OUT ptd like this 

{x800; x2040; x402; x2; x240} the last word is the payload (command) 

As a response (ACK?), i get {x402;x2040;x402; x2; x240} (is this an acknowledge?i guess yes) Actual bytes transferred is @2, so it's nice 

 

- I want it to send me back awaited data so i prepare an IN ptd like this  

{x800; x1040; x804 ; x2} this time no payload but i need to tell him how many bytes i want to receive here 4 (i don't know if it's the right way) 

As a response, i get {x9402; x1040; x804; x2; x6031; F7EB} 

oh my god, what is that? code 9 is for underrun, 2 bytes received in the payload but 4 actually ? This is not what i want. 

 

-Ok let's toggle it and send back the IN ptd again. Oh no same things. 

 

-3rd time, toggle it again? Would you work please? 

Geez, i get {x8000; x1040; x804; x2; x6031; x3412}. x1234ABCD is the payload i wanted, but why this x6031 is still there? I looked after it on usb spec, is that a PID response? 

3 = DATA0 

1 = OUT 

6 = Not Acknowledge Yet 

0 = reserved 

 

I don't know.... 

 

Tell me if i missed something important here. :-/
0 Kudos
Reply