This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#pragma STRING(XDATA) fatal-error

I am having the problem that my program now uses 32kb which means the memory is full.

void print(char *x)
{
    while(*x) {
        SerialWrite(*x++);}
}
SerialWrite looks like:

void SerialWrite(unsigned char c)

    {
        while(tx_buffer_size>250);
        ES=0;
        tx_buffer_size++;
        if (tx_buffer_empty == 0){
            txBuffer[tx_in++] = c;}
        else {
            tx_buffer_empty = 0;
            SBUF = c;}
        ES=1;
    }
//I call the print function with a string text as arguement like:

print("Hello World");


I only used 2.2kb of my 32kb external memory so my conclusion is too move "Hello World" to the external memory instead of having it hardcoded in the main program.

Unfortunately my attempt did not help

I tried:

char xdata msg1[] = "Hello World";
print(msg1);

This did increase the external memory size by 12 which is correct as the string contains 11 chars + the null. But the program memory also increased by 3. I tried different string lengths but the program memory keeps increasing by 3 bytes.

Than I added the 'const' keyword in front of the char but this had no effect

Following other's advice I did:

#pragma STRING (XDATA)


On top of the program
This is propably the correct solution only it gives me a fatal error:

C51 FATAL-ERROR - ACTION: PARSING INVOKE-/#PRAGMA-LINE LINE: #pragma STRING(XDATA) ERROR: INCOMPATIBLE CONTROL C51 TERMINATED.

I have read:
http://www.keil.com/support/man/docs/c51/c51_le_const.htm http://www.keil.com/support/man/docs/c51/c51_string.htm

How can I solve this problem?

  • Putting the string in external memory isn't going to help. It can actually make things worse.

    Why? The string itself, because it exists in RAM, has to be initialized by something and that something is code. The code will copy the string from CODE space to RAM. This copying happens at startup.

    So you need to look elsewhere for places to remove redundant or duplicate stuff.

  • What's probably killing your ROM consumption (and definitely some performance) here is the use of a generic pointer as the argument to your print() function. Putting string literals anywhere else but CODE memory is just a waste of RAM (for the non-CODE copy) and start-up time (for making the initial copy from code to RAM before the start of main()).

    So no, you should not put your string in XDATA --- it should be marked code so it goes into CODE. Next you should think hard if your print() function really needs a generic pointer argument. A function using a memory-class-specific pointer argument like

    print(char code *);
    


    should be both smaller and faster by a considerable margin.