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

Array initialization in ext memory

Hi! i have use p89c669 microcontroller and am29f040b [512 kb] flash.When i using the external code memory i can't initialize the array that have more than 4 values.if i initialize more than that the program will not be executed.if i comment the array the program was executed.the code was

const char red [256] = {0x00,0x00...0x00,0x00};

please help me!

regrads,
K.T.Venkatesan.

Parents Reply Children
  • "in that case can we use two sperate arrays that each have 60kb"

    I think Erik is saying that the issue is not the actual size of the array, but that it crosses a 64K address boundary...?

  • Erik is saying that the issue is not the actual size of the array, but that it crosses a 64K address boundary

  • "the program will not be executed"

    You still need to provide more detail than that!

  • I have experience of the product and I might be able to help more than some other posters here; but only if you give more details.

    I guess you are using banking for code space? also for data space?

    If so, then what are the banking constraints?

  • Hi! Actualy i use the p89c669 microcontroller and amd 512 kb flash.now i had write a program for led blinking.after that program was loaded in the flash [external code memory] and the EA pin in the microcontroller was grounded.when i power on the target pcb the led was blinking as the per code.when i add an array array [76800] ={0x00,..0xfd}; in code the compiler give the error error c249:'!':SEGMENT TOO LARGE .

    Last time i use the array as array[255] = {0x00,...0xff}; and load it in target board the leds was not blinking.then i change the array format as extern unsigned char const far array [256] ={0x00,...0xff} the problem was solved.

    Regards,
    K.T.Venkatesan.

  • I think a close inspection of the linker map file would be appropriate.

  • extern unsigned char const far array [256] ={0x00,...0xff}
    

    You can't have an initialiser on an extern declaration, can you?

  • Why use the 'far'? I thought that was used on cores that support 24 bit addressing.

    Are you beyond 64K? Don't cross the boundary!

    Check the map file.

  • Why use the 'far'? I thought that was used on cores that support 24 bit addressing.
    which the (soon to be discontinued) '669 does

    Erik

  • You can't have an initialiser on an extern declaration, can you?

    Yes. Well, yes on a "definition" but not on a "declaration", to be pedantic, but the syntax is legal, and from the code snippets above you can't really tell whether it was meant to be a declaration. The initializer makes it a definition, and you'll get some sort of "multiply defined" diagnostic message if the syntax shows up in a .h file included in several .c files (for example).

    From the ANSI C89 spec:

    3.7.2 External object definitions
    
    Semantics
    
       If the declaration of an identifier for an object has file scope
    and an initializer, the declaration is an external definition for the
    identifier.
    
       A declaration of an identifier for an object that has file scope
    without an initializer, and without a storage-class specifier or with
    the storage-class specifier static , constitutes a tentative
    definition.  If a translation unit contains one or more tentative
    definitions for an identifier, and the translation unit contains no
    external definition for that identifier, then the behavior is exactly
    as if the translation unit contains a file scope declaration of that
    identifier, with the composite type as of the end of the translation
    unit, with an initializer equal to 0.
    
       If the declaration of an identifier for an object is a tentative
    definition and has internal linkage, the declared type shall not be an
    incomplete type.
    
    Examples
    
             int i1 = 1;          /*  definition, external linkage */
             static int i2 = 2;   /*  definition, internal linkage */
             extern int i3 = 3;   /*  definition, external linkage */
             int i4;              /*  tentative definition, external linkage */
             static int i5;       /*  tentative definition, internal linkage */
    
             int i1;   /*  valid tentative definition, refers to previous */
             int i2;   /*  $3.1.2.2 renders undefined, linkage disagreement */
             int i3;   /*  valid tentative definition, refers to previous */
             int i4;   /*  valid tentative definition, refers to previous */
             int i5;   /*  $3.1.2.2 renders undefined, linkage disagreement */
    
    
    
             extern int i1; /* refers to previous, whose linkage is external */
             extern int i2; /* refers to previous, whose linkage is internal */
             extern int i3; /* refers to previous, whose linkage is external */
             extern int i4; /* refers to previous, whose linkage is external */
             extern int i5; /* refers to previous, whose linkage is internal */
    
    

    Since I'm not a fan of programming languages doing much (if anything) implicitly, I prefer always to repeat the extern/static on the definition as well as the declarations. This at least earns me a diagnostic message when an object changes from external to internal, and serves as a useful reminder that "this object is accessible from outside", and keeps the syntax parallel with the "static" case.

  • Yes!i can initialize the array with extern
    i see this in keil web site http://www.keil.com/support/docs/3128.htm

    K.T.V

  • Erik is saying that the issue is not the actual size of the array, but that it crosses a 64K address boundary then, then only way is seperate the 512kb into 8 blocks, am i right?

  • The whole point of that article is that you do the initialisation in assembler - not in 'C'!

  • Have you examined the link map file ?