LM4f120: Using “buttons.h” for inbuilt buttons.

Last few days I spent a lot of time with the LM4F120 board just to get familiarized with the Stellarisware APIs. There are some documents available with the software which gives a good picture on the behavior of those APIs. Since TI discontinued Stellarisware you can find these documents under Tivaware section in TI.com.

Following is the way to implement ‘button.h’ in your code. Here, I will be using inbuilt buttons to turn on and off the LEDs in the circuit.

Code:

#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "drivers/buttons.h"

int main(void) {

unsigned char button_val;
unsigned char Delta;
unsigned char Rawstate;

SysCtlClockSet(SYSCTL_SYSDIV_5| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE , GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

ButtonsInit();

while(1){
SysCtlDelay(100000);

button_val = ButtonsPoll(&Delta, &Rawstate);

if(BUTTON_PRESSED(LEFT_BUTTON,button_val,Delta)){
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0xFF);
}

if(BUTTON_PRESSED(RIGHT_BUTTON,button_val,Delta)){
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
}
}

}

But unfortunately this code alone will not do the trick. You should strictly adhere to following steps in order to build this code. Otherwise you will receive “Unresolved variable …” errors.

Include path:

In order to make sure that your includes are working you must mention the include paths to the compiler.

include

Linker:

Following library file should also be added.

linker

Pre-processor:

Following pre-processor macros should also be added.

preprocessor

Virtual link:

Buttons.c file should also be linked to the project.

File > Import > General > File system

virtual

Now build the code and use it in your hardware.

Thank you.

7 comments

  1. I’m having trouble to compile several projects from internet that use the StellarisWare.

    I followed the project but appeared 6 erros.

    – Description Resource Path Location Type
    #10010 errors encountered during linking; “Basico – Button Polling – biblioteca da stellaris.out” not built Basico – Button Polling – biblioteca da stellaris C/C++ Problem
    – Description Resource Path Location Type
    #10234-D unresolved symbols remain Basico – Button Polling – biblioteca da stellaris C/C++ Problem
    – Description Resource Path Location Type
    unresolved symbol ROM_GPIODirModeSet, first referenced in ./buttons.obj Basico – Button Polling – biblioteca da stellaris C/C++ Problem
    – Description Resource Path Location Type
    unresolved symbol ROM_GPIOPadConfigSet, first referenced in ./buttons.obj Basico – Button Polling – biblioteca da stellaris C/C++ Problem
    – Description Resource Path Location Type
    unresolved symbol ROM_GPIOPinRead, first referenced in ./buttons.obj Basico – Button Polling – biblioteca da stellaris C/C++ Problem
    – Description Resource Path Location Type
    unresolved symbol ROM_SysCtlPeripheralEnable, first referenced in ./buttons.obj Basico – Button Polling – biblioteca da stellaris C/C++ Problem

    How I can resolve this?

    1. Hello Haroldo,

      Thank you for your question. Your linking seems to be the problem. Make sure that the paths you entered for the include libraries are correct.
      What is the IDE that you are using?

      Check you linking paths and include paths again and let me know.

      If you cannot resolve the issue. Please mail your source to info@unboxnbeyond.com and put a comment here.

      Thank you.

  2. I have the same issue, I have copied your code and replaced my main.c in earnest, checking every include/ paths and pre-processor step is identical. I then get these errors:

    Description Resource Path Location Type
    #10010 errors encountered during linking; “lab3.out” not built lab3 C/C++ Problem
    #10234-D unresolved symbols remain lab3 C/C++ Problem
    unresolved symbol ROM_GPIOPadConfigSet, first referenced in ./drivers/buttons.obj lab3 C/C++ Problem
    unresolved symbol ROM_GPIODirModeSet, first referenced in ./drivers/buttons.obj lab3 C/C++ Problem

    I am using CCS, Just wondering if you have had any more thoughts on this.

    1. Hello Peter,

      Thank you for the comment. It looks like you have not included the pre processor defines correctly. In order to use the stellaris rom you need to put the following definition at, “Project options > Build > Arm compiler > Advanced options > Pre defined symbols > Pre-define name ”

      PART_LM4F120H5QR
      TARGET_IS_BLIZZARD_RA1

      I hope you are using the stellaris launchpad. I got the same issue when I remove the TARGET_IS_BLIZZARD_RA1 definition. Please let me know which board you are using.

      Thank you.

  3. Its odd, because I get the same ROM errors as warning and errors. I deleted my current predefined symbols and copy and pasted your text, they were identical however. Do you know if the order matters? Is it necessary to add these same macros to the ARM linker as well perhaps? I am using the stellaris launchpad yes, thanks for your quick reply!

    1. Hello Peter,

      So it seems like your issue still exist. hmmm..

      >> Do you know if the order matters?

      The order of the definitions should not matter. Even if you define them using “#define” within the code, that should work. So it acts same as a normal C “#define”.

      >> Is it necessary to add these same macros to the ARM linker as well perhaps?

      In-fact after your issue I started a project from the scratch and followed the same procedure I explained in the post. So the only linker related configuration I did was adding the linker file search path to “C:\StellarisWare\driverlib\ccs-cm4f\Debug\driverlib-cm4f.lib”.

      If you still have the issue and if the code can be disclosed, can you please ‘zip’ your project and mail it to info@unboxnbeyond.com. I will look into it.

      >> thanks for your quick reply!

      Welcome!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s