Translate

Friday, October 14, 2011

MSP430 - IAR vs mspgcc

Updated !
There are some differences between a C program developed with IAR and one developed for mspgcc.
This article will try to address these differences in order  to port a MSP430 program developed for IAR into a mspgcc one and viceversa.
I'll try to keep update the article every time I found something or if I receive suggestions.

With the mspgcc (msp430-elf) version maintained by TI, there are further differences.


Include files

Component 

The main inclusion file necessary is related to the component used.
With IAR usually it was #include <msp43xxxxx.h> wherexxxx indicated the specific family.

With mspgcc is better to include the file io.h and set the cflags to the correct cpu.
For example :


 IAR mspgcc  msp430-elf
Family MSP430 F 2012
#include <msp430x20x2.h>
#include <io.h>
set -mmcu=msp430x2012 in cflags
#include <msp430.h>
#include <legacymsp430.h>
set -mmcu=msp430f2012 in cflags
Be sure to have -I and -L in the CFLAGS with the path to the MSP430_TI/include

In Code::Blocks, in order to add the correct mmcu flag :
  • open Settings/Compiler and Debugger 
  • go in the tab Compiler Settings/Other options
  • add the line -mmcu=msp430x2012 (or the specific mcu used)

Or, it is possible to find and include the correct header.
Looking in the file io.h is possible to see the correct inclusion. 

Ports

Some programs with IAR uses different port notation.
For example, the demo program for the MSP430F169, used in the Olimex card, uses the notation :
P3OUT_bit.P3OUT_0 to address the bit 0 of the port 3.

With mspgcc the single bit need to be addressed differently.
If a single bit needs to be addressed, it is necessary to use the mask bits.
For example, to set the bit zero to 1or the port3 :

P3OUT |= 0x01;

To set it to zero :

P3OUT &= ~0x01;

Better to prepare some defines, something like this :

#define BIT_0 0x01
#define BIT_1 0x02
#define BIT_2 0x04
#define BIT_4 0x08
#define BIT_5 0x10
#define BIT_6 0x20
#define BIT_7 0x40
#define BIT_8 0x80

and then use notation like :

P3OUT |= BIT_0

Interrupts

In IAR the interrupt function is a normal function with __interrupt as type.
mspgcc has a special function called interrupt.

Because of that under mspgcc no function prototypes are allowed for interrupt functions.
For example, for the Timerinterrupt function :

 IAR  mspgcc  msp430-elf
/* Timer A0 interrupt service routine */
__interrupt void Timer_A (void);
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A( void )
{
...
}
// Timer A0 interrupt service routine
interrupt(TIMERA0_VECTOR) Timer_A (void)
{
....
}
// Timer A0 interrupt service routine
__attribute__((__interrupt__(TIMERA0_VECTOR)))
void Timer_A (void)
{
....
}

To enable the interrupts is possible to use the function eint() or _BIS_SR(GIE);
Include the file signals.h when it is used (#include <signals.h>)

No comments:

Post a Comment