2
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ Which toolchain are you using? \$\endgroup\$ – AndrejaKo Jul 22 '12 at 14:36
  • \$\begingroup\$ @AndrejaKo I'm using msp430-gcc in linux \$\endgroup\$ – Leonardo Marques Jul 22 '12 at 14:40
  • 2
    \$\begingroup\$ there is no outPWM function mention in pwm.c ? \$\endgroup\$ – pstan Jul 22 '12 at 16:05
  • \$\begingroup\$ @pstan there is, it was my mistake when writing the question I'm sorry \$\endgroup\$ – Leonardo Marques Jul 22 '12 at 19:15
5
\$\begingroup\$

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

\$\endgroup\$

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.