Search code examples
cembeddedkeil

Unable to blink LED on TM4C123G?


My TI Tiva ARM program is not working on TM4C123G. Using board EK TM4C123GXL. Program doesn't blink on board RGB LEDs. I am able to run other example program to check the LEDs, this program is from textbook TI TIVA ARM PROGRAMMING FOR EMBEDDED SYSTEMS. Need help to debug this program. Thanks

Code:

/*  p2.4.c: Toggling a single LED

/*  This program turns on the red LED and toggles the blue LED 0.5 sec on and 0.5 sec off. */

#include "TM4C123GH6PM.h"

void delayMs(int n);

int main(void)
{

    /* enable clock to GPIOF at clock gating control register */
    SYSCTL->RCGCGPIO |= 0x20;
    /* enable the GPIO pins for the LED (PF3, 2 1) as output */
    GPIOF->DIR = 0x0E;
    /* enable the GPIO pins for digital function */
    GPIOF->DEN = 0x0E;
    /* turn on red LED only and leave it on */
    GPIOF->DATA = 0x02;
    
    while(1)
    {      
        GPIOF->DATA |= 4;    /* turn on blue LED */
        delayMs(500);

        GPIOF->DATA &= ~4;   /* turn off blue LED */
        delayMs(500); 
    }
}

/* delay n milliseconds (16 MHz CPU clock) */
void delayMs(int n)
{
    int i, j;
    for(i = 0 ; i < n; i++)
        for(j = 0; j < 3180; j++)
        {}  /* do nothing for 1 ms */
}

I am using KEIL IDE-Version: µVision V5.36.0.0

Tool Version Numbers:
Toolchain:        MDK-Lite  Version: 5.36.0.0
Toolchain Path:    G:\Keil_v5\ARM\ARMCLANG\Bin
C Compiler:         ArmClang.exe        V6.16
Assembler:          Armasm.exe        V6.16
Linker/Locator:     ArmLink.exe        V6.16
Library Manager:    ArmAr.exe        V6.16
Hex Converter:      FromElf.exe        V6.16
CPU DLL:               SARMCM3.DLL          V5.36.0.0
Dialog DLL:         TCM.DLL              V1.53.0.0
Target DLL:             lmidk-agdi.dll       V???
Dialog DLL:         TCM.DLL              V1.53.0.0

Solution

  • It looks like some issue with the compiler version optimization. Reverted back to v5. enter image description here