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.

Linux/SW-EK-TM4C123GXL: undefined reference to `GPIOPinRead'

Part Number: SW-EK-TM4C123GXL
Other Parts Discussed in Thread: TM4C123GH6PM

Tool/software: Linux

Hi 

I am trying to blink LEDs on the Tiva launchpad.

Here is my source code for blinking LEDs

1 #include <stdbool.h>
2 #include <stdint.h>
3
4 #include "inc/hw_types.h"
5 #include "inc/hw_gpio.h"
6 #include "inc/hw_memmap.h"
7 #include "inc/hw_sysctl.h"
8 #include "driverlib/gpio.h"
9 #include "driverlib/rom.h"
10 #include "driverlib/sysctl.h"
11 #include "driverlib/pin_map.h"
12 #include "driverlib/can.h"
13
14 #define LED_RED GPIO_PIN_1
15 #define LED_BLUE GPIO_PIN_2
16 #define LED_GREEN GPIO_PIN_3
17 #define SW2 GPIO_PIN_0
18 #define SW1 GPIO_PIN_4
19
20 int main()
21 {
22 ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
23 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
24 ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN);
25 ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, SW2);
26
27 for (;;) {
28
29 if (GPIOPinRead(GPIO_PORTF_BASE,SW2)) {
30 GPIOPinWrite(GPIO_PORTF_BASE, LED_GREEN, LED_GREEN);
31 } else {
32 GPIOPinWrite(GPIO_PORTF_BASE, LED_GREEN, 0);
33 }
34 }
35 }
36

when I compiled the above code using make, I got the following errors

sudha@VCHN172:~/tmc4123/Embedded/led-project$ make
arm-none-eabi-gcc -o build/main.o src/main.c -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -I/home/sudha/tmc4123/Embedded/tivaware -DTARGET_IS_BLIZZARD_RA1
arm-none-eabi-ld -o build/a.out build/main.o build/startup_gcc.o -T TM4C123GH6PM.ld --entry ResetISR --gc-sections
build/main.o: In function `main':
/home/sudha/tmc4123/Embedded/led-project/src/main.c:29: undefined reference to `GPIOPinRead'
/home/sudha/tmc4123/Embedded/led-project/src/main.c:32: undefined reference to `GPIOPinWrite'
Makefile:57: recipe for target 'build/a.out' failed
make: *** [build/a.out] Error 1

but when I use ROM_GPIOPinWrite or ROM_GPIOPinRead, the code is compiled successfully.

Please help me what is the issue when using GPIOPinWrite/GPIOPinRead, and how to solve the issue.

  • You've provided an excellent description of your issue and your Subject Line (missed by so many here) is perfect!       (Clearly identifies your issue - vastly superior to the (so often appearing) "inane" TM4xyx: TM4xyz"!)    (What were the forum designers thinking - beyond "Banning LIKE?")

    To your issue - I feel (and share) your pain.      And even after reviewing your code - I cannot provide guaranteed direction.

    I checked "gpio.h" and indeed (both) of your "references" - claimed as "undefined" - ARE present & defined!       Thus - somehow your compiler (appears) to "fail to find and/or (if found) reject the findings!"

    What I do note is an "inconsistency" w/in your code.      Your code begins w/"Only calls to ROM functions" - and then shifts (abruptly) to "Non ROM calls!"       While suspected "legal" - it (may) make you vulnerable to the condition you report.

    A quick check would see you remove those early "ROM_GPIOPinType() calls" - replace w/their "Non ROM" twins (leaving your "undefined" calls untouched) - and test/report...

    Should this "fix" fail - read up on the "MAP" call - and use that for "ALL" of your function calls.     (consistency is (most often) Good!

    Noted is your, "first ever forum post" - Welcome aboard - terrific job!

  • I don't think this is a compile error it's a link error.

    pathi sudharshan said:
    arm-none-eabi-ld -o build/a.out build/main.o build/startup_gcc.o -T TM4C123GH6PM.ld --entry ResetISR --gc-sections
    build/main.o: In function `main':
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:29: undefined reference to `GPIOPinRead'
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:32: undefined reference to `GPIOPinWrite'

    Typically, when an error mentions an undefined reference, it's not talking about a missing prototype but a missing definition. Check that the appropriate library is included in the link and is present wherever you've referenced it.

    Robert

  • "A quick check would see you remove those early "ROM_GPIOPinType() calls" - replace w/their "Non ROM" twins (leaving your "undefined" calls untouched) - and test/report..."

    I tried by removing function thar are prefixed with ROM and here is the code

    20 int main()
    21 {
    22 SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    23 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    24 GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN);
    25 GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, SW2);
    26
    27 for (;;) {
    28 // set the red LED pin high, others low
    29 if (GPIOPinRead(GPIO_PORTF_BASE,SW2)) {
    30 GPIOPinWrite(GPIO_PORTF_BASE, LED_GREEN, LED_GREEN);
    31 } else {
    32 GPIOPinWrite(GPIO_PORTF_BASE, LED_GREEN, 0);
    33 }
    34 }
    35 }
    36


    But sill I am getting the same problem

    sudha@VCHN172:~/tmc4123/Embedded/led-project$ make
    arm-none-eabi-gcc -o build/main.o src/main.c -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -I/home/sudha/tmc4123/Embedded/tivaware -DTARGET_IS_BLIZZARD_RA1
    arm-none-eabi-gcc -o build/startup_gcc.o src/startup_gcc.c -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -I/home/sudha/tmc4123/Embedded/tivaware -DTARGET_IS_BLIZZARD_RA1
    arm-none-eabi-ld -o build/a.out build/main.o build/startup_gcc.o -T TM4C123GH6PM.ld --entry ResetISR --gc-sections
    build/main.o: In function `main':
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:22: undefined reference to `SysCtlClockSet'
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:23: undefined reference to `SysCtlPeripheralEnable'
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:24: undefined reference to `GPIOPinTypeGPIOOutput'
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:25: undefined reference to `GPIOPinTypeGPIOInput'
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:29: undefined reference to `GPIOPinRead'
    /home/sudha/tmc4123/Embedded/led-project/src/main.c:32: undefined reference to `GPIOPinWrite'
    Makefile:57: recipe for target 'build/a.out' failed
    make: *** [build/a.out] Error 1


    I have read from the link eehusky.wordpress.com/.../

    The Stellaris Launchpad comes preloaded with a copy of driverlib in ROM so that when you are creating your programs you don’t need to link in a copy of driverlib yourself. What the MAP_ and ROM_ prefixes are meant to accomplish is increase the portability of applications you write for the LaunchPad. Different versions of the hardware will have different subsets of driverlib loaded into ROM.

    would you please help me how to link the driverlib as a part of the compilation process.
  • Hi Robert Adsett,
    GPIOPinRead function is present in driverlib folder. Would please help me how to link this library with the project
  • pathi sudharshan said:
    GPIOPinRead function is present in driverlib folder. Would please help me how to link this library with the project

    Since the GCC ARM compiler is being used, the driverlib/gcc/libdriver.a library in the TivaWare installation needs to be linked. Try adding the following to the command in the makefile:

    -L /home/sudha/tmc4123/Embedded/tivaware/driverlib/gcc -l driver

  • Very neat/inspired SOLUTION Chester!     You & Robert sit (high) atop the "food chain" in the area of "Compilers/Linkers" & issues "GCC."