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.

TM4C123G6HPM管脚解锁问题

Other Parts Discussed in Thread: EK-TM4C123GXL

  • TM4C123x的PF0和PD7脚有锁,在解锁后方可以指定管脚功能。详细信息请参考GPIO部分的GPIOLOCK和GPIOCR寄存器及相关描述。

如果需要调整PF0的功能,需要在使能PF脚后执行如下操作:

HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;//解锁

HWREG(BUTTONS_GPIO_BASE + GPIO_O_CR) |= 0x01;// (GPIOCR 寄存器的内容只有在 GPIOLOCK 寄存器解锁时才能被修改)确认相应的位如果是PD7解锁应该写入0x80

HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = 0;//重新锁定

要包含的头文件

#include "inc/hw_types.h"

#include "inc/hw_gpio.h"

 

实际上不只是PD7和PF0,PC[3:0]也是有锁的。因为PD7和PF0是和NMI中断复用的,NMI中断优先级很高(仅次于复位中断),为了防止程序误动作,加锁可以起到保护作用。PC[3:0]是Jtag。也是一种保护。

可参考例程

C:\ti\TivaWare_C_Series-1.0\examples\boards\ek-tm4c123gxl\drivers\buttons.c

//PF0解锁

        HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;//解锁

        HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;//确认

        HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;//重新锁定

        GPIOPinTypeGPIOInput(GPIO_PORTC_BASE,GPIO_PIN_4|GPIO_PIN_5 |GPIO_PIN_6);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);//使能GPIOF

 

//PD7解锁

        HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;//解锁

        HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0x80;//确认

        HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;//重新锁定

  • JTAG接口的解锁操作,可以参考如下例程:

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c123gxl\gpio_jtag

  • “UNLOCK problem with TM4C123GH6M PF0 Pin”

    I’m using PF0 pin as SSI1 RX function, but PF0 default is NMI. I write the unlock PF0 code as the example showed in forum as follows.

     

        HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK)  = GPIO_LOCK_KEY;   //Unlock

        HWREG(GPIO_PORTF_BASE+GPIO_O_CR)   |= 0X01;     // Enable PF0 AFS

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1);     GPIOPinConfigure(GPIO_PF0_SSI1RX);         

        HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK) =0;          // Relock

    It works well on the first time the program is debugged and PF0 is working as SSI1RX. But when the target board is reset or re-power on. The TM4C123G does not work and runs into a fault ISR which led to an infinite loop. After this it never works again, unless we comment the unlock program code. But if we do this, the PF0 function is default to NMI pin again.

    How can I permanently set PF0 to SSI1RX function?