This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Unconfiguring a GPIO Pin's alternative function



I am working with CCS5.4 on a TM4F212EFQC (or maybe a big brother for now).  I am writing a functional test app for the HW.  For some applications a pin will be configured for GPIO output and sometimes PWM output.  With one application I want to toggle between the two functions.  I use the following line of code to configure the pin for an alternative function:

GPIOPinConfigure (GPIO_PH5_M0PWM5);

But there is not a GPIOPinUnconfigure function or a GPIO_PH5_GPIO value. 

So once configured as PWM, how do I reconfigure the pin back to GPIO?  Looking at the code it seems sending it a 0x00 would be a bad idea.

(Currently it seems the option is to start running as GPIO, run GPIO tests, switch to PWM, run PWM tests and if you want to go back to GPIO, then reset.  This may work for a functional test.  I am not sure I can think of an application in the field that would need the functionality.)

  • Maybe:

    GPIOPinConfigure (GPIO_PH5_M0PWM5&0xFFFFFFF0);

    ???

  • Suspect a subsequent, single GPIOPinTypeGPIOOutput() and (for assurance) a following GPIOPadConfigSet() will do that trick...

    GPIOPadConfigSet() gives you full control over output strength and/or push-pull or other output formats...

    One thing I find useful - Stellaris training our group - GPIOPinConfigure() is only used to "break" that pin's normal/customary GPIO connection.  (i.e. force that pin into Alternate Function mode)  That point never openly/fully made in the docs.  (we could not find...)

    Update: we note that alternative post (below) "misses" this advisory (part of suggested,  gpiodirectmodeset()

    Note:
    GPIOPadConfigSet() must also be used to configure the corresponding pad(s) in order for them
    to propagate the signal to/from the GPIO.    You may well consider this point...

    Note further: GPIOPinTypeGPIOOutput() includes GPIODirModeSet() AND GPIOPadConfigSet() - thus clearly is superior method...  And enables your follow on (although not mandatory) use of GPIOPadConfigSet() - should you need any output "tweak."

  • John Osen said:
    So once configured as PWM, how do I reconfigure the pin back to GPIO?

    From the description of the GPIO Alternate Function Select (GPIOAFSEL) register in a LM4F datasheet:
    The GPIOAFSEL register is the mode control select register. If a bit is clear, the pin is used as a GPIO and is controlled by the GPIO registers. Setting a bit in this register configures the corresponding GPIO line to be controlled by an associated peripheral.
    The GPIODirModeSet TivaWare driverlib function sets or clears a bit in GPIOAFSEL according to its ui32PinIO parameter.

    From reading the TivaWare driverlib gpio.c file, if you call GPIOPinTypeGPIOInput or GPIOPinTypeGPIOOutput the corresponding bit in GPIOAFSEL will be cleared, via a call to GPIODirModeSet, returning the pin to GPIO use.