Hi Vaclav,

The above measures will allow you to build the project, but manual inspection of the code generated for usb.c, l.309 revealed that there is severe bug in the code generator: instead of just reading SetupPacket.wValue1 (offset 3), the generated code overwrites SetupPacket.bmRequestType (offset 0). There seems to be lack of
scratch register allocation. I'll have to investigate this
further... Just thought you might want to now.

can we return to this problem ? I tried to get newest SDCC-20080905
and compile the project again.

Good.

Downloaded the PICHID package -
http://www.nutsvolts.com/media-files/113/USB.zip

Did that as well.

Made necessary changes in usb.c and Makefile - see diffs. In compile
log there are missing some lines about --optimmize-goto and modified
dog caaled EVELYN.

Hmm. I spent the evening (after your post) compiling and inspecting the USB/PICHID/* stuff and updated the source to compile without warnings "the right way" (except for EVELYN, which is harmless: it removed empty if-blocks). Find attached a more generally applicable Makefile, a patch to move sdcc keywords into the __-namespace (just recommended, cosmetic.patch) and another patch to remove all warnings (take address of proper object instead of casting blindly). However, they yield no difference in the output.

But device is not detected at all.

You mean that the PIC-USB-Device is not detected by some host system with confirmed working USB support, right? Gee, that makes it difficult...

Did you find something for these problems you mentioned ?

They are gone, the generated code is correct as far as I can see (well, I can only check some 100 LOCs, but the above problem is definitely no longer there; didn't bother to find out since when, though...). Your problem lies elsewhere I fear. Might be another compiler bug, or maybe your setup? Can you confirm your setup using the distributed USBHID.hex from USB.zip?

Maybe https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1772322&group_id=599 is related to and can solve your problem, though I do not quite why recompiling the libraries (solution proposed there) did help at all... You might try using SDCC 2.5.6 (r4161, to be obtained from svn directly).

Could *anyone* who has already run the given USB code on a PIC confirm that the code generated by the current SDCC 2.8.3, r5228, snapshot from 2008-09-05 is broken (or alternatively check that it works just fine)? Or post the version/revision of *any* (preferably the last ;-) ) working SDCC version so that I can generate reference .asm output? I do not even have a PIC nor a testbed to try, so I am quite lost here. How shall I debug this?!? I even tried to diff the disassembled versions of the packaged and the newly built USBHID.hex, but that diff is ... huge ...

Raphael
#
#
#

CHIP = 2550

LIBS = libio18f$(CHIP).lib libc18f.lib

OFILES = main.o usb.o

HEXFILE = USBHID.hex

OPTS = --vc --denable-peeps --optimize-cmp --optimize-df --obanksel=9 
--opt-code-size --fommit-frame-pointer
#OPTS = --vc --no-peep
#OPTS = --denable-peeps --optimize-cmp

CC = sdcc -mpic16 -p18f$(CHIP)
CFLAGS = -I. $(OPTS)

LD = $(CC)
LDFLAGS = -Wl,-s,18f$(CHIP).lkr,-m

all: $(HEXFILE)
        
clean:
        $(RM) *.asm *.cod *.hex *.lst *.map *.o

%.o: %.c
        $(CC) $(CFLAGS) -c $<

$(HEXFILE): $(OFILES)
        $(LD) $(LDFLAGS) -o $@ $(OFILES) $(LIBS)

#
# dependencies
#
main.o: usb.h callbacks.h
usb.o: usb.h callbacks.h

diff --git a/PICHID/main.c b/PICHID/main.c
index 7233d32..2a95ba7 100644
--- a/PICHID/main.c
+++ b/PICHID/main.c
@@ -35,24 +35,24 @@
 // Define configuration registers (fuses)
 #if defined(pic18f2550) || defined(pic18f2455) || defined(pic18f4550) || defined(pic18f4455)
 #if CLK_48MHZ
-code char at 0x300000 CONFIG1L = 0x24; // USB, /2 post (48MHz), /5 pre (20 MHz)
+__code char __at(0x300000) CONFIG1L = 0x24; // USB, /2 post (48MHz), /5 pre (20 MHz)
 #else
-code char at 0x300000 CONFIG1L = 0x3c; // USB, /6 post (16MHz), /5 pre (20 MHz)
-// code char at 0x300000 CONFIG1L = 0x34; // USB, /4 post (24MHz), /5 pre (20 MHz)
+__code char __at(0x300000) CONFIG1L = 0x3c; // USB, /6 post (16MHz), /5 pre (20 MHz)
+// __code char __at(0x300000) CONFIG1L = 0x34; // USB, /4 post (24MHz), /5 pre (20 MHz)
 #endif
-code char at 0x300001 CONFIG1H = 0x0e; // IESO=0, FCMEN=0, HS-PLL (40MHz)
-code char at 0x300002 CONFIG2L = 0x20; // Brown out off, PWRT On
-code char at 0x300003 CONFIG2H = 0x00; // WDT off
-code char at 0x300004 CONFIG3L = 0xff; // Unused configuration bits
-code char at 0x300005 CONFIG3H = 0x01; // No MCLR, PORTB digital, CCP2 - RC1
-code char at 0x300006 CONFIG4L = 0x80; // ICD off, ext off, LVP off, stk ovr off
-code char at 0x300007 CONFIG4H = 0xff; // Unused configuration bits
-code char at 0x300008 CONFIG5L = 0xff; // No code read protection
-code char at 0x300009 CONFIG5H = 0xff; // No data/boot read protection
-code char at 0x30000A CONFIG6L = 0xff; // No code write protection
-code char at 0x30000B CONFIG6H = 0xff; // No data/boot/table protection
-code char at 0x30000C CONFIG7L = 0xff; // No table read protection
-code char at 0x30000D CONFIG7H = 0xff; // No boot table protection
+__code char __at(0x300001) CONFIG1H = 0x0e; // IESO=0, FCMEN=0, HS-PLL (40MHz)
+__code char __at(0x300002) CONFIG2L = 0x20; // Brown out off, PWRT On
+__code char __at(0x300003) CONFIG2H = 0x00; // WDT off
+__code char __at(0x300004) CONFIG3L = 0xff; // Unused configuration bits
+__code char __at(0x300005) CONFIG3H = 0x01; // No MCLR, PORTB digital, CCP2 - RC1
+__code char __at(0x300006) CONFIG4L = 0x80; // ICD off, ext off, LVP off, stk ovr off
+__code char __at(0x300007) CONFIG4H = 0xff; // Unused configuration bits
+__code char __at(0x300008) CONFIG5L = 0xff; // No code read protection
+__code char __at(0x300009) CONFIG5H = 0xff; // No data/boot read protection
+__code char __at(0x30000A) CONFIG6L = 0xff; // No code write protection
+__code char __at(0x30000B) CONFIG6H = 0xff; // No data/boot/table protection
+__code char __at(0x30000C) CONFIG7L = 0xff; // No table read protection
+__code char __at(0x30000D) CONFIG7H = 0xff; // No boot table protection
 #endif
 
 // HID feature buffer
@@ -85,7 +85,7 @@ static unsigned char RxRS232()
 {
     unsigned char rxByte;
  
-    _asm clrwdt _endasm;
+    __asm clrwdt __endasm;
 
     // Check for Overrun Error
     if (RCSTA & 0x02)
@@ -108,7 +108,7 @@ static unsigned char RxRS232()
 
 static void TxRS232(unsigned char txData)
 {
-    _asm clrwdt _endasm;
+    __asm clrwdt __endasm;
 
     putchar(txData);
 }
diff --git a/PICHID/usb.c b/PICHID/usb.c
index edac54f..5deb9d4 100644
--- a/PICHID/usb.c
+++ b/PICHID/usb.c
@@ -66,7 +66,7 @@ byte hidIdleRate;
 byte hidProtocol; // [0] Boot Protocol [1] Report Protocol
 byte hidRxLen;    // # of bytes put into buffer
 
-code byte deviceDescriptor[] =
+__code byte deviceDescriptor[] =
 {
     0x12, 0x01, // bLength, bDescriptorType
     0x00, 0x02, // bcdUSB (low byte), bcdUSB (high byte)
@@ -84,7 +84,7 @@ code byte deviceDescriptor[] =
 #define HISZ HID_INPUT_REPORT_BYTES
 #define HOSZ HID_OUTPUT_REPORT_BYTES
 
-code ConfigStruct configDescriptor =
+__code ConfigStruct configDescriptor =
 {
     {
     // Configuration descriptor
@@ -125,7 +125,7 @@ code ConfigStruct configDescriptor =
 #define HFRB HID_FEATURE_REPORT_BYTES
 
 #define HID_REPORT_SIZE 0x2f // Size is from HID Descriptor tool
-code byte HIDReport[HID_REPORT_SIZE] = {
+__code byte HIDReport[HID_REPORT_SIZE] = {
     0x06, 0xa0, 0xff,  // USAGE_PAGE (Vendor Defined Page 1)
     0x09, 0x01,        // USAGE (Vendor Usage 1)
     0xa1, 0x01,        // COLLECTION (Application)
@@ -150,18 +150,18 @@ code byte HIDReport[HID_REPORT_SIZE] = {
     0xc0               // END_COLLECTION
 };
 
-code byte stringDescriptor0[] =
+__code byte stringDescriptor0[] =
 {
     0x04, STRING_DESCRIPTOR,
     0x09, 0x04,
 };
-code byte stringDescriptor1[] =
+__code byte stringDescriptor1[] =
 {
     0x0E, STRING_DESCRIPTOR, // bLength, bDscType
     'X', 0x00, 'a', 0x00, 'n', 0x00, 'd', 0x00,
     'e', 0x00, 'r', 0x00,
 };
-code byte stringDescriptor2[] =
+__code byte stringDescriptor2[] =
 {
     0x20, STRING_DESCRIPTOR,
     'U', 0x00, 'S', 0x00, 'B', 0x00, ' ', 0x00,
@@ -170,10 +170,10 @@ code byte stringDescriptor2[] =
     'H', 0x00, 'I', 0x00, 'D', 0x00,
 };
 
-volatile BDT at 0x0400 ep0Bo; //Endpoint #0 BD Out
-volatile BDT at 0x0404 ep0Bi; //Endpoint #0 BD In
-volatile BDT at 0x0408 ep1Bo; //Endpoint #1 BD Out
-volatile BDT at 0x040C ep1Bi; //Endpoint #1 BD In
+volatile BDT __at(0x0400) ep0Bo; //Endpoint #0 BD Out
+volatile BDT __at(0x0404) ep0Bi; //Endpoint #0 BD In
+volatile BDT __at(0x0408) ep1Bo; //Endpoint #1 BD Out
+volatile BDT __at(0x040C) ep1Bi; //Endpoint #1 BD In
 
 // TBD: add definitions for additional endpoints (2-16).
 
@@ -1161,7 +1161,7 @@ void ProcessUSBTransactions(void)
 
 #if 1
 // Test - put something into EEPROM
-code at 0xF00000 word dataEEPROM[] =
+__code __at(0xF00000) word dataEEPROM[] =
 {
     0, 1, 2, 3, 4, 5, 6, 7,
     '0', '1', '2', '3', '4', '5', '6', '7',
diff --git a/PICHID/usb.h b/PICHID/usb.h
index 5089a19..4b5291f 100644
--- a/PICHID/usb.h
+++ b/PICHID/usb.h
@@ -104,10 +104,10 @@ extern byte selfPowered;
 extern byte remoteWakeup;
 extern byte currentConfiguration;
 
-extern volatile BDT at 0x0400 ep0Bo; //Endpoint #0 BD Out
-extern volatile BDT at 0x0404 ep0Bi; //Endpoint #0 BD In
-extern volatile BDT at 0x0408 ep1Bo; //Endpoint #1 BD Out
-extern volatile BDT at 0x040C ep1Bi; //Endpoint #1 BD In
+extern volatile BDT __at(0x0400) ep0Bo; //Endpoint #0 BD Out
+extern volatile BDT __at(0x0404) ep0Bi; //Endpoint #0 BD In
+extern volatile BDT __at(0x0408) ep1Bo; //Endpoint #1 BD Out
+extern volatile BDT __at(0x040C) ep1Bi; //Endpoint #1 BD In
 
 // Every device request starts with an 8 byte setup packet (USB 2.0, chap 9.3)
 // with a standard layout.  The meaning of wValue and wIndex will
diff --git a/PICHID/main.c b/PICHID/main.c
index 2a95ba7..04f7530 100644
--- a/PICHID/main.c
+++ b/PICHID/main.c
@@ -235,7 +235,7 @@ void SetupFeatureReport(byte reportID)
     {
         // When the report arrives in the data stage, the data will be  
         // stored in HIDFeatureBuffer.
-        inPtr = (byte*)&HIDFeatureBuffer;
+        inPtr = &HIDFeatureBuffer[0];
     }
 }
 
@@ -267,7 +267,7 @@ void GetFeatureReport(byte reportID)
 	if (reportID == 0)
 	{
 		// Handle report #0
-		outPtr = (byte *)&HIDFeatureBuffer;
+		outPtr = &HIDFeatureBuffer[0];
 		HIDFeatureBuffer[0] = PORTA;
 		// HIDFeatureBuffer[HID_FEATURE_REPORT_BYTES-1] = 0x2C;
 		wCount = HID_FEATURE_REPORT_BYTES;
@@ -286,7 +286,7 @@ void SetupOutputReport(byte reportID)
 	{
 		// When the report arrives in the data stage, the data will be  
 		// stored in HIDFeatureBuffer
-		inPtr = (byte*)&HIDRxBuffer;
+		inPtr = &HIDRxBuffer[0];
 	}
 }
 
@@ -316,7 +316,7 @@ void GetInputReport(byte reportID)
 	{
 		// Send back the contents of the HID report
 		// TBD: provide useful information...
-		outPtr = (byte *)&HIDTxBuffer;
+		outPtr = &HIDTxBuffer[0];
 
 		// The number of bytes in the report (from usb.h).
 		wCount = HID_INPUT_REPORT_BYTES;
diff --git a/PICHID/usb.c b/PICHID/usb.c
index 5deb9d4..dd9fad8 100644
--- a/PICHID/usb.c
+++ b/PICHID/usb.c
@@ -214,7 +214,7 @@ printf("HIDTxReport: %d\r\n", (word)len);
 
    // Copy data from user's buffer to dual-ram buffer
 #if USE_MEMCPY
-    memcpy(HIDTxBuffer, buffer, len);
+    memcpy(&HIDTxBuffer[0], buffer, len);
 #else
     for (i = 0; i < len; i++)
         HIDTxBuffer[i] = buffer[i];
@@ -250,7 +250,7 @@ byte HIDRxReport(byte *buffer, byte len)
         
         // Copy data from dual-ram buffer to user's buffer
 #if USE_MEMCPY
-        memcpy(buffer, HIDRxBuffer, len);
+        memcpy(buffer, &HIDRxBuffer[0], len);
 #else
         for(hidRxLen = 0; hidRxLen < len; hidRxLen++)
         {
@@ -288,10 +288,10 @@ void HIDInitEndpoint(void)
     UEP1 = 0x1E;
     
     ep1Bo.Cnt = sizeof(HIDRxBuffer);
-    ep1Bo.ADDR = PTR16(&HIDRxBuffer);
+    ep1Bo.ADDR = PTR16(&HIDRxBuffer[0]);
     ep1Bo.Stat = UOWN | DTSEN;
 
-    ep1Bi.ADDR = PTR16(&HIDTxBuffer);
+    ep1Bi.ADDR = PTR16(&HIDTxBuffer[0]);
     ep1Bi.Stat = DTS;
 }
 
@@ -349,7 +349,7 @@ printf("HID: HID_DESCRIPTOR\r\n");
 #endif
             // HID descriptor.
             requestHandled = 1;
-            outPtr = &configDescriptor.HIDDescriptor;
+            outPtr = &configDescriptor.HIDDescriptor[0];
             wCount = HID_HEADER_SIZE;
         }
         else if (descriptorType == REPORT_DESCRIPTOR)
@@ -359,7 +359,7 @@ printf("HID: REPORT_DESCRIPTOR\r\n");
 #endif
             // Report descriptor.
             requestHandled = 1;
-            outPtr = (code byte *)HIDReport;
+            outPtr = &HIDReport[0];
             wCount = HID_REPORT_SIZE;
         }
         else if (descriptorType == PHYSICAL_DESCRIPTOR)
@@ -464,7 +464,7 @@ static void GetDescriptor(void)
                 printf("DEVICE_DESCRIPTOR\r\n");
 #endif
                 requestHandled = 1;
-                outPtr = (byte *)&deviceDescriptor;
+                outPtr = &deviceDescriptor[0];
                 wCount = DEVICE_DESCRIPTOR_SIZE;
         }
         else if (descriptorType == CONFIGURATION_DESCRIPTOR)
@@ -497,11 +497,11 @@ static void GetDescriptor(void)
 #endif
                 requestHandled = 1;
                 if (descriptorIndex == 0)
-                    outPtr = &stringDescriptor0;
+                    outPtr = &stringDescriptor0[0];
                 else if (descriptorIndex == 1)
-                    outPtr = &stringDescriptor1;
+                    outPtr = &stringDescriptor1[0];
                 else
-                    outPtr = &stringDescriptor2;
+                    outPtr = &stringDescriptor2[0];
                 wCount = *outPtr;
         }
         else
@@ -557,7 +557,7 @@ printf("GetStatus\r\n");
 
     if (requestHandled)
     {
-        outPtr = (byte *)&controlTransferBuffer;
+        outPtr = &controlTransferBuffer[0];
         wCount = 2;
     }
 }
@@ -669,7 +669,7 @@ void ProcessStandardRequest(void)
             printf("GET_CONFIGURATION\r\n");
 #endif
             requestHandled = 1;
-            outPtr = (byte*)&currentConfiguration;
+            outPtr = &currentConfiguration;
             wCount = 1;
     }
     else if (request == GET_STATUS)
@@ -690,7 +690,7 @@ void ProcessStandardRequest(void)
 #endif
             requestHandled = 1;
             controlTransferBuffer[0] = 0;
-            outPtr = &controlTransferBuffer;
+            outPtr = &controlTransferBuffer[0];
             wCount = 1;
     }
     else if (request == SET_INTERFACE)
@@ -742,7 +742,7 @@ void InDataStage(void)
     ep0Bi.Stat &= ~(BC8 | BC9); // Clear BC8 and BC9
     ep0Bi.Stat |= (byte)((bufferSize & 0x0300) >> 8);
     ep0Bi.Cnt = (byte)(bufferSize & 0xFF);
-    ep0Bi.ADDR = PTR16(&controlTransferBuffer);
+    ep0Bi.ADDR = PTR16(&controlTransferBuffer[0]);
 
     // Update the number of bytes that still need to be sent.  Getting
     // all the data back to the host can take multiple transactions, so
@@ -750,7 +750,7 @@ void InDataStage(void)
     wCount = wCount - bufferSize;
     
     // Move data to the USB output buffer from wherever it sits now.
-    inPtr = (byte *)&controlTransferBuffer;
+    inPtr = &controlTransferBuffer[0];
 
 #if USE_MEMCPY
     memcpy(inPtr, outPtr, bufferSize);
@@ -779,7 +779,7 @@ void OutDataStage(void)
     // Accumulate total number of bytes read
     wCount = wCount + bufferSize;
     
-    outPtr = (byte*)&controlTransferBuffer;
+    outPtr = &controlTransferBuffer[0];
 #if USE_MEMCPY
     memcpy(inPtr, outPtr, bufferSize);
 #else
@@ -841,7 +841,7 @@ void SetupStage(void)
         ep0Bo.Stat = UOWN;
 
         // Set the in buffer descriptor on endpoint 0 to send data
-        ep0Bi.ADDR = PTR16(&controlTransferBuffer);
+        ep0Bi.ADDR = PTR16(&controlTransferBuffer[0]);
         // Give to SIE, DATA1 packet, enable data toggle checks
         ep0Bi.Stat = UOWN | DTS | DTSEN; 
     }
@@ -856,7 +856,7 @@ void SetupStage(void)
 
         // Set the out buffer descriptor on endpoint 0 to receive data
         ep0Bo.Cnt = E0SZ;
-        ep0Bo.ADDR = PTR16(&controlTransferBuffer);
+        ep0Bo.ADDR = PTR16(&controlTransferBuffer[0]);
         // Give to SIE, DATA1 packet, enable data toggle checks
         ep0Bo.Stat = UOWN | DTS | DTSEN;
     }
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to