How do I create a USB memory section and place variables there?
I am using the LPC2148, which has a 8k RAM buffer for USB operations, but I am not using the USB interface, and instead want to use that memory for some of my larger buffers that are defined at compile time (global variables) to free up regular memory. I can, of course, use pointers, such as:
#define ucBuffer1 ((unsigned char *)USB_MEMORY_START)
#define ucBuffer2 ((unsigned char *)USB_MEMORY_START+100)
but then I have to manage the addresses and consumption of USB memory, and risk doing my pointer math wrong. A better solution would be to create a CPP file with all of the variables declared as you normally would:
unsigned char ucBuffer1[100];
unsigned char ucBuffer2[100];
and let the linker manage the actual addresses. I could then place that entire CPP file into the USB memory section. Alternatively, I can use the "__attribute__ ((section(".bar")))" directive, such as:
unsigned int var __attribute__ ((section(".bar")));
In either case, I cannot figure out for to create a section that the linker will use to locate these variables. I'm sure I'm missing something obvious... any help would be greatly appreciated!
Please sign in to leave a comment.
Comments
2 comments