1

TI Tiva Arm board EK-TM4C123GXL unable to run the following program. Need help debugging, Its textbook program , Book Link : http://www.microdigitaled.com/ARM/TI_ARM_books.htm

/*  p2_7.c: Read a switch and write it to the LED */

/*  This program reads SW1 of Tiva LaunchPad and writes the inverse of the value to the green LED. SW1 is low when pressed (Normally High). LED is on when high. */


#include "TM4C123GH6PM.h"

int main(void)
{
    unsigned int value;
    SYSCTL->RCGCGPIO |= 0x20;   /* enable clock to GPIOF */
    GPIOF->DIR = 0x08;          /* set PORTF3 pin as output (LED) pin */
                                /* and PORTF4 as input, SW1 is on PORTF4 */
    GPIOF->DEN = 0x18;          /* set PORTF pins 4-3 as digital pins */
    GPIOF->PUR = 0x10;          /* enable pull up for pin 4 */

    while(1)
    {   
        value = GPIOF->DATA;    /* read data from PORTF */
        value = ~value;         /* switch is low active; LED is high active */
        value = value >> 1;     /* shift it right to display on green LED */
        GPIOF->DATA = value;    /* put it on the green LED */
    }
}
  • IDE-Version: µVision V5.36.0.0 Tool Version Numbers: Toolchain: MDK-Lite Version: 5.36.0.0 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 Dialog DLL: TCM.DLL V1.53.0.0 – Rachit Remote Dec 30 '21 at 00:56
  • 1
    Don't add information relevant to the question in comments - edit the question. This is the second question where you have stated that a particular program won't run. It was not true in the previous occasion, and I doubt it is true here. How do you know it is not running? Almost certainly it is running, but not doing what you expect. Have you stepped the code in the debugger? – Clifford Dec 30 '21 at 16:29
  • Where did your `TM4C123GH6PM.h` header file come from? The structure member `GPIOA_Type::DATA` for example should be declared with the `__IO` qualifier (or in an up-to-date CMSIS header `__IOM`). And in turn these macros should be defined as `volatile` in `core_cm4.h`. That should ensure the code works - I admit to being stumped on this one. Does it work is you declared `value` `volatile`? Should not be necessary however. Note that in any case optimising trivial code like this serves little purpose and optimised code seldom makes much sense when using a symbolic debugger. – Clifford Dec 30 '21 at 16:57
  • that header file, is coming from Keil run time environment setup – Rachit Remote Dec 30 '21 at 20:03
  • Do you have a paid for licence or is this a demo version? This is probably a question for Keil/ARM tech support: https://www.keil.com/support/contact.asp Note that Keil is a subsidiary of ARM so you will be getting the best expertise. – Clifford Dec 31 '21 at 11:04
  • Demo / student version. – Rachit Remote Jan 03 '22 at 02:05
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 07 '22 at 13:14

1 Answers1

0

Works after reverting back the compiler to v5. http://www.microdigitaled.com/commonMaterials/compiler%20version.pdf Snippet

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • 1
    It also works on the same compiler version v6, by setting the optimization flag to -o0 – Rachit Remote Dec 30 '21 at 01:28
  • https://imgur.com/a/60KbBtE – Rachit Remote Dec 30 '21 at 01:28
  • Most likely the hardware registers are not declared volatile, so the compiler is optimizing away the I/O. – stark Dec 30 '21 at 02:37
  • That was your solution to the last question too - it remains a really poor solution. The LLVM based ARM v6 compiler is superior to ARMCC v5. And the compiler is not your problem. – Clifford Dec 30 '21 at 16:31
  • @stark : That would make sense, but assuming that the standard CMSIS header is used (and the symbol names and member names suggest that), all members should be declared with `__IOM`, `__IM` or `__OM` qualifiers which are defined in `core_m4.h` as `volatile`. Also does not explain why ARMCC v5 works - it is the same header. – Clifford Dec 30 '21 at 17:03
  • This information should be in the question - it is not really an answer; rather just an observation. – Clifford Dec 30 '21 at 17:04
  • Yes, i dont know why v5 works, maybe the optimization flag is not set on v5, by default the optimization flag is set to level 1 on v6. – Rachit Remote Dec 30 '21 at 20:11
  • another observation, on v5 setting optimization flag to 1, -o1 still works, but on v6 it doesnt work. – Rachit Remote Dec 30 '21 at 20:31
  • v5 is ARM's own armcc compiler whilst v6 is clang/llvm based - they are _very_ different. On the project settings C/C++ tab there is a read-only field _"Compiler Control String"_. Copy and paste that into your question. IMO the Keil defaults to the v6 compiler are inappropriate; I suggest setting the warnings level to "unspecified" adding `-Wall` to _"Misc Controls"_, and check "Turn warnings into errors". Then set the optimisation level to -O0 if you intend to use the symbolic debugger - that does not solve your problem, but it will allow you to proceed. – Clifford Dec 31 '21 at 10:54