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.

TM4C123GH6PM: GPIOPinRead causes fault ISR when USB enabled.

Part Number: TM4C123GH6PM

I am trying to expand on a working gamepad project to increase the number of GPIO buttons available but keep getting fault ISRs when I try to use port D GPIO.

I have minimized the project as shown below to highlight the issue.

Whenever execution gets to the ROM_GPIOPinRead() statement Tiva faults.

If I comment out the 2 lines that configure the USB pins [SysCtlGPIOAHBEnable();ROM_GPIOPinTypeUSBAnalog();] the GPIO read executes without issue (obviously USB doesn't enumerate though).

Thoughts?

int main()
{
    volatile uint8_t D;

    ROM_FPULazyStackingEnable();

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //Unlock the GPIO inputs which are locked
    HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= GPIO_PIN_7;
    
    ROM_GPIODirModeSet(GPIO_PORTD_BASE, 0xcf, GPIO_DIR_MODE_IN);
    ROM_GPIOPadConfigSet(GPIO_PORTD_BASE, 0xcf, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)));

    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    
    while(1)
    {
        D = ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0);
    }
    
}

  • I get a similar result with other peripherals, so this is not USB specific.
    E.G. I also use the ADC in my project and if I try using some some bits of port E as digital and others as ADC then accessing the digital GPIO causes a fault too.
    It looks like there is an incompatibility in Tivaware in configuring the GPIO and peripherals, but I haven't been able to determine a sequence/order yet that works.
    BR,
    Steve
  • Hello Steve,

    I don't see a call for GPIOPinTypeGPIOInput for GPIO_PIN_0. Try including that in your configuration and the issue should resolve.
  • Ralph,
    I thought that GPIODirModeSet/GPIOPadConfigSet were effectively alternatives to GPIOPinTypeGPIOInput that allowed control over the pullup etc...?
    I have not use GPIOPinTypeGPIOInput on any of the other GPIOs and they behave as expected, although there are no alternate peripherals being used on the working ports.

    Anyhow, I tried adding "GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, 0xcf);" before the while(SysCtlPeripheralReady) and I still get the fault ISR.

    I also tried removing the GPIODirModeSet/GPIOPadConfigSet in lieu of GPIOPinTypeGPIOInput but again I still get the fault ISR.

    BR,
    Steve
  • Hello Steve,

    Ah I found the missing detail that tripped me up too.

    Here are the comments for SysCtlGPIOAHBEnable

    //! This function is used to enable the specified GPIO peripheral to be
    //! accessed from the Advanced Host Bus (AHB) instead of the legacy Advanced
    //! Peripheral Bus (APB).  When a GPIO peripheral is enabled for AHB access,
    //! the \b _AHB_BASE form of the base address should be used for GPIO
    //! functions.  For example, instead of using \b GPIO_PORTA_BASE as the base
    //! address for GPIO functions, use \b GPIO_PORTA_AHB_BASE instead.

    So what is really needed is:

    D = GPIOPinRead(GPIO_PORTD_AHB_BASE, GPIO_PIN_0);

    Code runs fine when doing that.

    Hadn't run into that little quirk before myself :)

  • Ralph,

    Thanks for the feedback.

    So, I actually kinda did the opposite, and converted my AHB calls to non-AHB since I had a significant amount of code not using AHB. This was cause my merging some older example code with newer working code I had.

    So, for example...
      SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
      ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    Became   
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4);

    Bottom line though is don't mix AHB and non-AHB :)

    I didn't notice the AHB references (well, I kinda did but had no clue about their significance!!)

    Anyhow, your guidance helped resolve my issue. Thanks.

    BR,

    Steve