This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Segment Error

Expert 1175 points
Other Parts Discussed in Thread: MSP430F5418

Hello,

I am using MSP430F5418 with IAR EW 5.10.

My problem is that when I execute the following code I got junk output in the variables.

#include <msp430.h>
#define STRING(variable,value) static const char (variable[]) @ "myseg" = (value)
#pragma location="myseg"
static const char test_str[] = "0123456";
__data20 static const char *_string_table [] = {
    test_str,
};
__data20 char a, b, c, d;
int main ()
{
    a = _string_table[0][0];
    b = _string_table[0][1];
    c = _string_table[0][2];
    d = _string_table[0][3];
    __no_operation();
}

My expected values in a,b,c,d are '0','1','2','3' respectively.
The segment "myseg" is located at 0x25000. But IAR is displaying junk values.
But when I compiled it using the "Large data model" it is giving the correct values.
But I can't use it. But I can use "Medium data model".

I think the problem is because the address is above FFFF.
So How can I refer a location which is at the upper memory?


Thanks.

 

  • The __data20 prefix creates an array of 20bit pointers. But test_str is a 16 bit address (even if you manually move it into myseg).
    So when you access the elements, you're getting only the lower 16 bit form the string address and access the wrong memory location.

    I'm not sure how you have to define test_str so it refers to a 20 bit address. maybe putting _data20 before it will help.

    Note that the compiler will create a virtual pointer variable "const char test_str" (whcih is not stored with the program, because of its constant value). But it is a 16 bit pointer/value. Maybe prefixing it with __data20 will solve the problem.
    This is proprietary compiler stuff and not part of any C standard, so I can only guess.

  • Thank you replying...

     

**Attention** This is a public forum