ソースを参照

wild debugging

David Voswinkel 15 年 前
コミット
b7b35800cc

BIN
avr/usbload/commandline/snesuploader


+ 20 - 9
avr/usbload/commandline/snesuploader.c

@@ -16,9 +16,10 @@
 
 
 #define READ_BUFFER_SIZE    1024
-#define SEND_BUFFER_SIZE    128
+#define SEND_BUFFER_SIZE    0x200
 #define BUFFER_CRC          (1024 * 32)
 #define BANK_SIZE           (1<<15)
+#define BANK_SIZE_SHIFT     15
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,6 +32,7 @@
 #include "../usbconfig.h"       /* device's VID/PID and names */
 
 
+
 void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
 {
     uint16_t i,
@@ -171,19 +173,23 @@ int main(int argc, char **argv)
 
         usb_control_msg(handle,
                         USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
-                        USB_UPLOAD_INIT, 0, 0, NULL, 0, 5000);
+                        USB_UPLOAD_INIT, BANK_SIZE_SHIFT , 0, NULL, 0, 5000);
 
 
         while ((cnt = fread(read_buffer, READ_BUFFER_SIZE, 1, fp)) > 0) {
-            for (step = 0; step < READ_BUFFER_SIZE; step += SEND_BUFFER_SIZE) {
+            for (step = 0; step <= READ_BUFFER_SIZE; step += SEND_BUFFER_SIZE) {
                 addr_lo = addr & 0xffff;
                 addr_hi = (addr >> 16) & 0xff;
+                //memset(read_buffer, 0xff, READ_BUFFER_SIZE);
                 cnt = usb_control_msg(handle,
                                 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
                                 USB_ENDPOINT_OUT, USB_UPLOAD_ADDR, addr_hi,
                                 addr_lo, (char *) read_buffer + step,
                                 SEND_BUFFER_SIZE, 5000);
-
+                if (addr%0x1000==0){
+                    printf ("bank=0x%02x  addr=0x%08x\n", bank, addr);
+                }                
+                
                 if (cnt < 0) {
                     fprintf(stderr, "USB error: %s\n", usb_strerror());
                     exit(-1);
@@ -193,24 +199,29 @@ int main(int argc, char **argv)
 #endif
                 addr += SEND_BUFFER_SIZE;
             }
-
             memcpy(crc_buffer + cnt_crc, read_buffer, READ_BUFFER_SIZE);
             cnt_crc += READ_BUFFER_SIZE;
             if (cnt_crc >= BANK_SIZE) {
                 crc = do_crc(crc_buffer, BANK_SIZE);
-                printf
-                    ("Addr: 0x%06x Bank: 0x%02x HiAddr: 0x%02x  LoAddr: 0x%04x Crc: 0x%04x\n",
-                     addr, bank, addr_hi, addr_lo, crc);
+                printf ("bank=0x%02x  crc=0x%04x\n", bank, crc);
                 memset(crc_buffer, 0, BUFFER_CRC);
                 bank++;
                 cnt_crc = 0;
             }
         }
+        
+        /*
+            
         cnt = usb_control_msg(handle,
                               USB_TYPE_VENDOR | USB_RECIP_DEVICE |
                               USB_ENDPOINT_OUT, USB_CRC, addr_hi, addr_lo, NULL,
                               0, 5000);
-
+        */   
+        cnt = usb_control_msg(handle,
+                            USB_TYPE_VENDOR | USB_RECIP_DEVICE |
+                            USB_ENDPOINT_OUT, USB_SNES_BOOT, 0, 0, NULL,
+                            0, 5000);
+        
 
         if (cnt < 1) {
             if (cnt < 0) {

+ 6 - 5
avr/usbload/config.h

@@ -3,10 +3,10 @@
 #define __config_h__
 
 #define DEBUG_USB                   1
-#undef DEBUG_USB_RAW               1
-#undef DEBUG_SRAM                  1
-#undef DEBUG_SRAM_RAW                  
-#undef DEBUG_SREG                  
+#define DEBUG_USB_RAW               1
+#define DEBUG_SRAM                  0
+#define DEBUG_SRAM_RAW              0   
+#define DEBUG_SREG                  0
 #define DEBUG                       1
 
 
@@ -15,11 +15,12 @@
 #define REQ_STATUS_BULK_UPLOAD      0x03
 #define REQ_STATUS_BULK_NEXT        0x04
 #define REQ_STATUS_CRC              0x05
+#define REQ_STATUS_BOOT             0x06
 
 #define USB_MAX_TRANS               0xff
 #define USB_CRC_CHECK               0x01
 
-#define TRANSFER_BUFFER_SIZE        0xff
+#define TRANSFER_BUFFER_SIZE        0x200
 
 
 #endif 

+ 35 - 11
avr/usbload/crc.c

@@ -41,23 +41,50 @@ uint16_t do_crc_update(uint16_t crc, uint8_t * data, uint16_t size)
 }
 
 
-void crc_check_memory(uint32_t top_addr,uint8_t *buffer)
+void crc_check_bulk_memory(uint32_t bottom_addr,uint32_t top_addr)
+{
+    uint16_t crc = 0;
+    uint32_t addr = 0;
+    uint8_t req_bank = 0;
+    sram_bulk_read_start(bottom_addr);
+    for (addr = bottom_addr; addr < top_addr; addr++) {
+        if (addr && addr % 0x8000 == 0) {
+            printf("crc_check_bulk: bank=0x%02x addr=0x%08lx crc=0x%04x\n",
+                req_bank,addr,crc);
+            req_bank++;
+            crc = 0;
+        }
+        crc = crc_xmodem_update(crc, sram_bulk_read());
+        sram_bulk_read_next();
+    }
+    sram_bulk_read_end();
+    if (addr % 0x8000 == 0)
+        printf("crc_check_bulk: bank=0x%02x addr=0x%08lx crc=0x%04x\n",
+            req_bank,addr,crc);
+
+}
+
+
+
+void crc_check_memory(uint32_t bottom_addr,uint32_t top_addr,uint8_t *buffer)
 {
     uint16_t crc = 0;
     uint32_t addr;
     uint8_t req_bank = 0;
-    for (addr = 0x000000; addr < top_addr; addr += TRANSFER_BUFFER_SIZE) {
-        sram_read_buffer(addr, buffer, TRANSFER_BUFFER_SIZE);
-        crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE);
-        if (addr && addr % 32768 == 0) {
-            printf("crc_check_memory: req_bank: 0x%02x Addr: 0x%08lx CRC: 0x%04x\n",
-                   req_bank, addr, crc);
+    for (addr = bottom_addr; addr < top_addr; addr += TRANSFER_BUFFER_SIZE) {
+        if (addr && addr % 0x8000 == 0) {
+            printf("crc_check_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n",
+                req_bank,addr,crc);
             req_bank++;
             crc = 0;
         }
+        sram_read_buffer(addr, buffer, TRANSFER_BUFFER_SIZE);
+        crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE);
     }
 }
 
+
+
 uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer)
 {
     uint16_t crc = 0;
@@ -66,8 +93,5 @@ uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buff
         sram_read_buffer(addr, buffer, TRANSFER_BUFFER_SIZE);
         crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE);
     }
-#if DEBUG_USB
-    printf("crc_check_memory_range: Addr: 0x%08lx CRC: 0x%04x\n", addr, crc);
-#endif
-  return crc;
+    return crc;
 }

+ 3 - 2
avr/usbload/crc.h

@@ -2,8 +2,9 @@
 #include <stdint.h> 
 
 
-uint16_t crc_xmodem_update (uint16_t crc, uint8_t data);
+uint16_t crc_xmodem_update(uint16_t crc, uint8_t data);
 uint16_t do_crc(uint8_t * data,uint16_t size);
 uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size);
-void crc_check_memory(uint32_t top_addr,uint8_t *buffer);
+void crc_check_memory(uint32_t bottom_addr,uint32_t top_addr,uint8_t *buffer);
 uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer);
+void crc_check_bulk_memory(uint32_t bottom_addr,uint32_t top_addr);

+ 70 - 18
avr/usbload/main.c

@@ -21,7 +21,7 @@ uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
 uint32_t req_addr = 0;
 uint32_t req_size;
 uint8_t req_bank;
-uint32_t req_bank_size;
+uint16_t req_bank_size;
 uint8_t req_state = REQ_STATUS_IDLE;
 uint8_t rx_remaining = 0;
 uint8_t tx_remaining = 0;
@@ -52,8 +52,9 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
         rx_remaining = 0;
         req_bank_size = 1 << rq->wValue.word;
         sync_errors = 0;
+        crc = 0;
 #if DEBUG_USB
-        printf("USB_UPLOAD_INIT: bank_size=%li\n", req_bank_size);
+        printf("USB_UPLOAD_INIT: bank_size=0x%x\n", req_bank_size);
 #endif
 /*
  * -------------------------------------------------------------------------
@@ -75,11 +76,20 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
         }
         rx_remaining = rq->wLength.word;
         ret_len = USB_MAX_TRANS;
-        if (req_addr && req_addr % req_bank_size == 0) {
 #if DEBUG_USB
-            printf("USB_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx \n",
+        if (req_addr && (req_addr % 0x1000) == 0) {
+            
+            printf("USB_UPLOAD_ADDR: bank=0x%02x addr=0x%08lx\n",
+                req_bank, req_addr);
+            crc_check_bulk_memory(req_addr - 0x1000,req_addr);
+        
+        }
 #endif
+        if (req_addr && req_addr % req_bank_size == 0) {
+#if DEBUG_USB
+            printf("USB_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx\n",
                    req_bank, req_addr);
+#endif
             req_bank++;
         }
         ret_len = USB_MAX_TRANS;
@@ -108,10 +118,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
 
         req_bank = 0;
         rx_remaining = 0;
-        req_bank_size = 1 << rq->wValue.word;
+        req_bank_size = (1 << rq->wValue.word) & 0xffff;
         sync_errors = 0;
 #if DEBUG_USB
-        printf("USB_BULK_UPLOAD_INIT: bank_size=%li\n", req_bank_size);
+        printf("USB_BULK_UPLOAD_INIT: bank_size=0x%x\n", req_bank_size);
 #endif
 /*
  * -------------------------------------------------------------------------
@@ -189,15 +199,20 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
         req_addr = req_addr << 16;
         req_addr = req_addr | rq->wIndex.word;
 #if DEBUG_USB
-        printf("USB_CRC: addr=0x%lx \n", req_addr);
+        printf("USB_CRC: addr=0x%08lx \n", req_addr);
 #endif
 
-#if USB_CRC_CHECK
-        cli();
-        crc_check_memory(req_addr,read_buffer);
-        sei();
+        crc_check_bulk_memory(0x000000,req_addr);
+        ret_len = 0;
+/*
+ * -------------------------------------------------------------------------
+ */
+    } else if (rq->bRequest == USB_SNES_BOOT) {
+        req_state = REQ_STATUS_BOOT;
+#if DEBUG_USB
+        printf("USB_SNES_BOOT: ");
+        ret_len = 0;
 #endif
-
 /*
  * -------------------------------------------------------------------------
  */
@@ -247,7 +262,6 @@ void test_read_write(){
     while (addr++ <= 0x0000ff){
         sram_write(addr,i++);
     }
-
     addr = 0x000000;
     while (addr++ <= 0x0000ff){
         printf("read addr=0x%08lx %x\n",addr,sram_read(addr));
@@ -279,19 +293,43 @@ void test_bulk_read_write(){
     sram_bulk_read_end();
 }
 
+
+void test_non_zero_memory(uint32_t bottom_addr,uint32_t top_addr)
+{
+    uint32_t addr = 0;
+    uint8_t c;
+    sram_bulk_read_start(bottom_addr);
+    for (addr = bottom_addr; addr < top_addr; addr++) {
+        c = sram_bulk_read();
+        if (c!=0xff)
+            printf("addr=0x%08lx c=0x%x\n",addr,c);
+        sram_bulk_read_next();
+    }
+    sram_bulk_read_end();
+}
+
+
+
+void test_crc(){
+    printf("test_crc: clear\n");
+    avr_bus_active();
+    sram_bulk_set(0x000000,0x10000,0xff);
+    printf("test_crc: crc\n");
+    crc_check_bulk_memory(0x000000,0x10000);
+    printf("test_crc: check\n");
+    test_non_zero_memory(0x000000,0x10000);
+}
+
 int main(void)
 {
     uint8_t i;
-    uint32_t addr;
 
     uart_init();
     stdout = &uart_stdout;
     
     system_init();
     printf("Sytem Init\n");
-
-    //while(1);
-
+    
     avr_bus_active();
     usbInit();
     printf("USB Init\n");
@@ -312,9 +350,23 @@ int main(void)
     printf("USB connect\n");
     sei();
     printf("USB poll\n");
-    for (;;) {                  /* main event loop */
+    while (req_state != REQ_STATUS_BOOT){
         usbPoll();
     }
+    printf("USB poll done\n");
+    usbDeviceDisconnect();      
+    printf("USB disconnect\n");
+    crc_check_bulk_memory(0x000000,0x80000);
+    
+    printf("Disable snes WR\n");
+    snes_wr_disable(); 
+    printf("Use Snes lowrom\n");
+    snes_lorom();
+    printf("Activate Snes bus\n");
+    snes_bus_active();
+                          
+                                 
+    while(1);
     return 0;
 }
 

+ 1 - 0
avr/usbload/requests.h

@@ -29,5 +29,6 @@
 #define USB_BULK_UPLOAD_ADDR    7
 #define USB_BULK_UPLOAD_NEXT    8
 #define USB_BULK_UPLOAD_END     9
+#define USB_SNES_BOOT           10
 
 #endif /* __REQUESTS_H_INCLUDED__ */

+ 39 - 21
avr/usbload/sram.c

@@ -66,18 +66,18 @@ void system_init(void)
 void sreg_set(uint32_t addr)
 {
     uint8_t i = 24;
-#ifdef DEBUG_SREG
+#if DEBUG_SREG
     printf("sreg_set: addr=0x%08lx",addr);
 #endif
     while(i--) {
         if ((addr & ( 1L << i))){
-#ifdef DEBUG_SREG
+#if DEBUG_SREG
             printf("1");
 #endif
             AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
         } else {
             AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
-#ifdef DEBUG_SREG
+#if DEBUG_SREG
             printf("0");
 #endif
             
@@ -85,7 +85,7 @@ void sreg_set(uint32_t addr)
         AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
         AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
     }
-#ifdef DEBUG_SREG
+#if DEBUG_SREG
     printf("\n");
 #endif
     AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
@@ -99,7 +99,7 @@ void sreg_set(uint32_t addr)
 
 void sram_bulk_read_start(uint32_t addr)
 {
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_bulk_read_start: addr=0x%08lx\n\r", addr);
 #endif
     avr_data_in();
@@ -112,6 +112,11 @@ void sram_bulk_read_start(uint32_t addr)
 
     AVR_RD_PORT &= ~(1 << AVR_RD_PIN);
     asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
  }
 
 inline void sram_bulk_read_next(void)
@@ -121,6 +126,11 @@ inline void sram_bulk_read_next(void)
     AVR_RD_PORT &= ~(1 << AVR_RD_PIN);
 
     asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
 }
 
 
@@ -131,7 +141,7 @@ inline uint8_t sram_bulk_read(void)
 
 void sram_bulk_read_end(void)
 {
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_bulk_read_end:");
 #endif
     AVR_RD_PORT |= (1 << AVR_RD_PIN);
@@ -142,7 +152,7 @@ void sram_bulk_read_end(void)
 uint8_t sram_read(uint32_t addr)
 {
     uint8_t byte;
-#ifdef DEBUG_SRAM_RAW
+#if DEBUG_SRAM_RAW
     printf("sram_read: addr=0x%08lx\n\r", addr);
 #endif
     
@@ -157,6 +167,11 @@ uint8_t sram_read(uint32_t addr)
     
     AVR_RD_PORT &= ~(1 << AVR_RD_PIN);
     
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
+    asm volatile ("nop");
     asm volatile ("nop");
     
     byte = AVR_DATA_PIN;
@@ -171,7 +186,7 @@ uint8_t sram_read(uint32_t addr)
 
 void sram_bulk_write_start(uint32_t addr)
 {
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_bulk_write_start: addr=0x%08lx\n\r", addr);
 #endif
 
@@ -200,7 +215,7 @@ inline void sram_bulk_write( uint8_t data)
 
 void sram_bulk_write_end(void)
 {
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_bulk_write_end:");
 #endif
     AVR_WR_PORT |= (1 << AVR_WR_PIN);
@@ -212,7 +227,7 @@ void sram_bulk_write_end(void)
 void sram_write(uint32_t addr, uint8_t data)
 {
 
-#ifdef DEBUG_SRAM_RAW
+#if DEBUG_SRAM_RAW
     printf("sram_write: addr=0x%08lx data=%x\n\r", addr, data);
 #endif
 
@@ -239,7 +254,7 @@ void sram_bulk_copy(uint32_t addr, uint8_t * src, uint32_t len)
 
     uint32_t i;
     uint8_t *ptr = src;
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_copy: addr=0x%08lx src=0x%p len=%li\n\r", addr,src,len);
 #endif
     sram_bulk_write_start(addr);
@@ -255,7 +270,7 @@ void sram_bulk_read_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
 
     uint32_t i;
     uint8_t *ptr = dst;
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_bulk_read_buffer: addr=0x%08lx dst=0x%p len=%li\n\r", addr,dst,len);
 #endif
     sram_bulk_read_start(addr);
@@ -267,18 +282,18 @@ void sram_bulk_read_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
     sram_bulk_read_end();
 }
 
-void sram_bulk_clear(uint32_t addr, uint32_t len){
+void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
     uint32_t i;
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_bulk_clear: addr=0x%08lx len=%li\n\r", addr,len);
 #endif
     sram_bulk_write_start(addr);
     for (i = addr; i < (addr + len); i++) {
         if (0 == i % 0xfff)
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
         printf("sram_bulk_clear: addr=0x%08lx\n\r", i);
 #endif
-        sram_bulk_write(0xff);
+        sram_bulk_write(value);
         sram_bulk_write_next();
     }
     sram_bulk_write_end();
@@ -287,12 +302,12 @@ void sram_bulk_clear(uint32_t addr, uint32_t len){
 void sram_clear(uint32_t addr, uint32_t len)
 {
     uint32_t i;
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_clear: addr=0x%08lx len=%li\n\r", addr,len);
 #endif
     for (i = addr; i < (addr + len); i++) {
         if (0 == i % 0xfff)
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_clear: addr=0x%08lx\n\r", i);
 #endif
         sram_write(i, 0x00);
@@ -304,7 +319,7 @@ void sram_copy(uint32_t addr, uint8_t * src, uint32_t len)
 
     uint32_t i;
     uint8_t *ptr = src;
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_copy: addr=0x%08lx src=0x%p len=%li\n\r", addr,src,len);
 #endif
     for (i = addr; i < (addr + len); i++)
@@ -316,7 +331,7 @@ void sram_read_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
 
     uint32_t i;
     uint8_t *ptr = dst;
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_read_buffer: addr=0x%08lx dst=0x%p len=%li\n\r", addr,dst,len);
 #endif
     for (i = addr; i < (addr + len); i++) {
@@ -325,10 +340,11 @@ void sram_read_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
     }
 }
 
+
 uint8_t sram_check(uint8_t * buffer, uint32_t len)
 {
     uint16_t cnt;
-#ifdef DEBUG_SRAM
+#if DEBUG_SRAM
     printf("sram_check: len=%li\n\r",len);
 #endif
     for (cnt = 0; cnt < len; cnt++)
@@ -336,3 +352,5 @@ uint8_t sram_check(uint8_t * buffer, uint32_t len)
             return 1;
     return 0;
 }
+
+

+ 1 - 1
avr/usbload/sram.h

@@ -161,4 +161,4 @@ void sram_bulk_write(uint8_t data);
 
 void sram_bulk_copy(uint32_t addr, uint8_t * src, uint32_t len);
 void sram_bulk_read_buffer(uint32_t addr, uint8_t * dst, uint32_t len);
-void sram_bulk_clear(uint32_t addr, uint32_t len);
+void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value);

+ 1 - 0
avr/usbload/uart.h

@@ -16,3 +16,4 @@ static int uart_stream(char c, FILE *stream);
 
 
 #endif                          /* _UART_H_ */
+

+ 1 - 4
avr/usbload/usb_bulk.c

@@ -26,6 +26,7 @@ extern uint8_t req_state;
 extern uint8_t rx_remaining; 
 extern uint8_t tx_remaining;
 extern  uint8_t tx_buffer[32];
+extern uint16_t crc;
 
 uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
 {
@@ -43,9 +44,7 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
         printf("usbFunctionWrite REQ_STATUS_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n",
                req_addr, len, rx_remaining);
 #endif
-        //cli();
         sram_copy(req_addr, data, len);
-        //sei();
         req_addr += len;
     } else if (req_state == REQ_STATUS_BULK_UPLOAD) {
 
@@ -56,12 +55,10 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
 #endif
         ptr = data;
         i = len;
-        cli();
         while(i--){
             sram_bulk_write(*ptr++);
             counter_up();
         }
-        sei();
     }
     return len;
 }

+ 2 - 1
avr/usbload/usb_bulk.h

@@ -1,3 +1,4 @@
 
 uint8_t usbFunctionWrite(uint8_t * data, uint8_t len);
-uint8_t usbFunctionRead(uint8_t * data, uint8_t len);
+uint8_t usbFunctionRead(uint8_t * data, uint8_t len);
+

+ 2 - 2
avr/usbload/usbconfig.h

@@ -114,7 +114,7 @@ section at the end of this file).
 /* Define this to 1 if the device has its own power supply. Set it to 0 if the
  * device is powered from the USB bus.
  */
-#define USB_CFG_MAX_BUS_POWER           40
+#define USB_CFG_MAX_BUS_POWER           300
 /* Set this variable to the maximum USB bus power consumption of your device.
  * The value is in milliamperes. [It will be divided by two since USB
  * communicates power requirements in units of 2 mA.]
@@ -141,7 +141,7 @@ section at the end of this file).
  * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
  * usbdrv.h.
  */
-#define USB_CFG_LONG_TRANSFERS          0
+#define USB_CFG_LONG_TRANSFERS          1
 /* Define this to 1 if you want to send/receive blocks of more than 254 bytes
  * in a single control-in or control-out transfer. Note that the capability
  * for long transfers increases the driver size.

+ 53 - 7
snesram.tmproj

@@ -3,7 +3,7 @@
 <plist version="1.0">
 <dict>
 	<key>currentDocument</key>
-	<string>avr/usbload/commandline/snesuploader.c</string>
+	<string>avr/usbload/main.c</string>
 	<key>documents</key>
 	<array>
 		<dict>
@@ -68,14 +68,14 @@
 			<key>caret</key>
 			<dict>
 				<key>column</key>
-				<integer>0</integer>
+				<integer>23</integer>
 				<key>line</key>
-				<integer>0</integer>
+				<integer>206</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>198</integer>
+			<integer>206</integer>
 		</dict>
 		<key>avr/usbload/crc.c</key>
 		<dict>
@@ -84,7 +84,37 @@
 				<key>column</key>
 				<integer>0</integer>
 				<key>line</key>
+				<integer>44</integer>
+			</dict>
+			<key>columnSelection</key>
+			<false/>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>21</integer>
+			<key>selectFrom</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>43</integer>
+			</dict>
+			<key>selectTo</key>
+			<dict>
+				<key>column</key>
 				<integer>0</integer>
+				<key>line</key>
+				<integer>44</integer>
+			</dict>
+		</dict>
+		<key>avr/usbload/crc.h</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>14</integer>
+				<key>line</key>
+				<integer>9</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
@@ -152,14 +182,14 @@
 			<key>caret</key>
 			<dict>
 				<key>column</key>
-				<integer>17</integer>
+				<integer>23</integer>
 				<key>line</key>
-				<integer>59</integer>
+				<integer>195</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>161</integer>
+			<integer>176</integer>
 		</dict>
 		<key>avr/usbload/sram.c</key>
 		<dict>
@@ -217,6 +247,20 @@
 			<key>firstVisibleLine</key>
 			<integer>0</integer>
 		</dict>
+		<key>avr/usbload/usb_bulk.c</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>47</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>21</integer>
+		</dict>
 		<key>avr/usbload/usbconfig.h</key>
 		<dict>
 			<key>caret</key>
@@ -578,6 +622,7 @@
 		<string>scripts/b.py</string>
 		<string>scripts/rom.py</string>
 		<string>avr/usbload/crc.c</string>
+		<string>avr/usbload/crc.h</string>
 		<string>avr/usbload/sram.c</string>
 		<string>avr/usbload/sram.h</string>
 		<string>avr/usbload/fifo.h</string>
@@ -587,6 +632,7 @@
 		<string>avr/usbload/debug.c</string>
 		<string>avr/usbload/uart.c</string>
 		<string>avr/usbload/main.c</string>
+		<string>avr/usbload/usb_bulk.c</string>
 		<string>avr/usbload/usbconfig.h</string>
 		<string>avr/usbload/commandline/opendevice.c</string>
 		<string>avr/usbload/commandline/opendevice.h</string>