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.

EK-TM4C123GXL: When I write anything inside my 'while' loop, the board crashes.

Part Number: EK-TM4C123GXL

Hi there,

I am using a software called Keil uVision 5. I am having an issue with my board in which I do not understand why.

When I write anything inside my 'while' loop, the board crashes. If the 'while' loop is empty, everything works fine. See below example: 

#include "TM4C123.h"
int main()
{
SYSCTL->RCGCGPIO |=0X20;
GPIOF->DIR |=0X04;
GPIOF->DEN |=0X04;
GPIOF->DATA |=0x04;
while(1)
{}
}

The above code works fine. However, if I add anything inside the 'while' loop, the board crashes. See below:

#include "TM4C123.h"
int main()
{
SYSCTL->RCGCGPIO |=0X20;
GPIOF->DIR |=0X04;
GPIOF->DEN |=0X04;
while(1)
{
GPIOF->DATA |=0x04;
}
}

The first code works fine, but the second leads to a crash. Do you have any advice/recommendations? 

Thank you.

  • That is a bit weird. Can you try other pins? Will you have the same problem? Can you add some delay inside the while loop?

    BTW, please refer to #4 note in the FAQ https://e2e.ti.com/support/microcontrollers/other/f/908/t/695568. We normally don't support DRM style of coding. It is prone to mistake. Please use the TivaWare library to develop your application.

  • This is a program that blink the LED connected to the PF3 pin using TivaWare. As you can see it is much easier to understand and develop the application. You can read its source code if you insist to use the DRM mode. 

    //*****************************************************************************
    //
    // Blink the on-board LED.
    //
    //*****************************************************************************
    int
    main(void)
    {
        volatile uint32_t ui32Loop;
    
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        //
        // Check if the peripheral access is enabled.
        //
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF))
        {
        }
    
        //
        // Enable the GPIO pin for the LED (PF3).  Set the direction as output, and
        // enable the GPIO pin for digital function.
        //
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
    
        //
        // Loop forever.
        //
        while(1)
        {
            //
            // Turn on the LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
    
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
            {
            }
    
            //
            // Turn off the LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0x0);
    
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
            {
            }
        }
    }

  • Thank you very much for your quick response, Charles.

    I tried using the TivaWare library, and the program worked.

    Best Wishes