The newbie problem I have is that I want, at run time, to modify my USB descriptors which in the Cypress examples are in a file called dscr.a51. They are declared in a segment called CODE, and I assume this is why attempts to modify them from the code are called illegal, even though they are actually in RAM on the FX2 Can anyone give me a quick nudge towards the best way to get round this? I'm familiar with C but not in an embedded environment.
Have you tried asking Cypress?
The 8051 has a "Harvard architecture", which is to say that it has separate code and data address spaces. The code space is read only. The read-only limiation has nothing to do with the memory type. There exists no instruction in the processor to write to code space. Often, 8051 designs will use logic to decode the bus such that the physical memory used to store code also appears in the data address space. The processor can then write to its data space, which will affect the code memory. This memory arrangement is often called a "von Neumann" architecture. The code keyword in Keil C denotes data that is located in the code address space. xdata marks data in the external data memory space. If you want to alter constants on the fly, declare them xdata
"If you want to alter constants (sic?!) on the fly, declare them xdata" While this is true in general, there may be specific requirements for these specific "constants" (USB descriptors) on this specific chip (Cypress FX2). Hence this needs checking with the data sheet and/or Cypress tech support.
Thanks for the suggestions. In the end I found a sample of (Cypress) code which I have made use of. The technique seems to be to cast a pointer to the 'constant' which must be altered, as xdata. It seemed to generate the right SRC code. I want to experiment with using xdata for the original declaration, but I haven't yet figured out how to control the linker to decide where the data actually goes in the address spaces.
pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr; *((BYTE xdata *)pHighSpeedConfigDscr+7) |= 0x40;