EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

MPS430 F_CPU undefined error on compilation

Started by ajmartin 12 months ago8 replieslatest reply 12 months ago336 views
Hell, I am new to the MPS family. Using Code Composer , I get the following error, I think it may be related to a setting in Code Composer I am missing, but I can not find it.

Building file: "../main.c"
Invoking: MSP430 Compiler
"C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/bin/cl430" -vmsp --use_hw_mpy=none --include_path="C:/ti/ccs1220/ccs/ccs_base/msp430/include" --include_path="C:/Users/Admin/workspace_v12/square wave" --include_path="C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/include" --advice:power=all --define=__MSP430G2231__ -g --printf_support=minimal --diag_warning=225 --diag_wrap=off --display_error_number --preproc_with_compile --preproc_dependency="main.d_raw" "../main.c"

>> Compilation failure
subdir_rules.mk:9: recipe for target 'main.obj' failed
"../main.c", line 11: error #20: identifier "F_CPU" is undefined
"../main.c", line 15: error #20: identifier "DC0CTL" is undefined
2 errors detected in the compilation of "../main.c".
gmake: *** [main.obj] Error 1
gmake: Target 'all' not remade because of errors.

**** Build Finished ****
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

# define F_CPU 1000000UL
# include <util/delay.h>
# include <mps430>
int Control = 0;

int main(void) {

/*** Watchdog timer and clock Set-Up ***/
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
DCOCTL = 0; // Select lowest DCOx and MODx
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

/*** GPIO Set-Up ***/
P1DIR |= BIT0; // P1.0 set as output
P1OUT &= ~BIT0; // P1.0 set LOW (Red LED)
P1DIR |= BIT6; // P1.6 set as output
P1OUT &= ~BIT6; // P1.6 set LOW (Green LED)

/*** Timer0_A Set-Up ***/
TA0CCR0 |= 3000; // Counter value
TA0CCTL0 |= CCIE; // Enable Timer0_A interrupts
TA0CTL |= TASSEL_1 + MC_1; // ACLK, Up Mode (Counts to TA0CCR0)

_BIS_SR(LPM0_bits + GIE); // Enter Low power mode 0 with interrupts enabled
}

#pragma vector=TIMER0_A0_VECTOR // Timer0 A0 interrupt service routine
__interrupt void Timer0_A0 (void) {

Control++;
P1OUT ^= BIT0; // P1.0 Toggle (Red LED)

if (Control == 4)
{
P1OUT ^= BIT6; // P1.6 Toggle (Green LED)
Control = 0;
}
}
[ - ]
Reply by VadimBMarch 5, 2023

It's MSP430, not MPS430.

1. Where and how is the symbol F_CPU defined?

2. Where and how is the symbol DC0CTL defined? There are two symbols, DC0CTL and DCOCTL.

3. Are you sure about #include <mps430> ? Shouldn't it be #include <msp430.h> (whatever it is and wherever it is located)? Since the compiler does not complain, it can find it. What's in that file?

[ - ]
Reply by ajmartinMarch 5, 2023

Sorry, dyslexia on the MPS, I have it in a Launchpad by TI. You are correct I need to add a .h to the include file. Lets forget about the second compile error, the first one is F_CPU undefined. It is defined, why is this error showing up? Maybe do to the mistake of leaving out the .H? I will try that soon. I kinda a doubt that would give me a F_CPU undefined error. But thanks for the suggestion, any other thoughts?


Alan

[ - ]
Reply by ajmartinMarch 5, 2023
[ - ]
Reply by VadimBMarch 5, 2023

You can generate preprocessor output to check what source the compiler tries to compile and where the problem is. I never used msp430 tools, only Sitara MCUs with gcc.

In gcc world the command line option is -E. You should find out what it is for your toolchain.

[ - ]
Reply by indigoredsterMarch 5, 2023

Try this:

Change the order to:

#include <mps430>
#define F_CPU 1000000UL
#include <util/delay.h>

note get rid of the space after the #'s ieĀ #include

[ - ]
Reply by ajmartinMarch 5, 2023

Just tried all that, same error. Let me take a different approach, can someone point me to where I can find a working example of PWM out. I am using the MSP430G2231 on a LaunchPad development tool. Also the board comes standard with out a crystal, so I am using the internal clock.


Oh I must mention, I have tried a few examples I found on the web and get the same errors as described above, So if someone has an example that is actually working, for sure. That would help in trying to figure what is NOT working here.

Thanks for the help!,


Alan



[ - ]
Reply by tcfkatMarch 5, 2023

Hello Allan!

As I have for a future project some MSP430 around here (more exactly MSP430F2013IN) I decided to install the IDE and compile your sample -- it compiles without problems, if I comment out one header file. So better check your installation.

//#include <util/delay.h>
#include <msp430.h>
#define F_CPU 1000000UL

volatile int Control = 0;

int main(void) {

   /*** Watchdog timer and clock Set-Up ***/
   WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
   DCOCTL = 0; // Select lowest DCOx and MODx
   BCSCTL1 = CALBC1_1MHZ; // Set range
   DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

   /*** GPIO Set-Up ***/
   P1DIR |= BIT0; // P1.0 set as output
   P1OUT &= ~BIT0; // P1.0 set LOW (Red LED)
   P1DIR |= BIT6; // P1.6 set as output
   P1OUT &= ~BIT6; // P1.6 set LOW (Green LED)

   /*** Timer0_A Set-Up ***/
   TA0CCR0 |= 3000; // Counter value
   TA0CCTL0 |= CCIE; // Enable Timer0_A interrupts
   TA0CTL |= TASSEL_1 + MC_1; // ACLK, Up Mode (Counts to TA0CCR0)
   _BIS_SR(LPM0_bits + GIE); // Enter Low power mode 0 with interrupts enabled
}

#pragma vector=TIMER0_A0_VECTOR // Timer0 A0 interrupt service routine

__interrupt void Timer0_A0 (void) {
   Control++;
   P1OUT ^= BIT0; // P1.0 Toggle (Red LED)
   if (Control == 4)
   {
      P1OUT ^= BIT6; // P1.6 Toggle (Green LED)
      Control = 0;
   }
}

The log:

**** Build of configuration Debug for project test ****
"C:\\ti\\ccs1220\\ccs\\utils\\bin\\gmake" -k -j 4 all -O 
Building file: "../main.c"
Invoking: MSP430 Compiler
"C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/bin/cl430" -vmsp --use_hw_mpy=none --include_path="C:/ti/ccs1220/ccs/ccs_base/msp430/include" --include_path="C:/Users/User/workspace_v12/test" --include_path="C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/include" --advice:power=all --define=__MSP430G2231__ -g --printf_support=minimal --diag_warning=225 --diag_wrap=off --display_error_number --preproc_with_compile --preproc_dependency="main.d_raw"  "../main.c"
Finished building: "../main.c"
Building target: "test.out"
Invoking: MSP430 Linker
"C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/bin/cl430" -vmsp --use_hw_mpy=none --advice:power=all --define=__MSP430G2231__ -g --printf_support=minimal --diag_warning=225 --diag_wrap=off --display_error_number -z -m"test.map" --heap_size=0 --stack_size=50 -i"C:/ti/ccs1220/ccs/ccs_base/msp430/include" -i"C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/lib" -i"C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="test_linkInfo.xml" --use_hw_mpy=none --rom_model -o "test.out" "./main.obj" "../lnk_msp430g2231.cmd"  -llibc.a 
<Linking>
warning #10443-D: The ".stack" section size is required to be aligned to 4 bytes, but the specified size, 0x32, is not. The aligned size is 0x34
remark #10372-D: (ULP 4.1) Detected uninitialized Port 2 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
Finished building target: "test.out"
**** Build Finished ****


hth, Eric

[ - ]
Reply by ajmartinMarch 5, 2023

Thank you so much, I suspected it was not the code but did know for sure. I have been on one other general forum, and the official TI micro-controller forum, and asked TI for help. It really helps me a lot to know the code complies on another machine

The 2024 Embedded Online Conference