From 651c3a4be7ebd8fc1fec4ca5fd45859408c4dc52 Mon Sep 17 00:00:00 2001 From: Doug Brown Date: Sat, 10 Dec 2011 18:57:17 -0800 Subject: [PATCH] Finished testing the new functions I made for chip identification. It works well --- usb_serial/usb_serial.c | 103 ++++------------------------------------ 1 file changed, 10 insertions(+), 93 deletions(-) diff --git a/usb_serial/usb_serial.c b/usb_serial/usb_serial.c index 056fab1..e248570 100644 --- a/usb_serial/usb_serial.c +++ b/usb_serial/usb_serial.c @@ -35,109 +35,26 @@ void USBSerial_Init(void) USB_Init(); } -static int gotChar = 0; void USBSerial_Check(void) { - if (USB_DeviceState == DEVICE_STATE_Configured) + /*if (USB_DeviceState == DEVICE_STATE_Configured) { if (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) { CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); - /*#define BUFSIZE 128UL - static uint32_t readBuf[BUFSIZE]; + struct ChipID chips[4]; + ExternalMem_IdentifyChips(chips); + char tmp[20]; + int x; - for (x = 0; x < 512UL * 1024UL / BUFSIZE; x++) + for (x = 0; x < 4; x++) { - ExternalMem_Read(x*BUFSIZE, readBuf, BUFSIZE); - - if (CDC_Device_SendData(&VirtualSerial_CDC_Interface, (const char *)readBuf, BUFSIZE*4) != ENDPOINT_RWSTREAM_NoError) - { - PORTD |= (1 << 7); - } - }*/ - - // Start out in programming state... - ExternalMem_DeassertCS(); - ExternalMem_DeassertOE(); - ExternalMem_DeassertWE(); - _delay_us(1); - - // Write 0xAA to 0x555 (first byte of unlock sequence) - // (The SST39SF040 asks for 0x5555 here -- but it doesn't matter, it's - // just an alternating pattern of 1s and 0s and the chips will ignore - // the bits above the value it asks for -- so I can just write a huge - // alternating pattern and it will work with most/all chips) - ExternalMem_SetAddressAndData(0x55555555UL, 0xAAAAAAAAUL); - ExternalMem_AssertCS(); - ExternalMem_AssertWE(); - _delay_us(1); - ExternalMem_DeassertWE(); - _delay_us(1); - - // Write 0x55 to 0x2AA (second byte of unlock sequence) - ExternalMem_SetAddressAndData(0xAAAAAAAAUL, 0x55555555UL); - ExternalMem_AssertWE(); - _delay_us(1); - ExternalMem_DeassertWE(); - _delay_us(1); - - // Write 0x90 to 0x555 (autoselect command) - ExternalMem_SetAddressAndData(0x55555555UL, 0x90909090UL); - ExternalMem_AssertWE(); - _delay_us(1); - ExternalMem_DeassertWE(); - //ExternalMem_DeassertCS(); - _delay_us(1); - - // Now we can start reading... - ExternalMem_SetAddress(0x0); - ExternalMem_SetDataAsInput(); - ExternalMem_AssertOE(); - //ExternalMem_AssertCS(); - - _delay_us(1); - - uint32_t result = ExternalMem_ReadData(); - - char test[20]; - sprintf(test, "%08lX ", result); - CDC_Device_SendString(&VirtualSerial_CDC_Interface, test); - - ExternalMem_SetAddress(0x1); - result = ExternalMem_ReadData(); - sprintf(test, "%08lX\r\n", result); - CDC_Device_SendString(&VirtualSerial_CDC_Interface, test); - - // Exit back to normal mode... - ExternalMem_DeassertOE(); - ExternalMem_SetAddressAndData(0x0, 0xF0F0F0F0UL); - //ExternalMem_AssertCS(); - ExternalMem_AssertWE(); - _delay_us(1); - ExternalMem_DeassertWE(); - //ExternalMem_DeassertCS(); - _delay_us(1); - - // Now do normal read cycle to confirm we exited - ExternalMem_SetAddress(0x0); - ExternalMem_SetDataAsInput(); - ExternalMem_AssertOE(); - //ExternalMem_AssertCS(); - - _delay_us(1); - - result = ExternalMem_ReadData(); - - sprintf(test, "%08lX ", result); - CDC_Device_SendString(&VirtualSerial_CDC_Interface, test); - - ExternalMem_SetAddress(0x1); - result = ExternalMem_ReadData(); - sprintf(test, "%08lX\r\n", result); - CDC_Device_SendString(&VirtualSerial_CDC_Interface, test); + sprintf(tmp, "IC%d: M%02X, D%02X\r\n", x, chips[x].manufacturerID, chips[x].deviceID); + CDC_Device_SendString(&VirtualSerial_CDC_Interface, tmp); + } } - } + }*/ CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask();