Page 1 of 1

How to connect GPIO output with peripheral input - single pin

Posted: Fri Feb 23, 2018 1:57 pm
by embedded-creations
I have a GPIO output driving an external chip that I would like to connect to a MCPWM timer sync input, without using an extra pin. I haven't been able to get this to work, but ESP_Sprite's comment from this thread gives me hope:
ESP_Sprite wrote:
a2retro wrote:Are all pin uses mutually exclusive or may some be overlapped during use somehow?
Outputs are mutually exclusive, for obvious reasons. Inputs can be shared in the GPIO matrix, that is, you connect one GPIO pin to multiple peripheral inputs. You can also connect a pin to the output of one peripheral and to the input of another. I don't think the IO-mux allows sharing of pins, so if you need to share something with a peripheral that's only on the IO-mux you may be out of luck.
I stripped down mcpwm_basic_config_example to just what I needed for a test case. GPIO12 is being driven with a test signal, and if I externally connect GPIO_SYNC0_IN (GPIO2) to GPIO12, my timer0 signal syncs up to the test signal.
2018-02-23 at 1.46 PM.png
2018-02-23 at 1.46 PM.png (20.93 KiB) Viewed 6165 times
If instead I remove the external wire, and try to route GPIO12 through the GPIO Matrix to PWM0_SYNC0, there's no syncing. I can't just call mcpwm_gpio_init() to connect up GPIO12 to PWM0_SYNC0, as it's been set as an output and mcpwm_gpio_init() would disable the output, so I call these functions instead:

Code: Select all

    PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[GPIO_SYNC0_IN]);
    gpio_matrix_in(GPIO_SYNC0_IN, PWM0_SYNC0_IN_IDX, false);    
It doesn't work, there's no syncing:
2018-02-23 at 1.53 PM.png
2018-02-23 at 1.53 PM.png (17.39 KiB) Viewed 6165 times
Can I connect a GPIO output to a peripheral input through the GPIO Matrix? If so, what am I doing wrong?

Full code is here

Re: How to connect GPIO output with peripheral input - single pin

Posted: Sat Feb 24, 2018 3:42 am
by WiFive
Shouldn't it be

Code: Select all

PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[12]);
gpio_matrix_in(12, PWM0_SYNC0_IN_IDX, false);   

Re: How to connect GPIO output with peripheral input - single pin

Posted: Sat Feb 24, 2018 9:18 am
by embedded-creations
WiFive wrote:Shouldn't it be

Code: Select all

PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[12]);
gpio_matrix_in(12, PWM0_SYNC0_IN_IDX, false);   
Thanks, but GPIO_SYNC0_IN is #defined to 12 in my code for the SYNC_PIN_SOURCE_INTERNAL test, so my code is effectively the same as what you suggested.

Re: How to connect GPIO output with peripheral input - single pin

Posted: Tue Feb 27, 2018 3:44 pm
by embedded-creations
I figured it out after stumbling across the GPIO_MODE_INPUT_OUTPUT definition in some code.

It's not as easy as calling gpio_set_direction(GPIO_NUM_12, GPIO_MODE_INPUT_OUTPUT) as gpio_set_direction doesn't handle GPIO_MODE_INPUT_OUTPUT properly. It does seem to work when calling gpio_config() with the mode set to GPIO_MODE_INPUT_OUTPUT.

I updated the Gist with working code.