Electronic – Compiling MSP430 files linking problems

compilergccmsp430

I'm trying to compile a simple C file to later upload to my MSP430 uC but when I try to compile I get something that looks like a linking problem:

main.c:7: undefined reference to `outPWM'

my folder contains these files:

  1. main.c
  2. pwm.h
  3. pwm.c

main.c only has this simple instructions:

#include <io.h>
#include <stdint.h>
#include "pwm.h"
int main( void ){
    // Stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;
    outPWM(1,4,100);    
    return 0;
}

pwm.h only has the function prototype and some macros:

#define MCU_CLOCK       160000000
#define PWM_FREQUENCY   50
//Set z% PWM duty cicle output on port x.y
int outPWM(uint8_t x,uint8_t y,uint8_t z);

and pwm.c has the function that is quite big so just for the sake of the example it will be this:

#include <io.h>
#include <signal.h>
#include "pwm.h"

int outPWM(uint8_t port,uint8_t sel,uint8_t PWM_Duty){
    return 0;
}

I might be using the wrong options while compiling but I have no idea what should I use besides what is provided in some examples on the web that I adapted to this:
msp430-gcc main.c -mmcu=msp430x2252 -O2 -Wall -o main.o

What am I doing wrong?

Thank you.

EDIT
Corrected function name in pwm.c

Best Answer

You have to compile both of your source files into your object file. Add pwm.c after main.c on the command line.

Related Topic