cancel
Showing results for 
Search instead for 
Did you mean: 

USB Superspeed Peripherals

New Contributor II

I want to configure some GPIO as pwm signals, but a don't know how to do it. For this reason, i have the following questions:

-first of all, I have seen that  GPIOs have two different configurations: simple and complex. But, all GPIOs are able to work with both configurations?

-Secondly how are the functions to configure a GPIO as pwm output signal?. In order to set the duty cycle or frequency.

Thanks for the support.

0 Likes
Reply
1 Solution
Moderator
Moderator

Hello,

Please make the following modifications to the code:

1. In the IO_Matrix part:

    io_cfg.isDQ32Bit = CyFalse;

    io_cfg.useUart   = CyTrue;

    io_cfg.useI2C    = CyTrue;

    io_cfg.useI2S    = CyFalse;

    io_cfg.useSpi    = CyTrue;

    io_cfg.lppMode   = CY_U3P_IO_MATRIX_LPP_DEFAULT;

    /* GPIOs 50,51 and 52 enabled. */

    io_cfg.gpioSimpleEn[0]  = 0;

    io_cfg.gpioSimpleEn[1]  = 0;

    io_cfg.gpioComplexEn[0] = 0;

    io_cfg.gpioComplexEn[1] = 0x001C0000;

    status = CyU3PDeviceConfigureIOMatrix (&io_cfg);

    if (status != CY_U3P_SUCCESS)

    {

        goto handle_fatal_error;

    }

2. You need not call CyU3PGpioInit() as it is called internally by the API CyU3PMipicsiInitializeGPIO().

3. You need not override GPIO50 as it is already configured as a complex in the IO_Matrix.

4. For configuring complex GPIO 50 as PWM, use the following lines of code after the API CyU3PMipicsiInitializeGPIO() is called:

    /* Configure GPIO 50 as PWM output */

        gpioConfig.outValue = CyFalse;

        gpioConfig.inputEn = CyFalse;

        gpioConfig.driveLowEn = CyTrue;

        gpioConfig.driveHighEn = CyTrue;

        gpioConfig.pinMode = CY_U3P_GPIO_MODE_PWM;

        gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR;

        gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;

        gpioConfig.timer = 0;

        gpioConfig.period = CY_FX_PWM_PERIOD;

        gpioConfig.threshold = CY_FX_PWM_25P_THRESHOLD;

        status = CyU3PGpioSetComplexConfig(50, &gpioConfig);

        if (status != CY_U3P_SUCCESS)

        {

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

            status);

        }

where CY_FX_PWM_PERIOD = (201600 - 1)

and     CY_FX_PWM_25P_THRESHOLD = (50400  - 1)

You can use your own period and threshold.

Please let me know if you still face any error after making the modifications mentioned above.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

0 Likes
Reply
7 Replies
Moderator
Moderator

Hello,

Please refer to the following thread which already answered a similar query:

Re: CX3 GPIO control and power on status

Note that CX3 supports only 12 GPIOs and they can be identified from the datasheet. Please let me know if you have any queries on this.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
Reply
New Contributor II

Are all of these 12 GPIOs able to work as a complex?, I am traying to configure the GPIO[50] as complex as follows:

-Firstly, I have declared the CyU3PGpioClock_t structure :

                    CyU3PGpioClock_t gpioClock;

                    gpioClock.fastClkDiv = 2;

                    gpioClock.slowClkDiv = 0;

                    gpioClock.simpleDiv  = CY_U3P_GPIO_SIMPLE_DIV_BY_2;

                    gpioClock.clkSrc     = CY_U3P_SYS_CLK;

                    gpioClock.halfDiv    = 0;

                    CyU3PGpioInit(&gpioClock, NULL);

-After that I have completed the configuration:

                    gpioConfig_Complex.outValue    = CyFalse;

                    gpioConfig_Complex.inputEn     = CyFalse;

                    gpioConfig_Complex.driveLowEn  = CyTrue;

                    gpioConfig_Complex.driveHighEn = CyTrue;

                    gpioConfig_Complex.pinMode     = CY_U3P_GPIO_MODE_PWM;

                    gpioConfig_Complex.intrMode    = CY_U3P_GPIO_NO_INTR;

                    gpioConfig_Complex.timerMode   = CY_U3P_GPIO_TIMER_HIGH_FREQ;

                    gpioConfig_Complex.timer       = 0;

                    gpioConfig_Complex.period      = (201600  - 1);

                    gpioConfig_Complex.threshold   = (50400  - 1);

                    status = CyU3PGpioSetComplexConfig(19, &gpioConfig_Complex);

                    if(status != 0) CyU3PDebugPrint(4,"Error \n");

It seems correctly, because it is possible to complile and load the firmware into IC. However I can not see the pwm signal in the oscilloscope.

So, it is correct?

Thanks.

0 Likes
Reply
Moderator
Moderator

Hello,

CX3 supports 12 GPIOs as per the datasheet. These are GPIO 17-26, GPIO 44 and GPIO 45. In addition to this, there are GPIOs that are multiplexed and can be used also as UART/I2S/SPI. According to section 4.1 of FX3 TRM, there are eight complex I/O pin groups, the elements of which are chosen in a modulo 8 fashion. This means that if you are configuring GPIO 17 as a complex GPIO then the next GPIO that can be configured as complex will be GPIO 25. While doing so you need to make sure that GPIO 25 is available and can be used as a GPIO (not dedicated for other interfaces).

From your description in the previous reply, I find that you are trying to configure GPIO[50] to produce PWM. But in the code snippet shared, I see that you are configuring GPIO 19. Please confirm which GPIO you want to use to generate PWM output. Please let us know if the code at any stage enters the handle_fatal_error. Please share the IO_Matrix configuration structure so that we can have a look at it.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
Reply
New Contributor II

Sorry, it was an error in the last code, it is really the GPIO[50] which is selected as a complex.

                    gpioConfig_Complex.outValue    = CyFalse;

                    gpioConfig_Complex.inputEn     = CyFalse;

                    gpioConfig_Complex.driveLowEn  = CyTrue;

                    gpioConfig_Complex.driveHighEn = CyTrue;

                    gpioConfig_Complex.pinMode       =   CY_U3P_GPIO_MODE_PWM;

                    gpioConfig_Complex.intrMode      = CY_U3P_GPIO_NO_INTR;

                    gpioConfig_Complex.timerMode   = CY_U3P_GPIO_TIMER_HIGH_FREQ;

                    gpioConfig_Complex.timer            = 0;

                    gpioConfig_Complex.period          = (201600 - 1);

                    gpioConfig_Complex.threshold     = (50400  - 1);

                    status = CyU3PGpioSetComplexConfig(50, &gpioConfig_Complex);

I have not any IO_Matrix configuration because i try to configure a single complex gpio, for this reason i have configured it using the CyU3PGpioComplexConfig_t structure.

Is it correct or i have to configure the IO_Matrix?. In this case, how could i do it?

0 Likes
Reply
Moderator
Moderator

Hello,

Please let us know if the code at any stage enters the handle_fatal_error. This can be verified by using the API CyU3PDeviceReset(CyFalse); inside this section of code. If code execution entered this section, then the device will enumerate as Bootloader Device in control center.

Also, for this case, the I2S block should be disabled and you can override the IO 50 by using the API CyU3PDeviceGpioOverride() before configuring it. Please share the IO_Matrix configuration structure so that we can have a look at it.

Please let me know if you have used the API CyU3PDeviceGpioOverride() for overriding IO 50 to use it as a GPIO. Please refer to the API guide to understand more about this API. It comes along with FX3 SDK and can be found in the following location:

C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\doc\firmware

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
Reply
New Contributor II

Yes of course,

I have three errors:

-CyU3PGpioInit failed with error code 67.

- CyU3PGpioInit failed with error code 64.

- CyU3PGpioSetComplexConfig failed with error code 68.

And you can see the part of the code:

********************************************************************************************************************************************************

/*****Init GPIO module****/ 

     CyU3PGpioClock_t gpioClock;

     gpioClock.fastClkDiv = 2;

     gpioClock.slowClkDiv = 0;

     gpioClock.simpleDiv  = CY_U3P_GPIO_SIMPLE_DIV_BY_2;

     gpioClock.clkSrc     = CY_U3P_SYS_CLK;

     gpioClock.halfDiv    = 0;

     status = CyU3PGpioInit(&gpioClock, NULL);

     if(status != 0)CyU3PDebugPrint (4, "CyU3PGpioInit failed, Init Clock error code = %d\n\r", status);

/***** Configuring GPIO[50] ******/

                    status = CyU3PDeviceGpioOverride (50, CyTrue);

                    if(status != 0)CyU3PDebugPrint (4, " CyU3PDeviceGpioOverride failed, Override gpio 50 error code = %d\n\r", status);

                    CyU3PMemSet ((uint8_t *)&io_cfg, 0, sizeof(io_cfg));

                        io_cfg.isDQ32Bit = CyFalse;

                        io_cfg.s0Mode = CY_U3P_SPORT_INACTIVE;

                        io_cfg.s1Mode = CY_U3P_SPORT_INACTIVE;

                        io_cfg.useUart   = CyTrue;

                        io_cfg.useI2C    = CyTrue;

                        io_cfg.useI2S    = CyFalse;

                        io_cfg.useSpi    = CyTrue;

                        io_cfg.lppMode   = CY_U3P_IO_MATRIX_LPP_SPI_ONLY;

                        io_cfg.gpioSimpleEn[0]  = 0;

                        io_cfg.gpioSimpleEn[1]  = 0;

                        /* GPIOs 50, 51 and 52 are used as complex GPIO. */

                        io_cfg.gpioComplexEn[0] = 0;

                        io_cfg.gpioComplexEn[1] = 0x001C0000;

                        status = CyU3PDeviceConfigureIOMatrix (&io_cfg);

                        if(status != 0)CyU3PDebugPrint (4, "CyU3PDeviceConfigureIOMatrix failed,configuring IOMatrix error code = %d\n\r", status);

                    gpioConfig_Complex.outValue    = CyFalse;

                    gpioConfig_Complex.inputEn     = CyFalse;

                    gpioConfig_Complex.driveLowEn  = CyTrue;

                    gpioConfig_Complex.driveHighEn = CyTrue;

                    gpioConfig_Complex.pinMode     = CY_U3P_GPIO_MODE_PWM;

                    gpioConfig_Complex.intrMode    = CY_U3P_GPIO_NO_INTR;

                    gpioConfig_Complex.timerMode   = CY_U3P_GPIO_TIMER_HIGH_FREQ;

                    gpioConfig_Complex.timer       = 0;

                    gpioConfig_Complex.period      = (201600 - 1);

                    gpioConfig_Complex.threshold   = (50400  - 1);

                    status = CyU3PGpioSetComplexConfig(50, &gpioConfig_Complex);

                    if(status != 0)CyU3PDebugPrint (4, "CyU3PGpioSetComplexConfig failed,configuring gpio50 error code = %d\n", status);

********************************************************************************************************************************************************

As you can see i just try to disable the I2S to use the GPIO [50] as a PWM signal.

0 Likes
Reply
Moderator
Moderator

Hello,

Please make the following modifications to the code:

1. In the IO_Matrix part:

    io_cfg.isDQ32Bit = CyFalse;

    io_cfg.useUart   = CyTrue;

    io_cfg.useI2C    = CyTrue;

    io_cfg.useI2S    = CyFalse;

    io_cfg.useSpi    = CyTrue;

    io_cfg.lppMode   = CY_U3P_IO_MATRIX_LPP_DEFAULT;

    /* GPIOs 50,51 and 52 enabled. */

    io_cfg.gpioSimpleEn[0]  = 0;

    io_cfg.gpioSimpleEn[1]  = 0;

    io_cfg.gpioComplexEn[0] = 0;

    io_cfg.gpioComplexEn[1] = 0x001C0000;

    status = CyU3PDeviceConfigureIOMatrix (&io_cfg);

    if (status != CY_U3P_SUCCESS)

    {

        goto handle_fatal_error;

    }

2. You need not call CyU3PGpioInit() as it is called internally by the API CyU3PMipicsiInitializeGPIO().

3. You need not override GPIO50 as it is already configured as a complex in the IO_Matrix.

4. For configuring complex GPIO 50 as PWM, use the following lines of code after the API CyU3PMipicsiInitializeGPIO() is called:

    /* Configure GPIO 50 as PWM output */

        gpioConfig.outValue = CyFalse;

        gpioConfig.inputEn = CyFalse;

        gpioConfig.driveLowEn = CyTrue;

        gpioConfig.driveHighEn = CyTrue;

        gpioConfig.pinMode = CY_U3P_GPIO_MODE_PWM;

        gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR;

        gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;

        gpioConfig.timer = 0;

        gpioConfig.period = CY_FX_PWM_PERIOD;

        gpioConfig.threshold = CY_FX_PWM_25P_THRESHOLD;

        status = CyU3PGpioSetComplexConfig(50, &gpioConfig);

        if (status != CY_U3P_SUCCESS)

        {

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

            status);

        }

where CY_FX_PWM_PERIOD = (201600 - 1)

and     CY_FX_PWM_25P_THRESHOLD = (50400  - 1)

You can use your own period and threshold.

Please let me know if you still face any error after making the modifications mentioned above.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

0 Likes
Reply