FX3 Fast GPIO Sampling

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

cross mob
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hello,

For my project, I'm currently using the FX3 (CYUSB3014) and looked into the SPI GPIO bit banging example as reference for the bit banging approach and given my timing requirements, it seems that we would need a delay less than a microsecond in between bits. From the looks of it, the smallest delay that can be used is with the CyU3PBusyWait (1uS). Is it possible to sample the logic levels of the GPIO pin/s with smaller delays and perform bit banging at a faster rate?

Thanks

 

 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi JL46,

1. What I have understood from your question is the 4 unused data bits of GPIF has to be initialized as HIGH and kept HIGH throughout the transfer. If its correct, GPIO4-7 can be pulled up using a resistor externally.
Also other GPIOs apart from DQ0-DQ7 can be used and initialized in the firmware.

2. There are two methods for reading the sampled data through control center,

a. You could declare a global flag, and change its value only when a particular vendor command is received by the firmware. Then you can check for this flag in the GpifToUsbDmaCallback and depending on the value of the flag, you could either discard or commit the buffer accordingly.
b. In the GPIF state machines, in the transition equations, there is FW_TRG. You could use (!DRDY&FW_TRG) in the GPIF transition equation (STATE0 -> STATE1) and in the firmware, call the  CyU3PGpifControlSWInput() API when a particular vendor command is received. For more information on this API, refer to Pg No. 263 of the FX3APIGuide.

3. When you double-click on a state, you can set how many times the state has to be repeated. So for the GpifToUsb project which I have shared with you, I have specified this value to be 32 for STATE1. I have attached a snapshot for your reference. So yes, 32 bits will be read from a GPIO synchronously with clk and drdy. 

Best Regards,
AliAsgar

View solution in original post

0 Likes
24 Replies
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

Through FX3 APIs minimum delay that can be provided is 1us (using CyU3PBusyWait as you mentioned). In spigpiomode example of fx3 sdk the clock stays high for around 1us, then sampling happens following clock going low for 1us. So using that example delay between two successive sampling will be around 2us.

We do not have an example firmware with <1us delay between bits sampled.

Regards,

Hemanth
0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi Hemanth,

I saw a related forum here as well: https://community.cypress.com/t5/USB-Superspeed-Peripherals/FX3-GPIO-Clocks/td-p/191417#:~:text=Simp....

It mentioned there that "Simple GPIO use FX3 GPIO clock to sample the pins and hence can operate at maximum 100.08MHz". Based on this forum, I assume that the GPIO status can be sampled at a max rate of 100.08MHz or even 50.04MHz (min. divisor of 2). I was wondering how this would be implemented.

Also, would it be possible to use for loops / other loops to serve as delays aside from the API's? 

Thanks

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi Hemanth,

I tried and the for loops idea for a delay don't seem to be the way to go. Even without delays from API, it doesn't seem to soove the problem either way.

I'm still looking at the forum link I saw regarding GPIOs and also asked here but can't seem to see how it would translate to the code itself since you said that the smallest delay is 1uS (1MHz).

The process I intend to to do is something like this:

1) read gpio pins status 

2) nanosecond delay (~tens to hundreds of nS)

3) read gpio pins status

4) nanosecond delay

5) repeat as needed.

Maybe a delay as a function of the FX3 clocks can be used for this? I'm not really sure but I'm trying to exhaust all possibilities to come to a definite conclusion.

Thank you for any assistance you can provide.

 

 

 

 

 

 

 

 

 

 

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

Hello,

1. Is the SPI used as a master or slave in the application?

2. Complex GPIOs can be used as timers to produce small delay. This KBA1 and KBA2 can be referred to configure the  complex gpios as timers, but the consistency of delay may not be achieved.

Best Regards,

AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

Apologies for the delay in response. The SPI pins (53:56) are connected to different part. What I'm using are GPIO pins configured in simple mode. 

I'm trying to read digital data from a connected device with timing diagram based below:

jl46_0-1617593945440.png

My goal is to have the DOUTx data bits be reconstructed on the FX3 end, in sync with the DCLK signal. Due to my assumption of previous limitations, I've been using DCLK levels 1MHz or below. The DOUT pins are connected to GPIOs 48,49,50,51, DRDY on GPIO21 and DCLK on GPIO22.

 

Here's the snippet of code I made to read from GPIO48 based on the timing diagram above and the bit banging example from FX3 SDK:

jl46_1-1617594477598.png

Right now, I'm trying to do this for only one channel (from GPIO48) but I'm also looking at the possibility of doing this for all 4 channels (GPIO48 to 51).

I also still want to clarify regarding the forum that I've mentioned in one of my previous comments regarding GPIO's being able to operate at max of 100MHz. Does this mean that GPIO status can be sampled at also around that rate or maybe even 50MHz (assuming divisor of 2)? 

 

Thanks

 

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

Hello,

From your reply above, we can understand that 4 bits sampling is required. To sample bits parallelly, GPIF interface is recommended. Sampling of parallel bits in GPIO's cannot be synchronized. Maximum frequency supported by GPIF II block is 100MHz, so sampling at this frequency is possible.

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

So the 100MHz mentioned in the forum is only for GPIF and outside of GPIF I wouldn't be able to do it?

Right now I'm using the gpio register access (not API) to simultaneously get the GPIO status of multiple pins but even with single channel sampling there seems to be problem. Is there a problem with my code snippet (check drdy to go low -> wait until clk goes low -> get gpio48 level and parse -> repeat) ?

 

Regards,

Jl46

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

Hi Jl46,

As we have understood, your application requires sampling of 4 bit data. Even if GPIO register access is used, 4 GPIO's cannot be synchronized.
So we would recommend you to use GPIF II block for sampling the 4 bits parallelly. We'll be happy to help if you have any queries on this.

Note: GPIF requires minimum of 8 bits for data, so the remaining unused 4 bits can be either pulled up or pulled down and those 4 bits can be discarded in the processing stage.

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

I'm also interested at finding a solution even for just one channel. I've been trying the code snippet I commented previously to read from just one channel but I'm also having some problem there it seems. I'm not sure if I'm properly detecting the negative edge from DCLK or if the varying logic from GPIO48 (dout) is reflected properly when I read the gpio registers.

Speaking of GPIF, I initially tried creating a new project and from what I see initially, I'm not able to set the corresponding GPIOs (48-51) as my data input line and I'm not sure exactly how to start using the GPIF designer to create a firmware that'll allow me to read data properly.

I appreciate the responses from my inquiry.

 

Thanks! 

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

Hi jl46,

Could you let us know exactly what problems are you facing using single channel?

In the code snippet which you had shared, 
In this line,
d0 = d0 | (*doutPtr >> 16) << (32-count),
(32-count) has to be replaced by (31-count).

Could you change the dout pins from 48:51 to some other pins that can be used with GPIF?

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

I'm expecting a constant value to beread from the GPIO48 (I checked from an oscilloscope and the bit stream is fairly constant). Instead of getting a constant code, I'm getting random values. I think it's likely that my code implementation is wrong. I'm reading 32 bits from GPIO48 in sync with a clock (timing diagram on previous comment) and transferring the result via usb using a modified bulkloopmanual firmware. I bit shift and mask every 8 bits in the 32 bit data and send it through USB (data[j] = d0 >> (8*j) & 0xFF where j = 0 to 4)

I'm using an FX3 eval board so yeah i think I can try using the allowed pins. What pins would i use for drdy, dclk, and dout pind for gpif? Are there any example firmware or manual regarding gpif interface I could look at?

 

Thanks,

Jl46

 

 

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

Hi jl46,

Could you share the modified bulkloopmanual firmware being used?

For dclk, pclk(GPIO16) could be used, For 8 bit data(because minimum data bus width for  GPIF is 8,  4 bit dout + 4 unused bits) , 8 pins can be selected from GPIO(0:7). Any control pin can be used to configure drdy signal.

Kindly refer to FX3_TRM, FX3_ProgrammersManual, and the gpif2_designer_userguide docs from the doc folder inside the downloaded SDK folder.

Best Regards,
AliAsgar

0 Likes
lock attach
Attachments are accessible only for community members.
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

Attached here is the modified BulkLoopManual firmware. I modified the DMA callback function to have a provision for reading DOUT (GPIO48) when certain command is received from Control Center.

I also added a clock configuration in the main() to set SysClk = 400MHz, allowing maximum 100MHz operation for Simple GPIOs (https://community.cypress.com/t5/USB-Superspeed-Peripherals/FX3-GPIO-Clocks/m-p/191420#M18985). I assumed that doing this will allow me to sample the GPIO registers status at the said rate so I tried adding it anyways.

I will check the documentations you mentioned in the SDK folder thank you. Is there a way for me to verify if the created firmware with GPIF? i.e., upload via control center and send commands and read data etc.

 

Thank you for the assistance,

jl46

0 Likes
lock attach
Attachments are accessible only for community members.
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi jl56

We tested your firmware at our end, and the output seemed to be as expected. I have attached a picture for your reference.

Could you check if dclk, drdy and dout inputs to gpio are stable.

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

I think I've also tried that and it was indeed working. My problem probably is that i keep getting FF FF FF all the time. Even with a clock source in DRDY, DCLK, and DOUT0 (supply digital signal to input pin instead), the response is always FF FF FF. 

 

Also can you help me understand clearly the forum link I posted on my previous comment? It sayst here that simple GPIo can operate at max of 100MHz. If it means that it can sample the GPIO pin at that rate, howw ould I be able to utilize that? Or is there I'm misunderstanding? Please help me clarify this assumption of mine as well.

Thanks,

jl46

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

Hi jl46,

We connected GPIO48 to GND, and we got 00 00 00 00 as output(as expected). Could you let us know specifically what input was given at your side, and what was received?

Simple GPIOs can operate at 100MHz and they can be sampled at that rate, but the frequency of sampling is constraint of the code written to read the GPIO's. This is why it was recommended to use GPIF as, GPIF samples data and stores it in the dma buffer.

Also the Simple GPIO clock is internal, but dclk (external clock) is being used in your application. Could you share with us the frequency of dclk being used.

Instead of using "while(*gpPtr & 0x400000)" to wait for the negative edge of the clock, an interrupt can be used for the negative edge of the clock, this is faster that the polling method.

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

I'm just using square waves from a signal generator as of this moment. I just try to look at the square wave profiles and try to estimate what I'd be expecting to be read.

I see. If the data is sampled through GPIF and is stored in a dma buffer, would the data be accessible and can be sent over USB similsr to the firmware I sent you? From what I remember in the firmware, the identification of usb command starts with looking at the buffer received and if I'm not mistaken, the firmware example for bulkloopmanual (basis of modified firmware) stores received and sent data in the dma buffer so I initially thought there might be problems.

I'm trying to use DCLK of at least 1.5MHz.

I think i previously tried interrupt based gpios but depending on the speed I think there were times when when I try to send command from control center and don't receive a response (error code 997) and i think it has to do with the speed at which the gpio pin is interrupt so it seemed to be limiting at the time. Also I'm not well versed in using interrupts so I'm not familiar with how to build firmware around or involving interrupts.

 

Regards,

Jl46

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

Hi jl46,

Are you using the FX3 explorer kit or a custom board? If using the custom board, could you please share the portion of schematics having the GPIO used??

Could you send a logic 1 and a logic 0 on the GPIO48 and share with us the results? Also are you facing similar problem with other GPIO pins?

The USB command does not interfere with the dma buffer used in the GPIF, as they are two different dma channels with different dma buffers.

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

I have decided to try out the GPIF approach for my problem. It kind of makes sense to do so since I wouldn't be able to fully utilize the GPIO sampling with my implementation since the code speed limits it.

 

I have tried reading and understanding the GPIF manuals to try and make my own GPIF based peripheral with USB transmission functionality but I'm really having a hard time implementing what I need. Can you give me a head start by maybe modifying my original firmware with GPIF capability? I apologize for the delay in reply as I was busy learning the GPIF interface and IDE (GPIF designer) but I wasn't able to grasp it.

 

thanks,

jl46

0 Likes
lock attach
Attachments are accessible only for community members.
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi jl46,

Please find attached firmware project and GPIF project as per your application requirement.

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi AliAsgar,

Thank you for the firmware I will review this. This is based on the timing diagram operation I commented am I correct? So using this firmware will allow me to do what I originally intend to do (measure digital stream from GPIO pin based on DRDY and DCLK signal) and get the data vis USB (control center) right? 

 

Thanks,

JL46

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

Hi JL46,

Yes the gpif state machine is designed based on the timing diagram operation you commented.

Also, please do make a correction in the firmware project I had sent,
Inside CyFxApplnStart() function,
dmacfg.size = 32.

Best Regards,
AliAsgar

0 Likes
jl46
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hello AliAsgar,

Apologies for the delay in response. I tried replying to the forum but I wasn't able to, which is why I'm sending this personal message.

 

I've only looked at the firmware etc. that you sent regarding the GPIF to USB example. I have a few questions before trying it with:

1) Is it possible to use and initialize other GPIO pins using this firmware? for example can I set GPIO4-7 (since GPIO0 to GPIO3 would be for data reading) to HIGH before running the GPFI reading? Will I be able to initialize and use other GPIOs using this firmware?

2) How do I read data using this firmware using control center? In my target operation, I'm going to send command via control center and as a response, I should get a sampled data.

3) With this GPIF based firmware, am I guaranteed that every 32 bits for each GPIO input will be read? I looked at the state machine in GPIF and I saw IN_DATA there. Does the IN_DATA mean sample 32 bits from the channels, synchronous with the clock and drdy? 

 

I'll try playing around and understanding the firmware you sent me while waiting for your response. Thank you for the help.

 

Regards,

JL46

0 Likes
lock attach
Attachments are accessible only for community members.
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi JL46,

1. What I have understood from your question is the 4 unused data bits of GPIF has to be initialized as HIGH and kept HIGH throughout the transfer. If its correct, GPIO4-7 can be pulled up using a resistor externally.
Also other GPIOs apart from DQ0-DQ7 can be used and initialized in the firmware.

2. There are two methods for reading the sampled data through control center,

a. You could declare a global flag, and change its value only when a particular vendor command is received by the firmware. Then you can check for this flag in the GpifToUsbDmaCallback and depending on the value of the flag, you could either discard or commit the buffer accordingly.
b. In the GPIF state machines, in the transition equations, there is FW_TRG. You could use (!DRDY&FW_TRG) in the GPIF transition equation (STATE0 -> STATE1) and in the firmware, call the  CyU3PGpifControlSWInput() API when a particular vendor command is received. For more information on this API, refer to Pg No. 263 of the FX3APIGuide.

3. When you double-click on a state, you can set how many times the state has to be repeated. So for the GpifToUsb project which I have shared with you, I have specified this value to be 32 for STATE1. I have attached a snapshot for your reference. So yes, 32 bits will be read from a GPIO synchronously with clk and drdy. 

Best Regards,
AliAsgar

0 Likes