EmbDev.net

Forum: ARM programming with GCC/GNU tools Linker woes, const arrays in Flash


Author: Toni Räsänen (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello,

I'm using Yagarto, with version info "arm-elf-gcc (GCC) 4.3.2", with 
AT91SAM7X128 chip.

I've been working with USB device port, and although it works now, the 
linker is giving me trouble. I am running the entire application from 
flash, without remapping (i.e. base address 0x0000'0000) and SRAM starts 
from 0x0020'0000. Pretty normal bootloader config.

USB code itself is taken from the Atmel's example cdc (serial converter) 
project and seems to be fine when run from SRAM.

After linking to Flash, I noticed that linker had allocated few bytes to 
SRAM region (copy-paste from resulting intel hex file):

...
:020000040020DA
:08000000343A0000383A000018
...

Guessing that this was some USB array, I found the addresses mentioned 
from map file:

...
0x00003a34                languageIdStringDescriptor
...
0x00003a38                productStringDescriptor
...

These are referred from a single array (stringDescriptors), and this 
array in turn is referred from a struct (all relevant stuff below).

So, it seemed that I had missed an "const" somewhere. But no, it's 
there, and to me it seems that all consts needed are there. Is there 
something I have missed, or could this be a bug in compiler/linker? 
(trouble casting   *array[] to **array or something...)


...
typedef struct {
    const USBDeviceDescriptor *pFsDevice;                   /// Pointer 
to the full-speed device descriptor.
    const USBConfigurationDescriptor *pFsConfiguration;     /// Pointer 
to the full-speed configuration descriptor.
    const USBDeviceQualifierDescriptor *pFsQualifier;       /// Pointer 
to the full-speed qualifier descriptor.
    const USBConfigurationDescriptor *pFsOtherSpeed;        /// Pointer 
to the full-speed other speed configuration descriptor.
    const USBDeviceDescriptor *pHsDevice;                   /// Pointer 
to the high-speed device descriptor.
    const USBConfigurationDescriptor *pHsConfiguration;     /// Pointer 
to the high-speed configuration descriptor.
    const USBDeviceQualifierDescriptor *pHsQualifier;       /// Pointer 
to the high-speed qualifier descriptor.
    const USBConfigurationDescriptor *pHsOtherSpeed;        /// Pointer 
to the high-speed other speed configuration descriptor.
    const unsigned char **pStrings;                         /// Pointer 
to the list of string descriptors.
    unsigned char numStrings;                               /// Number 
of string descriptors in list.
} USBDDriverDescriptors;

#define USBStringDescriptor_ENGLISH_US          0x09, 0x04
#define USBStringDescriptor_LENGTH(length)      ((length) * 2 + 2)
#define USBStringDescriptor_UNICODE(ascii)      (ascii), 0

// Language ID string descriptor
const unsigned char languageIdStringDescriptor[] = {
    USBStringDescriptor_LENGTH(1),
    USBGenericDescriptor_STRING,
    USBStringDescriptor_ENGLISH_US
};

// Product string descriptor
const unsigned char productStringDescriptor[] = {
    USBStringDescriptor_LENGTH(12),
    USBGenericDescriptor_STRING,
    USBStringDescriptor_UNICODE('M'),
    USBStringDescriptor_UNICODE('y'),
    USBStringDescriptor_UNICODE('D'),
    USBStringDescriptor_UNICODE('e'),
    USBStringDescriptor_UNICODE('v'),
    USBStringDescriptor_UNICODE('i'),
    USBStringDescriptor_UNICODE('c'),
    USBStringDescriptor_UNICODE('e'),
    USBStringDescriptor_UNICODE('1'),
    USBStringDescriptor_UNICODE('2'),
    USBStringDescriptor_UNICODE('8'),
    USBStringDescriptor_UNICODE('x')
};

/// List of string descriptors used by the device
const unsigned char *stringDescriptors[] = {
    languageIdStringDescriptor,
    productStringDescriptor
};

/// List of standard descriptors for the serial driver.
const USBDDriverDescriptors cdcdSerialDriverDescriptors = {
    &deviceDescriptor,
    (USBConfigurationDescriptor *) &(configurationDescriptors),
    0, // No full-speed device qualifier descriptor
    0, // No full-speed other speed configuration
    0, // No high-speed device descriptor
    0, // No high-speed configuration descriptor
    0, // No high-speed device qualifier descriptor
    0, // No high-speed other speed configuration descriptor
    stringDescriptors,
    2 // 2 string descriptors in list
};

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Difficult to analyse with the given information. Please attach the 
complete map-file to a message. A minimal example with all needed files 
for a "make all" to reproduce the issue would be fine.

Author: Toni Räsänen (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
The attached file is a minimal project that has this behavior (including 
map file from test compile) using the same structure definitions.

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Please try this (mind the 2nd const):
//...
const unsigned char *const stringDescriptors[] = {
    languageIdStringDescriptor,
    productStringDescriptor,
};
//...

Author: Toni Räsänen (Guest)
Posted on:

Rate this post
0 useful
not useful
Thanks, that did the trick, although the seconds const somehow seems so 
"wrong" to my eye.

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful

Author: Toni Räsänen (Guest)
Posted on:

Rate this post
0 useful
not useful
Yes, makes sense, when I now think of it. I just never had encountered 
this kind of "const to const" situation before.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.