EmbDev.net

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


von Toni Räsänen (Guest)


Rate this post
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
};

von Martin T. (mthomas) (Moderator)


Rate this post
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.

von Toni Räsänen (Guest)


Attached files:

Rate this post
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.

von Martin T. (mthomas) (Moderator)


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

von Toni Räsänen (Guest)


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

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful

von Toni Räsänen (Guest)


Rate this post
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.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.