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.

Error when compiling with gcc in terminal

Other Parts Discussed in Thread: TM4C123GH6PM

Hi,

I'm trying to compile a basic program that uses I2C for a TM4C123GH6PM without using any IDE (running Linux Mint 17 x64). So I found a Makefile that should be able to do this:

# Tiva Makefile
# #####################################
#
# Part of the uCtools project
# uctools.github.com
#
#######################################
# user configuration:
#######################################
# TARGET: name of the output file
TARGET = main
# MCU: part number to build for
MCU = TM4C123GH6PM
# SOURCES: list of input source sources
SOURCES = main.c startup_gcc.c
# INCLUDES: list of includes, by default, use Includes directory
INCLUDES = -IInclude
# OUTDIR: directory to use for output
OUTDIR = build
# TIVAWARE_PATH: path to tivaware folder
#TIVAWARE_PATH = /home/eric/code/tivaware
#TIVAWARE_PATH gets set by an environment variable

# LD_SCRIPT: linker script
LD_SCRIPT = $(MCU).ld

# define flags
CFLAGS = -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
CFLAGS +=-Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall
CFLAGS += -pedantic -DPART_$(MCU) -c -I$(TIVAWARE_PATH)
CFLAGS += -DTARGET_IS_BLIZZARD_RA1 -Dgcc
LDFLAGS = -T $(LD_SCRIPT) --entry ResetISR --gc-sections

#######################################
# end of user configuration
#######################################
#
#######################################
# binaries
#######################################
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
OBJCOPY = arm-none-eabi-objcopy
RM      = rm -f
MKDIR	= mkdir -p
#######################################

# list of object files, placed in the build directory regardless of source path
OBJECTS = $(addprefix $(OUTDIR)/,$(notdir $(SOURCES:.c=.o)))

# default: build bin
all: $(OUTDIR)/$(TARGET).bin

$(OUTDIR)/%.o: src/%.c | $(OUTDIR)
	$(CC) -o $@ $^ $(CFLAGS)

$(OUTDIR)/a.out: $(OBJECTS)
	$(LD) -o $@ $^ $(LDFLAGS)

$(OUTDIR)/main.bin: $(OUTDIR)/a.out
	$(OBJCOPY) -O binary $< $@

# create the output directory
$(OUTDIR):
	$(MKDIR) $(OUTDIR)

clean:
	-$(RM) $(OUTDIR)/*

.PHONY: all clean

The problem is I get `undefined reference to `GPIOPinTypeI2CSCL'` and `undefined reference to `GPIOPinTypeI2C'` when trying to compile. The two lines that cause the error are:

    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

If I comment these lines out, I can compile and run the program on the device, but I2C obviously doesn't work.

These are the relevant include statements in my source code:

#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_i2c.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/i2c.h"

Is there anything wrong with my Makefile or am I missing an include?

  • Hello Ari,

    I guess this is during Link Phase that you are getting an error. Please check if the driverlib.lib has been included for link

    Regards

    Amit

  • How do I do this?

    This is the output from make VERBOSE=1:

    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/ari/development/launchpad/tivaware -DTARGET_IS_BLIZZARD_RA1 -Dgcc
    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/ari/development/launchpad/tivaware -DTARGET_IS_BLIZZARD_RA1 -Dgcc
    arm-none-eabi-ld -o build/a.out build/main.o build/startup_gcc.o -T TM4C123GH6PM.ld --entry ResetISR --gc-sections
    arm-none-eabi-objcopy -O binary build/a.out build/main.bin

    Also, shouldn't there be ROM_ versions of these methods that don't need to link with driverlib but use the version in the launchpad's ROM?

  • Hello Ari,

    The arm-none-eabi-ld must have the precompiled library file option as "-l" or "--library" for the path where the driverlib in TivaWare is kept under driverlib\gcc\libdriver.a

    Regards

    Amit

  • Thanks, adding

    -L $(TIVAWARE_PATH)/driverlib/gcc -l driver

    fixed the compiler errors. Just wondering why ROM_... versions of these particular functions don't exist?

  • Hello Ari,

    It does exist. The define that you are using i.e. TARGET_IS_BLIZZARD_RA1 is not correct. For TM4C devices it must be TARGET_IS_TM4C123_RB1

    Regards

    Amit

  • Ah thanks then the previous solution of adding the driverlib library is not actually necessary.

  • Hello Ari,

    For any function which does not have a ROM equivalent then you do not need to.

    Regards

    Amit