Linker woes, const arrays in Flash

Guest #1189205
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
};
Moderator
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.
Guest
The attached file is a minimal project that has this behavior (including 
map file from test compile) using the same structure definitions.
Attached files:
Guest
Yes, makes sense, when I now think of it. I just never had encountered 
this kind of "const to const" situation before.

Reply

A question of your own? This thread is over 17 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.