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.

Hardfault error while accessing GPIO

Genius 3300 points
Other Parts Discussed in Thread: TM4C123GH6PM

1. I am make PF0 & PF4 as input pull up.

2. But as soon as I am trying to access GPIO->DIR register, I get hardfault.

3. I have read that this occur if clock is not enabled for GPIO port. But I have enable clock also.

4. I am using launchpad & MCU TM4C123GH6PM .

5. Code snippet is below. I am using keil V4

Code 

#define REG32_BIT_3                ((uint32_t)0x00000008)
#define REG32_BIT_4                ((uint32_t)0x00000010)
#define REG32_BIT_5                ((uint32_t)0x00000020)
#define REG32_BIT_16               ((uint32_t)0x00010000)
#define REG32_BIT_17               ((uint32_t)0x00020000)
#define REG32_BIT_18               ((uint32_t)0x00040000)
#define REG32_BIT_19               ((uint32_t)0x00080000)


/* PF4 as input pull up */    
    SYSCTL->RCGCGPIO |= REG32_BIT_5;         /* enable PORTF clock */
    __NOP();
    __NOP();
    __NOP();
    __NOP();
    __NOP();    /* 5 NOPs */    
    GPIOF_AHB->DIR      &= (u32_t)(~REG32_BIT_4);  /* make as input */
    GPIOF_AHB->AFSEL    &= (u32_t)(~REG32_BIT_4);  /* used as GPIO */
    GPIOF_AHB->PUR      |= REG32_BIT_4;            /* pull up enabled */
    GPIOF_AHB->PDR      &= (u32_t)(~REG32_BIT_4);  /* pull down disabled */
    GPIOF_AHB->ODR      &= (u32_t)(~REG32_BIT_4);  /* not open drain */
    GPIOF_AHB->AMSEL    &= (u32_t)(~REG32_BIT_4);  /* analog function disabled */  
    GPIOF_AHB->PCTL     &= (u32_t)( ~(REG32_BIT_16 | REG32_BIT_17 | REG32_BIT_18 | REG32_BIT_19) );   /* GPIO */
    GPIOF_AHB->DEN      |= REG32_BIT_4;            /* digital function enabled */

    
/* PF0 as input pull up */    
    SYSCTL->RCGCGPIO |= REG32_BIT_5;         /* enable PORTF clock */
    __NOP();
    __NOP();
    __NOP();
    __NOP();
    __NOP();    /* 5 NOPs */
    GPIOF_AHB->LOCK      = 0x4c4f434bU;            /* write lock key */
    GPIOF_AHB->CR       |= REG32_BIT_0;            /* enable write to PF0 pin */        
    GPIOF_AHB->DIR      &= (u32_t)(~REG32_BIT_0);  /* make as input */
    GPIOF_AHB->AFSEL    &= (u32_t)(~REG32_BIT_0);  /* used as GPIO */
    GPIOF_AHB->PUR      |= REG32_BIT_0;            /* pull up enabled */
    GPIOF_AHB->PDR      &= (u32_t)(~REG32_BIT_0);  /* pull down disabled */
    GPIOF_AHB->ODR      &= (u32_t)(~REG32_BIT_0);  /* not open drain */
    GPIOF_AHB->AMSEL    &= (u32_t)(~REG32_BIT_0);  /* analog function disabled */  
    GPIOF_AHB->PCTL     &= (u32_t)( ~(REG32_BIT_0 | REG32_BIT_1 | REG32_BIT_2 | REG32_BIT_3) );   /* GPIO */
    GPIOF_AHB->DEN      |= REG32_BIT_0;            /* digital function enabled */