Either compile it from scratch or load
USBVirtualSerial-ExtSRAMTest_Micropendous-AT90USB1287.hex directly
onto your board. A 16MHz crystal is assumed.
The Host side testing script, TestExtSRAMAccess.py, requires Python
2.5.x and PySerial
http://python.org/download/releases/2.5.5
http://sourceforge.net/projects/pyserial/files/pyserial/2.5/
If you do not want to install Python the communication protocol is
very simple. Send some data to the Serial Port of the device loaded
with USBVirtualSerial-ExtSRAMTest firmware and read back seven lines
of \r\n-terminated text.
The output should be something like:
PORTE=135
__malloc_heap_start=8448
__malloc_heap_end=65535
ExtMemArray[0]=4294967295 at 8450
ExtMemArray[1]=1010101010 at 8454
ExtMemArray[ExtMemLastIndex]=1234567890 at 65506
ExtMemLastIndex=14264
Changes made to USBVirtualSerial.c from Micropendous-2011-03-01.zip
to create USBVirtualSerial-ExtSRAMTest.c include:
The required linker command in the makefile is:
EXTMEMOPTS +=-Wl,--defsym=__heap_start=0x802100,--defsym=__heap_end=0x80ffff
This places the heap in external SRAM while leaving internal SRAM
for variables and the stack. Other options given at
http://www.nongnu.org/avr-libc/user-manual/malloc.html are not
workable.
Set up external SRAM in an .init section:
// set up external SRAM prior to anything else to make sure malloc()
has access to it
void EnableExternalSRAM (void) __attribute__ ((naked)) __attribute__
((section (".init3")));
void EnableExternalSRAM(void)
{
PORTE_EXT_SRAM_SETUP;
XMCRA = ((1 << SRE)); // zero wait-states
XMCRB = 0;
}
Create a global pointer to the data array:
static uint32_t* ExtMemArray;
Use malloc to allocate the memory for 32-bit integers near the top of main()
uint16_t ExtMemArraySize = 57056; // 57056/4 = 14264
ExtMemArray = (uint32_t *) malloc(ExtMemArraySize);
if (ExtMemArray == NULL) {
abort(); }
Before the call to USB_Init() in SetupHardware, make sure once more
that the external SRAM interface is active:
PORTE_EXT_SRAM_SETUP;
ENABLE_EXT_SRAM;
SELECT_EXT_SRAM_BANK0;
Inside MainTask() change the values of array elements and send
associated data to the Host if it requests it:
ExtMemArray[0] = (uint32_t)4294967295;
// maximum unsigned 32-bit integer value
ExtMemArray[14264] = (uint32_t)1234567890; // final array element
if ((count = fread(&buffer, 1, CDC_TXRX_EPSIZE, &USBSerialStream)) > 0) {
fprintf(&USBSerialStream, "__malloc_heap_start=%5u\r\n",
((uint16_t)__malloc_heap_start));
fprintf(&USBSerialStream, "ExtMemArray[0]=%10lu at %5u\r\n",
((uint32_t)ExtMemArray[0]), ((uint16_t)&ExtMemArray[0]));
fprintf(&USBSerialStream, "ExtMemArray[14264]=%10lu at %5u\r\n",
((uint32_t)ExtMemArray[14264]), ((uint16_t)&ExtMemArray[14264]));
}
USBVirtualSerial-ExtSRAMTest firmware can be found at:
http://code.google.com/p/micropendous/downloads/detail?name=USBVirtualSerial-ExtSRAMTest.zip