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: How to unlock PD7 Pin to use it as UART2 Transmit pin in TM4C123GH6PM CUSTOM BOARD?

Part Number: TM4C123GH6PM

Hello all,

I've designed my own TM4C123GH6PM CUSTOM BOARD. I missed out the point that PD7 is locked PIN while designing the PCB  . So now I want to use UART2 on the custom board.

All other UARTs are working fine. Kindly suggest!

  • Hello Ralph,

    I tried unlocking the Pin as suggested in the link mentioned by you, but my code goes into Fault ISR

    Below is code for unlocking and UART initilization

    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/uart.h"

    int main()
    {
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // clock at 80 Mhz

    ui32SysClkFreq = 80000000;

    HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;

    HWREG(GPIO_PORTD_BASE+GPIO_O_CR) |= GPIO_PIN_7;

    /*********************UART2 INTILIAZATION********************************/
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
    while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_UART2)));

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    GPIOPinConfigure(GPIO_PD6_U2RX);
    GPIOPinConfigure(GPIO_PD7_U2TX);
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6| GPIO_PIN_7);

    UARTConfigSetExpClk(UART2_BASE, ui32SysClkFreq, 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


    UARTFlowControlSet(UART2_BASE,UART_FLOWCONTROL_NONE);
    IntEnable(INT_UART2);
    UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);

    IntMasterEnable();

    while(1)
    {
    }


    }

    But My code goes into Fault ISR. I've added the ISR for UART2 in startup.c file
  • Hello Sumit,

    The initialization seems fine to me, and if you correctly added the right ISR to the UART2 portion for startup_ccs.c, then I don't have an immediate suggestion on a root cause.

    Please refer to our Fault Diagnosis app note to try and find out the root cause of the fault: http://www.ti.com/lit/an/spma043/spma043.pdf

    If you get stuck regarding what to do once you've identified the fault, let me know what steps you've taken from the app note and what the results are and I can try to help guide you further then.

  • Code shown does not establish the fact that,

    "SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);" - which is w/in "UART2_INIT"

    Executes prior to "Main's" call to, "HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;" - which will yield a visit to "Fault ISR."

    By "single-stepping" your code - you should be able to identify the "exact location" of, "Entry to the Fault ISR."      Your report of such would greatly aid remote diagnostics...

  • Hello cb1,

    Great catch, I didn't recall of the importance of the ordering for the Unlock sequence. Yes, the SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); needs to be called before the Unlock process is executed.

    So the proper sequence would be (for the sake of Sumit's full clarity):

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTD_BASE+GPIO_O_CR) |= GPIO_PIN_7;

    And that would then followed by any configuration API's.

    Thanks for catching what I failed to :)

  • Ralph,

    Thank you - as always - appreciated.

    Your crüe answers "so many" - AND my crack staff (yet never moi...HA!) have made that mistake SO MANY TIMES - it has (almost) stuck!

    There's NO failing on your part - poster's "miss" of PD7's (enforced) requirement - (which VIOLATES KISS) - distracted from his, "central goal!"     KISS dictates that the "Program's Goal" be met  INITIALLY - by the shortest/simplest & most direct means.    (i.e. NOT by any port unlocking!)    

    That simplicity could have been achieved by, "Initially selecting a UART pin NOT BURDENED by "UNLOCK" - getting that to work - and only then using that code (modified to the user's desired port)  in conjunction with the (later, added) "Port Unlock."    

    As proven - yet again - the bundling of code processes "INVITES ERROR!"      Instead - confining code build to a single process  -  one at a time & test/verifying  (KISS) always  WORKS BEST!

  • Thank You Ralph for guiding me in the right way.
    My problem was solved !!
  • Thank You cb1_mobile for guiding me in the right way.
    My problem was solved !! Well one always learns from mistake. I will never miss this point again in future designs.
  • May I suggest that should you (really) seek to, "Never miss this issue again" - that you create a, (Cross-Linked/Referenced) "Code Example File" which details the "full/proper handling" of peripherals.

    Note that you do NOT have to create such an example for "each/every" peripheral. Instead - I'd like you to create a, "General Set-Up/Config. example - appropriate for most all (hopefully all) MCU Peripherals. Such would insure that both the "mated" GPIO Port - and the Peripheral Module - receive their due, "SysCtlPeripheralEnable()" function calls.

    Such a "code safety template" - can be created for other aspects of MCU programming too. Very similar to, "Aircraft Pilot's Check-List" which (always) advises during our "walk-around" inspection - and then cockpit check-out. Both the air-craft - and your MCU's check-list - should be as complete as possible - and "Followed to the utmost."