GPIF GPIO

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

cross mob
lock attach
Attachments are accessible only for community members.
lfl_4816136
Level 2
Level 2

JayakrishnaT_76

Hello, I want to add another PWM based on the project you provided last time to transmit data through gpif, but the project does not respond after I added it. Can you give me some suggestions?

Here are the functions I need to implement:

1. After power on, first configure 78365 through gpio to simulate spi

2. Generate a PWM to drive external mems

3. Send data to 78365 cyclically through gpif

The following code from line 745 is the part I added

I look forward to your answer

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hello,

Please refer to the attached firmware.

I have modified the firmware according to your requirement. For the PWM generation, I have used complex GPIO 45. The frequency and duty cycle are set randomly (according to ComplesGpioApp example firmware of SDK). Please modify the parameters according to your requirement.

You can refer to this KBA for Calculating PWM Period and Duty Cycle in FX3 – KBA226759 calculating the PWM Period.

Please let me know if any queries on this.

Regards,

Rashi

Regards,
Rashi

View solution in original post

0 Likes
17 Replies
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

It seems that you are trying to bit-bang the GPIOs for communicating to  78365 through SPI.

If yes, please refer to UsbSpiGpioMode example firmware of the SDK (Path: FX3 SDK Installation Path\Cypress\EZ-USB FX3 SDK\1.3\firmware\serialif_examples\cyfxusbspigpiomode) uses GPIOs (53,54,55,56) for SPI communication. You can use GPIO 33,34,35 as used in your firmware.

Please let me know if any query on this

Regards,

Rashi

Regards,
Rashi
0 Likes

hello,

As you said, I need to use GPIO33, 34, 35 to simulate spi, and I have also written the related logic, but what I want to ask is, how should I configure the relevant parameters? I have seen the example of SRAMMater. In the example, first CyU3PGpifLoad (&CyFxGpifConfig) and then "Initialize the GPIO module" can I also design this way,

And how do I create the thread, do I need to create two threads?

0 Likes

Hello,

If the 78365  needs to be configured/initialized first i.e. before the FX3 starts to send the data, then the "Initialize GPIO module" needs to be called first and then the GPIF state machine can be loaded/started.

I assume that you are using the firmware shared in this thread Gpif master​If yes, the data transfer will start as soon as the device is connected (glIsApplnActive) so some flow control is needed as 78365 needs to be initialized first. So a flag (spi_configuration_done) can be used along with the other flags i.e. if(glIsApplnActive && tcplt && spi_configuration_done)

spi_configuration_done flag should be CyFalse initially and once the configuration through SPI is completed this flag can be set to CyTrue.

Later when in the CyFxAppThread_Entry function the flags will be checked and then the data transfer will be done

Please let me know if any queries on this

Regards,

Rashi

Regards,
Rashi
0 Likes

Hello there,

My design is like this, Initialize 78365 (GPIO 33, 34, 35) -> start GPIF to transmit data -> drive PWM (GPIO 45), I now know how to configure GPIO, but how do I Create the thread,the following is the generation Screenshot of PWM logic

pastedImage_2.png

In this code, I used "for(;;)" to generate a PWM, but "for(;;)" is also used in CyFxAppThread_Entry, so I am confused how to deal with this place, because of PWM and gpif It is outputting at the same time. Do you need to create two threads? If so, how to set it?

0 Likes

pastedImage_0.png

0 Likes

Hello,

Okay, I understand.

Can you share the firmware with us so that I can suggest you the solution?

Regards,

Rashi

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

hello

  Below is my firmware. Starting from line 745, I added Initialize 78365 and the code for generating PWM. I will add my firmware in the attachment below.

0 Likes
lock attach
Attachments are accessible only for community members.

Hello,

Please refer to the attached firmware.

I have modified the firmware according to your requirement. For the PWM generation, I have used complex GPIO 45. The frequency and duty cycle are set randomly (according to ComplesGpioApp example firmware of SDK). Please modify the parameters according to your requirement.

You can refer to this KBA for Calculating PWM Period and Duty Cycle in FX3 – KBA226759 calculating the PWM Period.

Please let me know if any queries on this.

Regards,

Rashi

Regards,
Rashi
0 Likes

Hello,

according to the example you provided to me, I want to know the clock frequency of the gpio that generates the PWM. In addition, I need the PWM period to increase or decrease by 1HZ every 500us, until the PWM reaches a certain threshold after the PWM period No more changes, so how should I design, can I directly set (gpioConfig.period = CY_FX_PWM_PERIOD) CY_FX_PWM_PERIOD as a variable?

0 Likes

Hello,

Yes, gpioConfig.period field of the GPIO configuration can be set as per your requirement.

§  SYS_CLK frequency = 403.2 MHz

§  GPIO fast clock frequency = (SYS_CLK frequency)/2 = 201.6 MHz

§  One clock period = 1/(GPIO fast clock frequency) = (1/201.6) µs

§  gpioConfig.period = (Desired PWM waveform period/One clock period)

Please refer to this KBA Calculating PWM Period and Duty Cycle in FX3 – KBA226759 for the same.

Regards,

Rashi

Regards,
Rashi
0 Likes

hello,

I have another question. Where should I write the logic of the PWM setup period? Is the logic added to CyFxApplnUSBSetupCB()? If not, can you tell me?

0 Likes

Hello,

I didn't get your question. Please explain so that I can help you better.

USBSetupCB is used for handling the USB setup specific requests.

Regards,

Rashi

Regards,
Rashi
0 Likes

Hello there,

That's it. I want to add the logic in the screenshot below to control gpioConfig.period and gpioConfig.threshold, but I don't know how to add this logic to my application. Can you tell me?

pastedImage_0.png

0 Likes

Hello,

It seems that you want to change the duty cycle of the PWM

The instance to call this function would depend on how many times you need to update the PWM duty cycle. If you want to call it continuously i.e. after every unit time interval then you can create a new thread and inside the infinite, for loop, the function can be called. You can put delay using CyU3PThreadSleep function based on the requirement

This is the code snippet from GpioComplexApp example of the FX3 SDK

(Path: ..\Cypress\EZ-USB FX3 SDK\1.3\firmware\serialif_examples)

for (;;)

    {

        /* Wait for 1s. */

        CyU3PThreadSleep (1000);

        /* Change the PWM duty cycle to 75%. */

        apiRetStatus = CyU3PGpioComplexUpdate (50,

                CY_FX_PWM_75P_THRESHOLD, CY_FX_PWM_PERIOD);

        if (apiRetStatus != CY_U3P_SUCCESS)

        {

            CyU3PDebugPrint (4, "CyU3PGpioComplexUpdate failed, error code = %d\n",

                    apiRetStatus);

            CyFxAppErrorHandler(apiRetStatus);

        }

        /* Wait for 1s. */

        CyU3PThreadSleep (1000);

        /* Change the PWM duty cycle to 25%. */

        apiRetStatus = CyU3PGpioComplexUpdate (50,

                CY_FX_PWM_25P_THRESHOLD, CY_FX_PWM_PERIOD);

        if (apiRetStatus != CY_U3P_SUCCESS)

        {

            CyU3PDebugPrint (4, "CyU3PGpioComplexUpdate failed, error code = %d\n",

                    apiRetStatus);

            CyFxAppErrorHandler(apiRetStatus);

        }

    }

Regards,

Rashi

Regards,
Rashi
0 Likes

Hello,

I understand what you mean. I have seen the example in "GpioComplexApp" before, and I already know how to modify the PWM frequency, but what I want to ask is how (or which module) should I add my logic, because The function I want to achieve is Initialize78365->data to78365->drive PWM (the frequency is variable), but in the "CyFxAppThread_Entry" part has used the "for (;;)" statement, so I want to know how to change the logic of PWM Add it to the project to achieve the function I expected.

There is another problem, "CyU3PThreadSleep" can only delay 1ms at least, and I need a smaller delay (us),

So can you help me solve my problem I look forward to your answer

0 Likes

Hello, according to your answer: pastedImage_0.png

But when I set "gpioConfig.period = 200; gpioConfig.threshold = 100;" the PWM period I measured with the oscilloscope is about 4us, can you tell me why

0 Likes
lock attach
Attachments are accessible only for community members.

Hello,

Please change the GPIO clock configuration as shown below

gpio_clk.PNG

with this, you will get a 1 us period when gpioConfig.Period = 200. Initially in the firmware, the fastClkDiv was 8 i.e. 403.2/8 = 50 MHz

So, that was the reason for the 4us period.

I have modified the firmware to add a global variable (pwm_started) which will be enabled when PWM has started only when the PWM starts in for loop for{} the logic to change the frequency can be added. You can do modifications as per your application i.e.e when the data transfer is done.

Regards,

Rashi

Regards,
Rashi
0 Likes