Jump to content
43oh

Recommended Posts

Hi all,

 

I am new to the forum to MCUs and to energia.

 

I have the TI Launchpad MSP430G2553 with a maximum of 16,384 bytes of available ram as far as I understand.

 

The program below compiles at 3,061 bytes if I use the data type "byte" for my large array, but apparently I am missing 72 bytes of space if I use the data type "int" which if I understand things well is only twice the size of a byte.

 

Can someone explain to me why I get this error?

 

P.S: Some variables are not yet used I know, but they will be

int dot   = 0;
int dash  = 1;
int empty = -1;
int unit  = 50;
int dot_unit = 1;
int dash_unit = 3;
int letter_space = 1;
int letters_space = 3;
int words_space = 7;

#define LED RED_LED

/*
Alphanumeric structure from A-Z and 0-9.
Values in the last column correspond to
decimal values for each ASCII character.
*/
byte alpha_num[36][6] = {
 {0,1,-1,-1,-1,65}, 
 {1,0,0,0,-1,66},
 {1,0,1,0,-1,67},
 {1,0,0,-1,-1,68},
 {0,-1,-1,-1,-1,69},
 {0,0,1,0,-1,70},
 {1,1,0,-1,-1,71},
 {0,0,0,0,-1,72},
 {0,0,-1,-1,-1,73},
 {0,1,1,1,-1,74},
 {1,0,1,-1,-1,75},
 {0,1,0,0,-1,76},
 {1,1,-1,-1,-1,77},
 {1,0,-1,-1,-1,78},
 {1,1,1,-1,-1,79},
 {0,1,1,0,-1,80},
 {1,1,0,1,-1,81},
 {0,1,0,-1,-1,82},
 {0,0,0,-1,-1,83},
 {1,-1,-1,-1,-1,84},
 {0,0,1,-1,-1,85},
 {0,0,0,1,-1,86},
 {0,1,1,-1,-1,87},
 {1,0,0,1,-1,88},
 {1,0,1,1,-1,89},
 {1,1,0,0,-1,90},
 {1,1,1,1,1,48},
 {0,1,1,1,1,49},
 {0,0,1,1,1,50},
 {0,0,0,1,1,51},
 {0,0,0,0,1,52},
 {0,0,0,0,0,53},
 {1,0,0,0,0,54},
 {1,1,0,0,0,55},
 {1,1,1,0,0,56},
 {1,1,1,1,0,57}
};

void setup() {
  
  pinMode(LED, OUTPUT);
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 

  // prints title with ending line break 
  Serial.println("Alphanumeric ASCII table"); 
}

void loop()
{
	print_table_values();
}

void print_table_values() 
{
        digitalWrite(LED, HIGH);
	for (int i = 0; i < 36; i++)
	{
		Serial.print(alpha_num[i][5]); 
		Serial.print(" is: ");
		Serial.write(alpha_num[i][5]);
		Serial.println("");
	}
        digitalWrite(LED, LOW);
	while(true) { 
		continue;
	}
}

If I use "int" as the array's data type I get the following error

[C:\energia\hardware\tools\msp430\bin\msp430-g++, -c, -Os, -w, -ffunction-sections, -fdata-sections, -mmcu=msp430g2553, -DF_CPU=16000000L, -MMD, -DARDUINO=101, -DENERGIA=17, -IC:\energia\hardware\msp430\cores\msp430, -IC:\energia\hardware\msp430\variants\launchpad, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\morse_ino.cpp, -o, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\morse_ino.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\atof.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\dtostrf.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\itoa.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\random.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\twi.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\twi_sw.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\usci_isr_handler.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\WInterrupts.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\wiring.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\wiring_analog.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\wiring_digital.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\wiring_pulse.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\wiring_shift.c.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\HardwareSerial.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\IPAddress.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\MACAddress.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\main.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\new.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\Print.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\Stream.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\TimerSerial.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\Tone.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\Wire.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\WMath.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-ar, rcs, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\WString.cpp.o]
[C:\energia\hardware\tools\msp430\bin\msp430-gcc, -Os, -Wl,-gc-sections,-u,main, -mmcu=msp430g2553, -o, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\morse_ino.cpp.elf, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\morse_ino.cpp.o, C:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp\core.a, -LC:\Users\xavier\AppData\Local\Temp\build7733100553055358358.tmp, -lm]
c:/energia/hardware/tools/msp430/bin/../lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld.exe: morse_ino.cpp.elf section `.bss' will not fit in region `ram'
c:/energia/hardware/tools/msp430/bin/../lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld.exe: region `ram' overflowed by 72 bytes
collect2: ld returned 1 exit status

This does not make sense to me.

Regards

X

Link to post
Share on other sites

To expand on the answer by @@terjeio

 

The const keyword tells the compiler, that a variable is a constant. This allows the compiler to store the variable in read-only memory (ROM, i.e. Flash) instead of read/write aka random access memory (RAM).

 

Changing the line

byte alpha_num[36][6] = {

to

const byte alpha_num[36][6] = {

should do the trick.

 

You can do the same thing with the int variables you declare at the top.

Link to post
Share on other sites

Sorry for beeing a bit terse. I will add another tip - storing an array of strings in flash is not as straigthforward, this is what I had to do:

char const *const command[] = {
	"first",
	"second",
	"third"
}

I had to do some research to figure that out - a constant array of pointers to constant strings (if I read it correctly now - still learning...)

Link to post
Share on other sites

I'm pretty sure that the first const goes before char.

 

Either way works (char const * const is equivalent to const char * const). That cdecl site only accepts the latter, however.

 

PS: As a string literal ("xyz") is already a const char* (i.e. stored in ROM), I don't think the second const is needed. But I'd have to test that to be sure.

 

The const after the * is the one that makes the pointers in the array const. You could get away with omitting the first const in this case, but I tend to just use both.

Link to post
Share on other sites

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...