1
\$\begingroup\$

I am trying to program the Stellaris LaunchPad to blink the red LED at 1 Hz, driven by the sysTick interrupt. I get an error though that I've been unable to solve yet.

The C source I came up with looks like this:

#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"

#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"

#include <stdint.h>

#define LED_RED GPIO_PIN_1

uint8_t ledState = LED_RED;

void isr( void ) {
    ledState ^= ledState; // toggle LED state
    ROM_GPIOPinWrite( GPIO_PORTF_BASE , LED_RED , ledState );
}


int main() {
    // Set system clock to 80 MHz using PLL and external 16 MHz crystal.
    ROM_SysCtlClockSet( SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN );

    // Enable GPIO for LED.
    ROM_SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOF );
    ROM_GPIOPinTypeGPIOOutput( GPIO_PORTF_BASE , LED_RED );

    // Enable SysTick at 500 ms and register an interrupt service routine.
    ROM_SysTickIntRegister( isr );
    ROM_SysTickPeriodSet( 40000000 ); // 80 MHz ÷ 2 
    HWREG( NVIC_ST_CURRENT ) = 0;     // A write to this register reloads the SysTick counter
    ROM_SysTickEnable();
    ROM_SysTickIntEnable(); // <=

    while ( 1 ) {}
}

And these are the command I use to compile it:

arm-none-eabi-gcc \
        blink.c \
        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_LM4F120H5QR \
        -c \
        -I~/stellaris/stellarisware \
        -DTARGET_IS_BLIZZARD_RA1

blink.c: In function 'main':
blink.c:34:2: warning: implicit declaration of function 'ROM_SysTickIntRegister' [-Wimplicit-function-declaration]
  ROM_SysTickIntRegister( isr );
  ^

and to link:

arm-none-eabi-ld \
         -T blink.ld \
         --entry ResetISR \
         -o a.out \
         startup_gcc.o \
         blink.o \
         --gc-sections

blink.o: In function `main':
~/stellaris/projects/sysTickBlink/blink.c:34: undefined reference to `ROM_SysTickIntRegister'

The startup_gcc.c can be found on GitHub: https://github.com/fabhack/SW-EK-LM4F120XL/blob/master/boards/ek-lm4f120xl/blinky/startup_gcc.c

  1. How can I solve the warning and error message?
  2. Why do I have to include inc/hw_nvic.h and inc/hw_types.h when it is also included in startup_gcc.c?
  3. Why is that ResetISR used during linking? I copied it from the Makefile in StellarisWare.
\$\endgroup\$
  • \$\begingroup\$ I solved the problem described in my question. Check my git server for a working 1 ms SysTick driven interrupt. \$\endgroup\$ – jippie Jan 2 '15 at 20:42
2
\$\begingroup\$

The systick.h in my launchpad installation doesn't have ROM_* functions. It has these:

extern void SysTickEnable(void);
extern void SysTickDisable(void);
extern void SysTickIntRegister(void (*pfnHandler)(void));
extern void SysTickIntUnregister(void);
extern void SysTickIntEnable(void);
extern void SysTickIntDisable(void);
extern void SysTickPeriodSet(uint32_t ui32Period);
extern uint32_t SysTickPeriodGet(void);
extern uint32_t SysTickValueGet(void);

Drop the ROM_

Your first port of call should be looking in the requisite header file to see what the functions are you should be using.

You also need to ensure you link in the right c files from the driverlib - in this case the systick.c file.

\$\endgroup\$
  • \$\begingroup\$ That solves the compile time warning, but not the undefined reference error during linking. \$\endgroup\$ – jippie Jan 2 '15 at 16:04
  • \$\begingroup\$ See my edit. . . \$\endgroup\$ – Majenko Jan 2 '15 at 16:12
  • \$\begingroup\$ Thanks. It compiles without errors now, although I don't really get why I need to include systick.c and interrupt.c rather than the .h versions. Next step is troubleshooting why the LED doesn't blink, but that is probably outside the scope of this question. \$\endgroup\$ – jippie Jan 2 '15 at 16:19
  • \$\begingroup\$ The .h files define what functions are available for your code to use. The .c files contain the actual functions themselves. \$\endgroup\$ – Majenko Jan 2 '15 at 16:20
  • \$\begingroup\$ So could I consider it a bug in the StellarisWare? \$\endgroup\$ – jippie Jan 2 '15 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.