View previous topic :: View next topic |
Author |
Message |
Fabri
Joined: 22 Aug 2005 Posts: 275
|
Error Not enough RAM for all variables |
Posted: Wed Mar 03, 2021 10:10 am |
|
|
Hello,
I tried to use text table in CCS I already use with XC8 compiler. This because my string isn't length fixed. Below example of structure of table. In production firmware I have 5 tables with total each composed of 40 text string.
When I compile with CCS V5.077 I have compiler error:
Error Not enough RAM for all variables
Why happens so ? I don't use RAM for tables.
Thanks for help !
Code: |
cont int *tab_msg_EN[5]{
"11111111\0",
"22222222\0",
"333\0",
"44444\0",
"5555\0",
};
|
|
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Mar 03, 2021 11:37 am |
|
|
I solved getting back and use array of strings without pointer. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 04, 2021 12:56 am |
|
|
Here is how to make variable length constant strings work. The program
below displays the following output in MPLAB vs. 8.92 simulator. This was
tested with CCS vs. 5.103. See the CCS manual on page 49.
Quote: |
11111111
22222222
333
44444
5555
|
Test program:
Code: |
#include <18F46K22.h>
#use delay(internal=4M)
#use rs232(baud=9600, UART1, ERRORS)
const int8 tab_msg_EN[][*] = {
"11111111\0",
"22222222\0",
"333\0",
"44444\0",
"5555\0"
};
//======================================
void main(void)
{
int8 i;
for(i=0; i<5; i++)
{
printf("%s \r", tab_msg_EN[i]);
}
while(TRUE);
}
|
Also, you don't have to put \0 at the end of your strings. The compiler
automatically puts a \0 at the end of a quoted string. So you can do it
like this and it will still work:
Code: |
const int8 tab_msg_EN[][*] = {
"11111111",
"22222222",
"333",
"44444",
"5555"
};
|
|
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Thu Mar 04, 2021 1:53 am |
|
|
Your help is greatly appreciated. I'm going to work around and test it.
Regards, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu Mar 04, 2021 2:04 am |
|
|
What was originally posted, would work without the problem, with one
simple change.
Just add:
#device PASS_STRINGS=IN_RAM
just up after the processor definitions.
The 'reason' for the problem is simple. On the PIC, the ROM memory
space is a separate address space to the RAM. So trying to declare an array
of pointers results in addresses that are way outside the RAM area.
The PASS_STRINGS option makes the compiler 'virtualise' pointers to the
ROM. This is the default behaviour in XC8.
So:
(Using PCM Programmers example)
Code: |
#include <18F46K22.h>
#device PASS_STRINGS=IN_RAM
#use delay(internal=4M)
#use rs232(baud=9600, UART1, ERRORS)
const int8 * tab_msg_EN[] = {
"11111111",
"22222222",
"333",
"44444",
"5555"
};
//======================================
void main(void)
{
int8 i;
for(i=0; i<5; i++)
{
printf("%s \r", tab_msg_EN[i]);
}
while(TRUE);
}
|
Will merrily work. |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Thu Mar 04, 2021 2:11 am |
|
|
Very interesting Ttelmah.
Thanks |
|
|
|