Mike Jablonski
Mike Jablonski

Reputation: 1755

Change from C compiler to C++ compiler causes compiler errors for MSP430 firmware

I am trying to compile a tried and true piece of firmware for the Texas Instruments MSP430 micro-controller with a new compiler (a C++ compiler, under Visual Studio using VisualGDB).

All prior versions of this firmware were compiled with a C compiler, with zero errors and zero warnings. The change from a C compiler to a C++ compiler must be the reason for my problem. (The code compiled with the C compiler has been running without problems for five years.)

Given this code snippet:

#include <msp430x14x.h>
WDTCTL = WDTPW+WDTHOLD;

I get this error:

error: 'WDTCTL' does not name a type c:\msptest\LedBlink\LedBlink.cpp

WDTCLT is declared in msp430x14x.h.

Can someone please point me in the right direction?

Upvotes: 0

Views: 562

Answers (3)

Mike Jablonski
Mike Jablonski

Reputation: 1755

Thank you to all that responded. The responses are helpful beyond the question that I asked.

I have found, and corrected, the problem. The problem was, I must admit, a careless error on my part. I cut and pasted code from a completed C program into a test program, omitting

int main()

Thus, the assignment statements that the compiler complained about were in the incorrect scope of the source code.

I posted my question prematurely.

That said, your answers are most helpful in making a decision to move ahead with using the GCC compiler (with Visual Studio as the IDE), or using the same compiler that I used for all previous versions of this firmware. I learned much from the set of answers you provided.

Thanks!

Upvotes: 0

Clifford
Clifford

Reputation: 93476

Two things are possible:

  • msp430x14x.h provided with each compiler are different - there is no standard form for such a header and each vendor may define them differently.
  • You are using the header from one compiler with another and it uses incompatible compiler extensions or syntax.

There is no doubt a great deal of compiler specific or "macro magic" going on here - what you need to look at is exactly how these macros are expanded by the pre-processor. The compiler is complaining about the expanded code, not the source you have posted.

The pre-processor has been used here to create syntax that would not otherwise be valid C or C++ so without consideration of the expansion, not much can be determined. And since each compiler may supply a different msp430x14x.h, without knowing exactly what C and what C++ compiler were used, not a lot can be said on that either. Remember that the full expansion must be considered - so if a macro is defined in terms of other macros, they too must be expanded. GCC has a n option top output the pre-processor output, or you can run the pre-processor separately directly (the executable is "cpp").

Upvotes: 3

TJD
TJD

Reputation: 11896

The problem is that WDTCTL is defined using sfrw, and although not shown in your code, sfrw is defined in iomacros.h as an inline asm statement. Clearly inline asm is going to be processor dependent and what works for msp430 won't work in visual studio.

Upvotes: 0

Related Questions