0
\$\begingroup\$

Using Code Composer Studio and MSP430F5438A I get that error when compiling, but if I randomly delete some lines of the code, it will work fine. The problem is that I have not finished yet and there is more coming! What can I do?

EDIT: The whole code is:

#include <msp430.h>
#include "hal_lcd.h"
#include "string.h"
#include "math.h"
char data;
int brcnfg=0, dbcnfg=0, prtycnfg=0, sbcnfg=0, getfile=0,sendfile=0, print=0, index=0,
    srescnfg=0,trescnfg=0, FrameLength=400, MatrixLength=200;

// Function prototypes
void BaudRateConfig(char data);
void DataBitsConfig(char data);
void ParityBitConfig(char data);
void StopBitConfig(char data);
/////////////////////////////////// Flash
char value;                                 // 8-bit value to write to seg C
void write_SegC(char value);
void read_SegC(char data);
void copy_C2D(void);
void erase();
void sqr();
void circ();
unsigned char * Flash_ptr = (unsigned char *) 0x10000;           // Initialize Flash pointer
long size[]={80000,80000,0,0,0,0,0,0,0};                                 // Files sizes
/////////////////////////////////// end Flash
int main(void)
{   WDTCTL = WDTPW | WDTHOLD;                         // Stop watchdog timer
P5SEL |= 0xC0;                                    // P3.4,5 = USCI_A0 TXD/RXD
UCA1CTL1 |= UCSWRST;
UCA1CTL0 |= UCMODE_0;
UCA1CTL1 = UCSSEL_1;                              // CLK = ACLK

UCA1CTL0 |= UC7BIT;                               // 7-bit characters
UCA1CTL0 &= ~UCSPB;                               // 1 StopBits
UCA1BR0 = 0x03;                                   // 32k/9600=3.41
UCA1BR1 = 0x00;                                   //
UCA1MCTL = UCBRS_3+UCBRF_0;                       // Modulation

UCA1CTL1 &= ~UCSWRST;                             // Release USCI state machine
UCA1IE |= UCRXIE;                                 // Enable USCI_A0 RX interrupt

halLcdInit();
halLcdClearScreen();



//   erase();

// Write the Square Path
sqr();

// Write the Circular Path
circ();

Flash_ptr = (unsigned char *) 0x10000;
FCTL3 = FWKEY;                            // Clear Lock bit

FCTL1 = FWKEY+ERASE;                      // Set Erase bit
*(unsigned int *)Flash_ptr = 0;           // Dummy write to erase Flash seg
while(!(WAIT & FCTL3));

FCTL3 = FWKEY+LOCK;                       // Set LOCK bit


__bis_SR_register(LPM0_bits + GIE);
__no_operation();
}

/*
 * main.c
 */

//=====================================================================================
//                          +++  USCI_A0_Interupt  +++
//=====================================================================================
#pragma vector = USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
if(__even_in_range(UCA1IV,18) == 0x02){          // Vector 2 - RXIFG
    data = UCA1RXBUF;
    // check if command
    if (data == '*')            // BaudRate Config.
        brcnfg=1;
    else if (data == '^')       // DataBits Config.
        dbcnfg=1;
    else if (data == '$')       // ParityBit Config.
        prtycnfg=1;
    else if (data == '#')       // StopBit Config.
        sbcnfg=1;
    else if (data == '%' || data == '{'){       // Get File from PC
        getfile=1;
        if(data=='{')
            print=1;
    }
    else if (data == '@'){      // EOF
        while(!(UCA1IFG & UCTXIFG));
        UCA1TXBUF='@';      // Send Acknowledge that the file has been received
        index++;
        getfile=0;   // Exit the file transfer mode
        print=0;
    }
    else if (data=='&'){ // Send File to PC
        sendfile=1;
    }
    else if(data=='<'){ // Finished sending the file to PC
        while(UCA1STAT & 0x01);
        halLcdPrint("PC: The file has been received",'2');
        halLcdScrollRow(1);
    }
    else if(data=='>') // Change square resolution
        srescnfg=1;
    else if(data=='}') // Change time resolution
        trescnfg=1;
    else{       // implement the command or just do echo
        if(brcnfg){            // BaudRate Config.
            while(UCA1STAT & 0x01);
            UCA1TXBUF='*';  // Send Acknowledge to PC
            while(UCA1STAT & 0x01);
            BaudRateConfig(data);
            brcnfg=0;
        }
        else if(dbcnfg){       // DataBit Config.
            while(UCA1STAT & 0x01);
            UCA1TXBUF='^';  // Send Acknowledge to PC
            while(UCA1STAT & 0x01);
            DataBitsConfig(data);
            dbcnfg=0;
        }
        else if(prtycnfg){     // Parity Bit Config.
            while(UCA1STAT & 0x01);
            UCA1TXBUF='$';  // Send Acknowledge to PC
            while(UCA1STAT & 0x01);
            ParityBitConfig(data);
            prtycnfg=0;
        }
        else if(sbcnfg){       // Stop Bit Config.
            while(UCA1STAT & 0x01);
            UCA1TXBUF='#';  // Send Acknowledge to PC
            while(UCA1STAT & 0x01);
            StopBitConfig(data);
            sbcnfg=0;
        }
        else if (getfile){  // Write to Flash
            /*while(!(UCA1IFG & UCTXIFG));
            UCA1TXBUF=data;
            if(print)
                halLcdPrint(data,'2');*/
            while(UCA1STAT & 0x01);    //   ???????
            write_SegC(data);
        }
        else if (sendfile)
            read_SegC(data);
        else if (srescnfg){  // srescnfg=SquareResolutionConfiguration // TEMPORARLY !!!!!!!!!!!!!!!!!!
            MatrixLength=sqrt(FrameLength*FrameLength/data);
            srescnfg=0;
            while(!(UCA1IFG & UCTXIFG));
            UCA1TXBUF='>'; // Send Ack for changing square resolution
        }
        else if (trescnfg){  // trescnfg=TimeResolutionConfiguration


            while(!(UCA1IFG & UCTXIFG));
            UCA1TXBUF='}'; // Send Ack for changing time resolution
        }
        else{
            /*while(UCA1STAT & 0x01);
            halLcdPrintLine("MCU: ",'2');*/    // Chat
            while(!(UCA1IFG & UCTXIFG));
            UCA1TXBUF=data;
        }
    }
}
}
void BaudRateConfig(char data){
if (data=='9'){  // 9600 BaudRate Configurations
    UCA1BR0 = 3;
    UCA1BR1 = 0;
    UCA1MCTL = UCBRS_3+UCBRF_0;
}
else if (data=='4'){  // 4800 BaudRate Configurations
    UCA1BR0 = 6;
    UCA1BR1 = 0;
    UCA1MCTL = UCBRS_7+UCBRF_0;
}
else if (data=='2'){  // 2400 BaudRate Configurations
    UCA1BR0 = 13;
    UCA1BR1 = 0;
    UCA1MCTL = UCBRS_6+UCBRF_0;
}
else if (data=='1'){  // 1200 BaudRate Configurations
    UCA1BR0 = 27;
    UCA1BR1 = 0;
    UCA1MCTL = UCBRS_2+UCBRF_0;
}
}
void DataBitsConfig(char data){
    if(data=='8')
        UCA1CTL0 &= ~UC7BIT;        //8-bit characters
    else if (data=='7')
        UCA1CTL0 |= UC7BIT;         //7-bit characters
}
void ParityBitConfig(char data){
    if(data=='N')
        UCA1CTL0 &= ~UCPEN;                 // Parity Disable
    else if(data=='E')
        UCA1CTL0 |= UCPEN + UCPAR;         // Parity Enable
    else if(data=='O'){
           UCA1CTL0 |= UCPEN;               // Parity Enable
           UCA1CTL0 &= ~UCPAR;
    }
}
void StopBitConfig(char data){
    if(data=='O')
        UCA1CTL0 &= ~UCSPB;             // 1 StopBits
    else if(data=='T')
        UCA1CTL0 |= UCSPB;              // 2 StopBits
}

//------------------------------------------------------------------------------
// Input = value, holds value to write to Seg C
//------------------------------------------------------------------------------
void write_SegC(char value)
{
  //__disable_interrupt();                  // 5xx Workaround: Disable global
                                            // interrupt while erasing. Re-Enable
                                            // GIE if needed

  FCTL3 = FWKEY;                            // Clear Lock bit

  FCTL1 = FWKEY+WRT;                        // Set WRT bit for write operation
  *Flash_ptr++ = data;                      // Write value to flash
  size[index]++;                            // Calculating the file size
  while(!(WAIT & FCTL3));

  FCTL1 = FWKEY;                            // Clear WRT bit
  FCTL3 = FWKEY+LOCK;                       // Set LOCK bit
}

void read_SegC(char data)
{
    char temp=data;
    unsigned char * Flash_ptrTemp;
    // Square Path
    if(temp==0)
    Flash_ptrTemp = (unsigned char *) 0x10000;
// Circular Path
else if(temp==1)
    Flash_ptrTemp = (unsigned char *) 0x23880;
else{
    Flash_ptrTemp = (unsigned char *) 0x27100;
    // Choose the right file to send to PC
    char k='0';
    while(temp!='2'){
        Flash_ptrTemp = Flash_ptrTemp + size[k-48];
        k++;
        temp--;
    }
}
long i;
// Send the file by sending char-by-char
for(i = 0; i < size[data-48]; i++)
{
    while(!(WAIT & FCTL3));
    while(!(UCA1IFG & UCTXIFG));
    UCA1TXBUF=*Flash_ptrTemp++;
    while(!(WAIT & FCTL3));
}
// Stop sending file mode
sendfile=0;
// Send EOF
while(!(UCA1IFG & UCTXIFG));
UCA1TXBUF='&';
}
void erase(){
    while(Flash_ptr < (unsigned char *)0x40000){
    FCTL3 = FWKEY;                            // Clear Lock bit

    FCTL1 = FWKEY+ERASE;                      // Set Erase bit
    *(unsigned int *)Flash_ptr = 0;           // Dummy write to erase Flash seg
    while(!(WAIT & FCTL3));

    FCTL3 = FWKEY+LOCK;                       // Set LOCK bit
    Flash_ptr += 0x200;
    }
    Flash_ptr = (unsigned char *) 0x10000;
}
void sqr(){
    unsigned char counter='0';
    unsigned char sqrMatrix[MatrixLength][2*MatrixLength];
    // First line
    int j;
    for(j=MatrixLength; j>5;j=j-2){
        sqrMatrix[counter][j]='@'; // 64 Decimal
        sqrMatrix[counter][j+1]=counter;
        counter++;
    }
    // Obstacle
    sqrMatrix[counter][5]='A'; // 65 Decimal
    sqrMatrix[counter][6]=counter;
    counter++;
    // Start the second line ;)
for(j=7;counter<255;j=j+2){
    sqrMatrix[counter][j]='@'; // 64 Decimal
    sqrMatrix[counter][j+1]=counter;
    counter++;
}

// The counter has reached 255->start filling also in the MSB bit.
for(j=0; j<MatrixLength;j=j+2){
    unsigned char MSB=counter/255;
    unsigned char LSB=counter%255;
    sqrMatrix[counter][j]='@'+MSB; // 64 Decimal
    sqrMatrix[counter][j+1]=LSB;
    counter++;
}
unsigned char backCount=counter;
// Obstacle
sqrMatrix[backCount][2*MatrixLength/2]='A'; // 65 Decimal
sqrMatrix[backCount][2*MatrixLength/2]=counter;
counter++;
backCount--;
// draw the 3rd line
for(j=(2*MatrixLength/2)+2;j<2*MatrixLength-5;j=j+2){
    unsigned char MSB=counter/255;
    unsigned char LSB=counter%255;
    sqrMatrix[backCount][j]='@'+MSB; // 64 Decimal
    sqrMatrix[backCount][j+1]=LSB;
    counter++;
    backCount--;
}
// Obstacle
sqrMatrix[backCount][2*MatrixLength/2-6]='A'; // 65 Decimal
sqrMatrix[backCount][2*MatrixLength/2-5]=counter;
backCount--;
// draw the last line
for(j=2*MatrixLength-7;j>2*MatrixLength/2;j=j-2){
    unsigned char MSB=counter/255;
    unsigned char LSB=counter%255;
    sqrMatrix[backCount][j]='@'+MSB; // 64 Decimal
    sqrMatrix[backCount][j+1]=LSB;
    counter++;
    backCount--;
}
int i;
for(i=0;i<MatrixLength;i++)
    for(j=0;j<MatrixLength*2;j++)
        write_SegC(sqrMatrix[i][j]);
}
void circ(){

}
\$\endgroup\$
  • 2
    \$\begingroup\$ It'd probably help to describe what features you're using or post code if it's small enough. Are you using things like floating point and stdio functions like printf etc? I'm not sure how to enable it under CCS but they'd almost certainly be a linker map that you can enable to see how much memory is being used by various parts of the code. \$\endgroup\$ – PeterJ Sep 12 '14 at 6:45
  • \$\begingroup\$ Try enabling optimizations, it will reduce the program size. \$\endgroup\$ – Mike Sep 12 '14 at 6:50
  • \$\begingroup\$ @Mike Where? PeterJ yeah i'm using long arrays and lcdPrints etc.. \$\endgroup\$ – Renya Karasuma Sep 12 '14 at 6:52
  • \$\begingroup\$ I expect that if you ever get the code size down, then you will have other problems. This (unsigned char sqrMatrix[MatrixLength][2*MatrixLength];) wants 80000 bytes but your processor only has 16K of ram (at least according to the information I could find about the MSP430F5438A) \$\endgroup\$ – JRE Sep 12 '14 at 9:22
3
\$\begingroup\$

Do you use a size restricted version of CCS?

If not, it appears you're running out of flash space on your uC. There are versions of your MSP family which go up to 512kbytes of Flash. Also, you might want to check if you are using large datastructures. I am not that familiar with CCS but I'm quite sure there is some way to see which parts of your program take up that much space (when using GCC the file is called MAP). Look for the largest sized object and try to reduce their size.

\$\endgroup\$
  • \$\begingroup\$ I dont think i'm running out of flash, the flash is 256K and I didn't even start writing to it! as I said, when removing some arbitary lines, there will be no compilation error, which means its not an issue of using long variables or something, I assume its a CCS problem tho mine is up to date I guess (Version 7.4.10 [C6000])! \$\endgroup\$ – Renya Karasuma Sep 12 '14 at 7:42
  • 1
    \$\begingroup\$ What do you mean by "your didn't even start writing to it"? The flash is where your program code is stored, not some arbitrary area. You are not looking for long variables but e.g. for large readonly arrays. \$\endgroup\$ – Tom L. Sep 12 '14 at 8:46
  • \$\begingroup\$ i'll post the whole code since I dont understand you.. \$\endgroup\$ – Renya Karasuma Sep 12 '14 at 9:00
  • \$\begingroup\$ Could you please also post your MAP file. I think that you might have an array which gets really large. CCS wants to store the initializer in flash, is unable to do so and quits. \$\endgroup\$ – Tom L. Sep 12 '14 at 11:56
  • 1
    \$\begingroup\$ what is "MAP"? how can I get it for you ? \$\endgroup\$ – Renya Karasuma Sep 12 '14 at 12:01

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.