On the C8051F38x, can I use the USB FIFO space for general purpose XRAM if the USB module is not using that memory? In other words, if I am only using Endpoints 0 and 1, can I use the remaining Endpoint 2, 3 and remaining free space in the USB FIFO space as general purpose XRAM?
On the C8051F38x, you can use the USB FIFO space as general purpose XRAM as long as the active Endpoint FIFO memory in this address space remains untouched and the guidelines in section 14.2 "Accessing USB FIFO Space" of the C8051F38x Reference Manual (page 94). Thus, if you are only using Endpoints 0 and 1, you can use the memory at locations 0x0400 to 0x073F as general purpose XRAM. The USB FIFO access guidelines are as follows (see section 14.2 for more information):
1) The USB Clock must be active and greater than or equal to twice the frequency of SYSCLK (USBCLK >= 2 x SYSCLK) because the USB FIFO memory is clocked from the USB clock.
2) The USB FIFO Access Ennable bit (USBFAE) in the EMI0CF register must be set to '1.'
When the USBFAE bit is set to '0' (default), the memory region between 0x0400 - 0x07FF is mapped to the normal on/off chip XRAM. When this bit is set, the USB FIFO memory is mapped to these locations, as shown in the following figure.
To locate a variable at a particular location in XDATA (including the USB FIFO space if the above conditions are met), you can use either the "_at_" directive:
xdata unsigned char myVariable _at_ 0x0402;
or use a command line linker directive. For more information on this technique, please refer to the following Keil article: