Conversion of C18 USB CDC firmware

General discussion on mikroC.
Author
Message
XorXaX
Posts: 181
Joined: 14 Nov 2006 17:09
Location: Ludvika, Sweden
Contact:

Conversion of C18 USB CDC firmware

#1 Post by XorXaX » 11 Aug 2008 08:19

Hello everyone!

Got bored this weekend and decided I would translate Microchips latest
C18 library for USB CDC into mikroC.

The translation went ok, kind of, at least there are not compiler errors,
so it compiles just fine!

But (there is always a but)! It doesn't work. The device is found my
Windows Vista but as an "unknown device" in the Device Manager. I've
been using SourceUSB to see the communications with the device and it
fails when the PC is requesting the descriptor from the PIC.

After looking into it some I've found out that for what ever reason the
program doesn't continue to line 277 in the usbdrv.c that calls for a
function that is supposed to dealt with the enumeration...

I figured, as there are many of us that wants CDC in mikroC why not
help each other out on this one?

The source can be found here:
http://otio.se/~jonas/cdc.rar

Before you open the mikroC project in the "Cdc"-folder you have to copy
the P18F4550CDC.* files to you mikroC\defs folder. I've disabled the
loading of the mikroC HID library in those files.

I've also added the original C18 library, in the "MC_CDC"-folder.

In the "inf"-folder you can find a *.inf file to be used when installing the
drivers (when everything works). You can use it if you are testing the
C18 lib. The MCHPUSB.hex is compiled and works with PIC18F4550
running with a 20MHz crystal. Worked for me yesterday with EasyPIC5.

The mikroC project is configured to make the PIC18F4550 run at 48MHz
on a 20MHz crystal.

So, what do you say? Are we gonna make this work or what?
Jonas Andersson, Sweden
EasyPIC3, EasyPIC5, various dev boards and fully licensed mikroC
"It's nice to be important, but it's more important to be nice"

XorXaX
Posts: 181
Joined: 14 Nov 2006 17:09
Location: Ludvika, Sweden
Contact:

#2 Post by XorXaX » 17 Aug 2008 00:02

Been on this for another 12 hours and I can't get it to work.

The PIC seems to get stuck in the USB default state.

Isn't there anyone that is as interneted as me to get this to work?

Or maybe mikroE is wokring on a CDC library for mikroC, mikroBasic and mikroPascal?
Jonas Andersson, Sweden
EasyPIC3, EasyPIC5, various dev boards and fully licensed mikroC
"It's nice to be important, but it's more important to be nice"

akasaki
Posts: 1
Joined: 18 Aug 2008 10:10

I want more informastion

#3 Post by akasaki » 18 Aug 2008 10:18

Hi, XorXaX!

I'm interested in your work.
I try comile your code, but I could not compile it because compiling error...
error:Operator [.] not applicable to this operands [SetupPkt]

what is "SetupPkt"? where is definition of SetupPkt?

XorXaX
Posts: 181
Joined: 14 Nov 2006 17:09
Location: Ludvika, Sweden
Contact:

Re: Conversion of C18 USB CDC firmware

#4 Post by XorXaX » 18 Aug 2008 10:23

Thanks for your interest!

To quote my self:
XorXaX wrote: Before you open the mikroC project in the "Cdc"-folder you have to copy
the P18F4550CDC.* files to you mikroC\defs folder. I've disabled the
loading of the mikroC HID library in those files.
You have to copy these definitions files and use the PIC18F4550CDC as
device for this project, this is because I have disable the HID library in
this device definition file.

In mikroE's USB HID library they define their own SetupPkt, thus can't we
use that variable in this CDC library, unless we disable it, that I have
done in my def files.

Try this again and let me know if it works better to compile.
Jonas Andersson, Sweden
EasyPIC3, EasyPIC5, various dev boards and fully licensed mikroC
"It's nice to be important, but it's more important to be nice"

pdo59
Posts: 10
Joined: 22 Aug 2008 22:22
Location: Italy

#5 Post by pdo59 » 24 Aug 2008 09:33

Hi Jonas,
I'm downloaded your work.
Today I'm trying it and do you know how it goes.

pdo59
Posts: 10
Joined: 22 Aug 2008 22:22
Location: Italy

#6 Post by pdo59 » 24 Aug 2008 19:16

Hi Jonas,
I'm tested your work, it is a really nice work ! :shock:
Even in my PC (Vista32) the hardware is not recognized. However during compilation with MikroC I see this message:

Code: Select all

- pointer conversion to int type 
occurred in lines 150 and 156 of usb9.c that is this istructions:

Code: Select all

*pSrc.bRom = *(USB_CD_Ptr + SetupPkt.e.bDscIndex);
I am investigating ... but is a hard work :cry: for a beginner like me !
So, what do you say? Are we gonna make this work or what?
... then ... I'm working.

XorXaX
Posts: 181
Joined: 14 Nov 2006 17:09
Location: Ludvika, Sweden
Contact:

#7 Post by XorXaX » 25 Aug 2008 11:06

Hi pdo59!

yeah, that pointer thingy, I have no idea how to get rid of it. I don't think
that is the problem casing the computer not to recognize it (but I'm not sure).

Maybe someone else does?
Jonas Andersson, Sweden
EasyPIC3, EasyPIC5, various dev boards and fully licensed mikroC
"It's nice to be important, but it's more important to be nice"

pdo59
Posts: 10
Joined: 22 Aug 2008 22:22
Location: Italy

#8 Post by pdo59 » 25 Aug 2008 19:11

Hello Jonas,
right, this is not the problem. :(
However in this manner the compiler don't send a warning :

Code: Select all

*pSrc.bRom = *(*USB_SD_Ptr + SetupPkt.e.bDscIndex);

XorXaX
Posts: 181
Joined: 14 Nov 2006 17:09
Location: Ludvika, Sweden
Contact:

#9 Post by XorXaX » 25 Aug 2008 20:12

Yepp, compiles without complains now, thanks for that.

I think the problem is that the UIR.TRNIF (the USB Transfer Complete Flag)
never seems to be asserted for whatever reason. And since this never gets
asserted, and the computer doesnt recognize the device it must mean that
for whatever reason the SETUP Token doesn't get through to alright in the
PIC or the PC never sends it... See PIC18F4550 datasheet, figure 17-9,
page 177.

See usbdrv.c line 303, that if-case is never run :(
Jonas Andersson, Sweden
EasyPIC3, EasyPIC5, various dev boards and fully licensed mikroC
"It's nice to be important, but it's more important to be nice"

Falcon
Posts: 31
Joined: 17 Feb 2008 22:20

#10 Post by Falcon » 25 Aug 2008 21:17

Hi there,

I have not seen Xorxax' translation job,but I am quite interested, as it could be useful in near future.

As far as I have seen, I believe that the mistake in the code below could be in SetupPkt.e.bDscIndex

So, from

*pSrc.bRom = *(*USB_SD_Ptr + SetupPkt.e.bDscIndex);
you could try
*pSrc.bRom = *(USB_SD_Ptr + SetupPkt->e.bDscIndex);

This is be because if "e" is a structure or an union, then "bDscIndex" is its member. However "e" is also a member of the structure/union of SetupPkt.

To directly access bDscIndex (from "e"), here's an example:
variable= e.bDscIndex

To access bDscIndex from SetupPkt (indirect access), then
variable= SetupPkt->e.bDscIndex

Please, let me know if it works,

Regards,

Falcon

XorXaX
Posts: 181
Joined: 14 Nov 2006 17:09
Location: Ludvika, Sweden
Contact:

#11 Post by XorXaX » 25 Aug 2008 21:40

Thanks for the suggestion Falcon, one could have hoped it would be that easy, but since SetupPkt isn't a pointer and just a global variable, we are supposted to use the . instead of the -> ...

If using the -> the code wont even compile.
Jonas Andersson, Sweden
EasyPIC3, EasyPIC5, various dev boards and fully licensed mikroC
"It's nice to be important, but it's more important to be nice"

pdo59
Posts: 10
Joined: 22 Aug 2008 22:22
Location: Italy

#12 Post by pdo59 » 25 Aug 2008 21:43

Hi Falcon,
your advice is correct, (I think), but the compiler reply:

Code: Select all

Pointer required
Thank you for your appreciate help; if you can, help us in this work trying to compile the XorXaX code.

lutcho
Posts: 2
Joined: 02 May 2008 21:13

#13 Post by lutcho » 30 Sep 2008 17:32

Some time ago I was able to complete de 'translation' of the Microchip CDC to MikroC, based on a job by Rotendje (take a look at http://www.mikroe.com/forum/viewtopic.php?t=11424).
Unfortunelly, I stopped at the same point: the USB device is detected but halts after a few seconds. Did someone got beyond this point?

regards,
Lutcho

pdo59
Posts: 10
Joined: 22 Aug 2008 22:22
Location: Italy

#14 Post by pdo59 » 30 Sep 2008 18:19

Hi lutcho,
unfortunately no. :cry:
The problem is that the code appears to be correct, but the device is not detected.

Mohan
Posts: 12
Joined: 23 Jan 2008 12:27
Location: Pondicherry
Contact:

#15 Post by Mohan » 01 Oct 2008 09:11

Hi Lutcho/PDO59,

Can you please give the latest project files so that somebody can try further (including myself).
Hobbyist, Pondicherry
India

Post Reply

Return to “mikroC General”