Jump to content
43oh

Help to Port MSP430G2744 to Energia


Recommended Posts

Hello everybody,

 

I am currently working on an automated rover project working on multiple MSP430

the board in charge of the electrical power management embbeds a MSP430G2744 model.

As I quite used to work with arduino IDE I tried to port it to Energia.

 

Unfortunately I got stuck at some point editing my variant of pins_energia.h :

The timers for the ported microcontrollers appears something like T0A0 T0A1 T1A0 ... etc

On the MSP430G2744 however they only appear as TA0, TA1 etc.

The Energia.h file in cores does not allow in its enumaration list for TA0, TB0 simple notations

I understand that the second number is related to the number of the CCR capture and compare register

but not all the timers seem to be related to a CCR in the datasheet of the MSP430G2744.

 

For now I just assumed as it seems to appear in the datasheet that the number of the CCR is the same as the number

for the pin eg. OUT0 with CCR0,  OUT 1with CCR1 etc each time but is it right ?

Here come my modified file (I highlighted the tricky part in red):

 

/*
  ************************************************************************
  *    pins_energia.h
  *
  *    Pin definition functions for LaunchPad w/ msp430g2744
  *        Copyright © 2012 Robert Wessels. All right reserved.
  *
  *     Contribution: Quentin Cabrol 04.2015
  *
  ***********************************************************************
  Derived from:
  pins_arduino.h - Pin definition functions for Arduino
  Part of Arduino - http://www.arduino.cc/
 
  Copyright © 2007 David A. Mellis
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
 
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
 
  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
*/
 
#ifndef Pins_Energia_h
#define Pins_Energia_h
#ifndef BV
#define BV(x) (1 << (x))
#endif
 
#if defined(__MSP430_HAS_EUSCI_A0__) || defined(__MSP430_HAS_EUSCI_A1__)
static const uint8_t TWISDA  = 18;  /* P3.1 */
static const uint8_t TWISCL  = 19;  /* P3.2 */
static const uint8_t MOSI    = 18;  /* P3.1 */
static const uint8_t MISO    = 19;  /* P3.2 */
#define TWISDA_SET_MODE  (PORT_SELECTION0 /*| PORT_SELECTION1 /*|INPUT_PULLUP*/)  
#define TWISCL_SET_MODE  (PORT_SELECTION0 /*| PORT_SELECTION1 /*| INPUT_PULLUP*/)
#define SPIMOSI_SET_MODE (PORT_SELECTION0)
#define SPIMISO_SET_MODE (PORT_SELECTION0)
static const uint8_t SS      = 22;  /* P3.0 */    
static const uint8_t SCK     = 23;  /* P3.3 */       
#define SPISCK_SET_MODE (PORT_SELECTION0)
static const uint8_t DEBUG_UARTRXD = 24;  /* Receive  Data (RXD) at P3.5 */
static const uint8_t DEBUG_UARTTXD = 25;  /* Transmit Data (TXD) at P3.4 */
static const uint8_t AUX_UARTRXD =24;  /* Receive  Data (RXD) at P3.5 */
static const uint8_t AUX_UARTTXD = 25;  /* Transmit Data (TXD) at P3.4 */
#define DEBUG_UARTRXD_SET_MODE (PORT_SELECTION0 | (PM_UCA1RXD << 8) | INPUT)  //--> to be checked
#define DEBUG_UARTTXD_SET_MODE (PORT_SELECTION0 | (PM_UCA1TXD << 8) | OUTPUT) //--> to be checked
#define AUX_UARTRXD_SET_MODE (PORT_SELECTION0 | INPUT)
#define AUX_UARTTXD_SET_MODE (PORT_SELECTION0 | OUTPUT)
#endif
 
 
#define DEBUG_UART_MODULE_OFFSET 0x40  //--> to be checked
#define AUX_UART_MODULE_OFFSET 0x0     //--> to be checked
#define SERIAL1_AVAILABLE 1
 
 
#if defined(__MSP430_HAS_USCI_A1__)
#define USE_USCI_A1
#endif
 
 
/* Analog pins */
/* Edited on 22.04.2015 */
 
static const uint8_t A1  =1 ;  
static const uint8_t A2  =2 ;
 
static const uint8_t A6  = 3;  
static const uint8_t A7  = 4;  
 
static const uint8_t A12  = 5;  
static const uint8_t A13  = 6;   
static const uint8_t A14  = 7;  
static const uint8_t A15  = 8;  
 
//-------------------------------------------
/* Layout of the MCU.
 
   All pins support digitalWrite() and attachInterrupt()  
   Pins marked with PWM support anaglogWrite()           --> TO BE ADDED  
   Pins marked with Ax support analogRead()
 
                                          +----\/----+
      (SBWTCK)                     TEST  1|          |38  P1.7        (TA2/TDO/TDI)  
                                   DVCC  2|          |37  P1.6      (TA1/TDI)  
      (ROSC)                       P2.5  3|          |36  P1.5         (TA0/TMS)
                                   DVSS  4|          |35  P1.4        (SMCLK/TCK)  
      (XOUT)                       P2.7  5|          |34  P1.3        (TA2)
      (XIN)                        P2.6  6|          |33  P1.2        (TA1)         
      (RST/NMI/SBWTDIO)            RST   7|          |32  P1.1        (TA0)      
      (ACLK)                (A0)   P2.0  8|          |31  P1.0      (TACLK/ADC10CLK)
      (TAINCLK/SMCLK)       (A1)   P2.1  9|          |30  P2.4    (A4)    (TA2/VREF+)   
      (TA0)                 (A2)   P2.2 10|          |29  P2.3     (A3)    (TA1/VREF-)
      (UCB0STE/UCA0CLK)     (A5)   P3.0 11|          |28  P3.7    (A7)
      (UCB0SIMO)            (SDA)  P3.1 12|          |27  P3.6    (A6)
      (UCB0SOMI)            (SCL)  P3.2 13|          |26  P3.5  (RXD)    (UCA0SOMI)
      (UCB0CLK/UCA0STE)            P3.3 14|          |25  P3.4    (TXD)    (UCA0SIMO)
                                   AVSS 15|          |24  P4.7        (TBCLK)
                                   AVCC 16|          |23  P4.6    (A15)    (TBOUTH)
      (TB0)                        P4.0 17|          |22  P4.5    (A14)    (TB2)
      (TB1)                        P4.1 18|          |21  P4.4    (A13)    (TB1)
      (TB2)                        P4.2 19|          |20  P4.3    (A12)    (TB0)
                                          +----------+
 
//-------------------------------------------
/* Layout of the Octanis1_EPS board
 
    'ext' stands for a connection outside of the board
    'onb' stands for onboard connection
 
             +
    (A1)     P2.1    1| onb =MCU9  --> I_EXT_PW
    (A2)     P2.2    2| onb =MCU10 --> I_SC
             +
 
             +
    (A6)     P3.6    3| onb =MCU27 --> V_BUS_MS
    (A7)     P3.7    4| onb =MCU28 --> V_BT_MS
             +
 
             +
    (A12)     P4.3    5| ext =MCU20 --> A_EXT1
    (A13)     P4.4    6| ext =MCU21 --> A_EXT2
    (A14)     P4.5    7| ext =MCU22 --> A_EXT3
    (A15)     P4.6    8| ext =MCU23 --> A_EXT4
             +
 
              +
         P1.1     9| onb =MCU32 --> EN_HEAT1
         P1.2    10| onb =MCU33 --> EN_HEAT2
         P1.3    11| onb =MCU34 --> EN_HEAT3
         P1.4    12| onb =MCU35 --> EN_CHG
         P1.5    13| onb =MCU36 --> EN_EXT1
         P1.6    14| onb =MCU37 --> EN_EXT2
         P1.7    15| onb =MCU38 --> EN_EXT3
                  +
 
              +
         TEST    16| ext =MCU1 --> TEST
         RST    17| ext =MCU7 --> RST
                  +
 
              +
     (SDA)    P3.1    18| ext =MCU12 --> I2C_SDA
     (SCL)    P3.2    19| ext =MCU13 --> I2C_SCL
                  +
 
    (not on the actual layout only for Launchpad compatibility)
              +
         P1.0    20| dummy =MCU31 --> RED_LED    
         P4.0    21| dummy =MCU17 --> GREEN_LED
                  +
*/
 
// Pin names based on layout of Octanis1_EPS  
// Edited by Q.Cabrol 22.04.2015
 
/************************************/
//PORT1
static const uint8_t P1_1 = 9;
static const uint8_t P1_2 = 10;
static const uint8_t P1_3 = 11;
static const uint8_t P1_4 = 12;
static const uint8_t P1_5 = 13;
static const uint8_t P1_6 = 14;
static const uint8_t P1_7 = 15;
//aliases
static const uint8_t EN_HEAT1 = 9;
static const uint8_t EN_HEAT2 = 10;
static const uint8_t EN_HEAT3 = 11;
static const uint8_t EN_CHG  = 12;
static const uint8_t EN_EXT1 = 13;
static const uint8_t EN_EXT2 = 14;
static const uint8_t EN_EXT3 = 15;
 
/***********************************/
//PORT2
static const uint8_t P2_1 = 1;
static const uint8_t P2_2 = 2;
//aliases
static const uint8_t I_EXT_PW = 1;
static const uint8_t I_SC = 2;
 
/**********************************/
//PORT3
static const uint8_t P3_1 = 18;
static const uint8_t P3_2 = 19;
static const uint8_t P3_6 = 3;
static const uint8_t P3_7 = 4;
//aliases
static const uint8_t I2C_SDA = 18;
static const uint8_t I2C_SCL = 19;
static const uint8_t V_BUS_MS = 3;
static const uint8_t V_BT_MS = 4;
 
/***********************************/
//PORT4
static const uint8_t P4_3 = 5;
static const uint8_t P4_4 = 6;
static const uint8_t P4_5 = 7;
static const uint8_t P4_6 = 8;
//aliases
static const uint8_t A_EXT1 = 5;
static const uint8_t A_EXT2 = 6;
static const uint8_t A_EXT3 = 7;
static const uint8_t A_EXT4 = 8;
 
/* For LaunchPad compatability */  
static const uint8_t RED_LED = 20;   
static const uint8_t GREEN_LED = 21;
 
//static const uint8_t TEMPSENSOR = 128 + 10; // depends on chip
 
 
/* Edited on 22.04.2015 */
#ifdef ARDUINO_MAIN
const uint16_t port_to_input[] = {
    NOT_A_PORT,
    (uint16_t) &P1IN,
    (uint16_t) &P2IN,
    (uint16_t) &P3IN,
    (uint16_t) &P4IN,
};
 
const uint16_t port_to_output[] = {
    NOT_A_PORT,
    (uint16_t) &P1OUT,
    (uint16_t) &P2OUT,
    (uint16_t) &P3OUT,
    (uint16_t) &P4OUT,
};
 
const uint16_t port_to_dir[] = {
    NOT_A_PORT,
    (uint16_t) &P1DIR,
    (uint16_t) &P2DIR,
    (uint16_t) &P3DIR,
    (uint16_t) &P4DIR,
};
 
const uint16_t port_to_ren[] = {
    NOT_A_PORT,
    (uint16_t) &P1REN,
    (uint16_t) &P2REN,
    (uint16_t) &P3REN,
    (uint16_t) &P4REN,
};
 
const uint16_t port_to_sel0[] = {
    NOT_A_PORT,
    (uint16_t) &P1SEL0,
    (uint16_t) &P2SEL0,
    (uint16_t) &P3SEL0,
    (uint16_t) &P4SEL0,
};
 
const uint16_t port_to_sel1[] = {
    NOT_A_PORT,
    (uint16_t) &P1SEL1,
    (uint16_t) &P2SEL1,
    (uint16_t) &P3SEL1,
    (uint16_t) &P4SEL1,
};
 
//this is actually not compatible with the definitions in Energia.h --> TO BE CORRECTED
//(A bad fix has been done for now, to be changed)
const uint8_t digital_pin_to_timer[] = {
    NOT_ON_TIMER,  /*  0 - pin count starts at 1 */
 
    NOT_ON_TIMER, /*  1 - P2.1 = I_EXT_PW */
    T0A0,           /*  2 - P2.2 = I_SC */
 
    NOT_ON_TIMER,          /*  3 - P3.6 */
    NOT_ON_TIMER,          /*  4 - P3.7 */
    
    T0B0,          /*  5 - P4.3 = A_EXT1 */
    T1B1,          /*  6 - P4.4 = A_EXT2 */
    T2B2,          /*  7 - P4.5 = A_EXT3 */
    NOT_ON_TIMER, /*  8 - P4.6 = A_EXT4 */
 
    T0A0,          /*   9 - P1.1 = EN_HEAT1 */
    T1A1,          /*  10 - P1.2 = EN_HEAT2 */
    T2A2,          /*  11 - P1.3 = EN_HEAT3 */
    NOT_ON_TIMER, /*  12 - P1.4 = EN_CHG */
    T0A0,          /*  13 - P1.5 = EN_EXT1 */
    T1A1,          /*  14 - P1.6 = EN_EXT2 */
    T2A2,          /*  15 - P1.7 = EN_EXT3 */
 
    NOT_ON_TIMER,  /* 16 - RST */
    NOT_ON_TIMER,  /* 17 - TEST */
 
    NOT_ON_TIMER, /* 20 - RED_LED   */
    T0B0,          /* 21 - GREEN_LED */
 
    NOT_ON_TIMER, /* 22 - SS   */
    NOT_ON_TIMER, /* 23 - SCK  */
    NOT_ON_TIMER, /* 24 - RXD   */
    NOT_ON_TIMER, /* 25 - TXD  */
 
};

 
const uint8_t digital_pin_to_port[] = {
    NOT_A_PIN,   /*  0 - pin count starts at 1 */
 
    P2,         /*  1 - P2.1 = I_EXT_PW */
    P2,          /*  2 - P2.2 = I_SC */
 
    P3,          /*  3 - P3.6 = V_BUS_MS */
    P3,          /*  4 - P3.7 = V_BT_MS */
 
    P4,          /*  5 - P4.3 = A_EXT1 */
    P4,          /*  6 - P4.4 = A_EXT2 */
    P4,          /*  7 - P4.5 = A_EXT3 */
    P4,          /*  8 - P4.6 = A_EXT4 */
 
    P1,          /*   9 - P1.1 = EN_HEAT1 */
    P1,          /*  10 - P1.2 = EN_HEAT2 */
    P1,          /*  11 - P1.3 = EN_HEAT3 */
    P1,          /*  12 - P1.4 = EN_CHG */
    P1,          /*  13 - P1.5 = EN_EXT1 */
    P1,          /*  14 - P1.6 = EN_EXT2 */
    P1,          /*  15 - P1.7 = EN_EXT3 */
 
    NOT_A_PIN,   /* 16 - TEST */
    NOT_A_PIN,   /* 17 - RST */
 
    P3,          /* 18 - P3.1 = I2C_SDA */
    P3,          /* 19 - P3.2 = I2C_SCL */
 
    P1,            /* 20 - RED_LED   */
    P4,          /* 21 - GREEN_LED */
 
    P3, /* 22 - P3.0 SS   */
    P3, /* 23 - P3.3 SCK  */
    P3, /* 24 - P3.5 RXD   */
    P3, /* 25 - P3.4 TXD  */
 
};
 
const uint8_t digital_pin_to_bit_mask[] = {
 
    NOT_A_PIN,   /*  0 - pin count starts at 1 */
 
    BV(1), /*  1 - P2.1 = I_EXT_PW */
    BV(2), /*  2 - P2.2 = I_SC */
 
    BV(6), /*  3 - P3.6 = V_BUS_MS */
    BV(7), /*  4 - P3.7 = V_BT_MS */
 
    BV(3), /*  5 - P4.3 = A_EXT1 */
    BV(4), /*  6 - P4.4 = A_EXT2 */
    BV(5), /*  7 - P4.5 = A_EXT3 */
    BV(6), /*  8 - P4.6 = A_EXT4 */
    
    BV(1), /*   9 - P1.1 = EN_HEAT1 */
    BV(2), /*  10 - P1.2 = EN_HEAT2 */
    BV(3), /*  11 - P1.3 = EN_HEAT3 */
    BV(4), /*  12 - P1.4 = EN_CHG */
    BV(5), /*  13 - P1.5 = EN_EXT1 */
    BV(6), /*  14 - P1.6 = EN_EXT2 */
    BV(7), /*  15 - P1.7 = EN_EXT3 */
 
    NOT_A_PIN,   /* 16 - TEST */
    NOT_A_PIN,   /* 17 - RST */
 
    BV(1), /* 18 - P3.1 = I2C_SDA */
    BV(2), /* 19 - P3.2 = I2C_SCL */
 
    BV(0), /* 20 - RED_LED   */
    BV(0), /* 21 - GREEN_LED */
 
    BV(0), /* 22 - SS   */
    BV(3), /* 23 - SCK  */
    BV(5), /* 24 - P3.5 RXD   */
    BV(4), /* 25 - P3.4 TXD  */
 
};
 
const uint32_t digital_pin_to_analog_in[] = {
        NOT_ON_ADC,     /*  dummy   */
 
        1,  /*  1 - P2.1 = I_EXT_PW (A1)*/
    2,  /*  2 - P2.2 = I_SC (A2)*/
    6,  /*  3 - P3.6 = V_BUS_MS (A6)*/
    7,  /*  4 - P3.7 = V_BT_MS (A7)*/
    12, /*  5 - P4.3 = A_EXT1 (A12)*/
    13, /*  6 - P4.4 = A_EXT2 (A13)*/
    14, /*  7 - P4.5 = A_EXT3 (A14)*/
    15, /*  8 - P4.6 = A_EXT4 (A15)*/
 
 
    NOT_ON_ADC,   /*   9 - P1.1 = EN_HEAT1 */
    NOT_ON_ADC,   /*  10 - P1.2 = EN_HEAT2 */
    NOT_ON_ADC,   /*  11 - P1.3 = EN_HEAT3 */
    NOT_ON_ADC,   /*  12 - P1.4 = EN_CHG */
    NOT_ON_ADC,   /*  13 - P1.5 = EN_EXT1 */
    NOT_ON_ADC,   /*  14 - P1.6 = EN_EXT2 */
    NOT_ON_ADC,   /*  15 - P1.7 = EN_EXT3 */
    NOT_ON_ADC,   /* 16 - TEST */
    NOT_ON_ADC,   /* 17 - RST */
    NOT_ON_ADC,   /* 18 - P3.1 = I2C_SDA */
    NOT_ON_ADC,   /* 19 - P3.2 = I2C_SCL */
        NOT_ON_ADC,   /*  20 - RED_LED */
        NOT_ON_ADC,   /*  21 - GREEN_LED */   
    NOT_ON_ADC,   /* 22 - SS   */
    NOT_ON_ADC,   /* 23 - SCK  */     
    NOT_ON_ADC,   /* 24 - P3.5 RXD   */
    NOT_ON_ADC,   /* 25 - P3.4 TXD  */   
};
 
#endif // #ifdef ARDUINO_MAIN
#endif // #ifndef Pins_Energia_h

 

Of course I modified the Board.mk and boards.txt files as well.

A second information I didn't fint is the upload protocol, I assumed:

 

lpmsp430g2744.upload.protocol=tilib

 

Would that work ? Note that I am planning to use a Spi-by-wire upload using only the TEST and RST pins.

 

For know I am getting the following error from the IDE:

 

post-45669-0-10948600-1430077772_thumb.png

 

Thank you in advance for your help

Hoping to read you soon.

 

Link to post
Share on other sites

Hello again,

 

I took time today to revize what was done with the MSP430G2955 and I must say I am a bit confused.

Could you help me get some things clear:

- Must I adapt the memory.x and periph.x files under /hardware/tools/***/ldscripts ?

- I guess I cannot use the msp430g2955.h file in the /hardware/tools/msp430 ... as is and I also need to adapt it

- When I try to include a msp430g2744.h that is an exact copy of the msp430g2955.h provided on the link you shared, I end up with the error

  "error **** USI USCI not available" and "LPM0_bits undeclared"

 

Concerning the monikers in the Energia.h file, my problem is that in the pins_energia.h file the moniker are defined according to the same numerotation that can be found on the datasheet of the related controller (eg. TA[x.y] on the datasheet is declared with the moniker T[x]A[y] in the pins_energia.h file).

However the numerotation of the timers for the msp430g2744 on datasheet is only TA[x] so it is not clear how I should define the timer moniker.

 

Thank you again for your help.

Link to post
Share on other sites
  • 2 weeks later...

For know I am getting the following error from the IDE:

 Hi, just a question, your ide appear as Linux, compilation too on bottom klingom winzz COM1 is reported as communication port, try in first select correct ACM0 or whichever is connected to Launchpad.

 About compilation error, USCI/USI not available, it appear as strange both error instead of EUSCI, are header ok?

 Again on definition both UART are mapped to same pin pair, USART channel use different pin generally upper and lower half of port 3.

 Are you using latest version of Energia?

 I don't have 2744 at hand but I can try code on a 2944 I use on an industrial motor controller.

If you share the files you made I can try see what happen.

Link to post
Share on other sites
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...