Linker woes, const arrays in Flash

Guest #1189205
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
};

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now