Author Topic: USB Problem  (Read 9258 times)

Offline quentin

  • Newbie
  • *
  • Posts: 4
    • View Profile
USB Problem
« on: May 21, 2012, 08:25:48 AM »
Hello,

I want to use the USB functionality of ?Tasker. Including the USB-MSD. I work on Windows XP SP3. For the three operating modes Windows ( XP or SEVEN ) me the following message: "USB Device Not Recognized". The debugger tells me that I stay in a function: USB_OTG_ISR.

Are what anyone has had this problem?

cordially

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: USB Problem
« Reply #1 on: May 21, 2012, 08:17:46 PM »
Hi

If the enumeration doesn't work it is normal that the PC gives such an error message.

However I have never experienced or heard of a problem with the processor staying in the ISR.

Which board and processor are you using? Ensure that the USB clock rate is correct (48MHz) and that the correct source for the USB clock is selected - it can be derived from the crystal input, the PLL or from a dedicated USB clock input.

Regards

Mark

Offline quentin

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: USB Problem
« Reply #2 on: May 22, 2012, 08:16:07 AM »
hello,

I just checked the USB clock is all good. the only thing I change is that on the line : const UTDISK * ptrDiskInfo fnGetDiskInfo (DISK_D);
Originally the "const" or was not but I was not compiliez Code Warrior tell me because an implicit conversion.

Processor : MCF52259

the card is not an evaluation board. the hard configuration is good Because it comes from a previous project.

cordially

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: USB Problem
« Reply #3 on: May 24, 2012, 06:16:20 PM »
Hi

Can the SW be run on the M52259EVB? If you, does it have the same issue?
If this is the case it may be interesting for you to send the binary/SREC (together with a map file) so that I can load to my board and possibly see a reason for it to hang.

Also, I would try building with optimisation off - there may be a difference (in some cases it may point to a volatile problem when optimising or even a compiler bug). If possible also testing with 2 compilers can be usedful - eg. GCC as well as Codewarrior etc.

Regards

Mark


Offline quentin

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: USB Problem
« Reply #4 on: May 25, 2012, 03:19:27 PM »
I have run tests on the M52259DEMOMCU in take care to take the project you have to send me by changing only the strictly necessary in the config.h file (activation M52259DEMO, USB, SDcard support or no). my compiler code Warrior is 7.2. CDC and HID mode compile OK but same problem for its MSD does not compile.
I do not use the BootLoader, I load the program with the full.S19

Erreur : illegal implicit conversion from 'const struct stUTDISK*' to ' struct stUTDISK'
usb_application.c line 723 : ptrDiskInfo = fnGetDiskInfo(DISK_D);  

I corrected the error by changing a little earlier in the code:

 static UTDISK *ptrDiskInfo = 0; -->  static const UTDISK *ptrDiskInfo = 0;

According to the debugger application is still blocking the function, USB_OTG_ISR, and watchdog takes over.

the SDcardsupport is forced to be enabled to use the USB?

Ps :The file "usb application" was not compiled if the SDCARD_SUPPORT is not enabled.
« Last Edit: June 04, 2012, 08:40:46 AM by quentin »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: USB Problem
« Reply #5 on: June 10, 2012, 03:57:49 PM »
Hi Quentin

Thank you for sending your code. In fact I could also reproduce the problem on the M52259EVB with any USB class when using CW7.2.

First of all, it is necessary to have the SD card support enabled to be able to work with MSD. This is because MSD and the SD card operate together and so it will result in a build error when only MSD is built without SD card enabled.

static const UTDISK *ptrDiskInfo = 0;
This is also correct. The pointer has been modifed to a const pointer recently since the caller should never attempt to change any contents. This means that the compiler will also generate errors if the user were to attempt this. It is a detail but probably the cleanest implementation. This adjustment was indeed missing in the last Coldfire version and so caused either a warning or an error - CW7.2 is very strict (at least with the project settings used) and so choses an error - other compilers may generate a warning and others just ignore it. In any case it has been corrected like this.

What I found is that CW7.2 is making an error in the USB interrupt routine - when I tried with CW7.1 (and some other compilers) it was OK. So I looked into this and identified the following problem and a workaround for it.

The code is as follows:

    while ((ucUSB_Int_status = (unsigned char)(INT_STAT & INT_ENB)) != 0) { // read present status
        if (ucUSB_Int_status & ~TOK_DNE) {


The main loop stays in the interrupt routine as long as there are enabled interrupt sources pending. When this is the case there is a check to see whether it is a TOK_DNE or any other type (bus state changes). It is expected that the check is therefore if (ucUSB_Int_status & 0xf7) since TOK_DNE is 0x08.
The first interrupt that arrives is a USB_RST (0x01) and so it is expected that the first check causes the reset handler to be executed (not a token interrupt) but this is never true. I looked at the code generated and see the following

moveq #0,d4
move.b d1,d4
move.l d4, d3             in case of the reset bit pending the value in  d3 ix 0x01
bclr #3, d3                this instruction does a test of the bit 3 (that is the TOK_DNE bit) and the sets this bit to zero
beq.w ....
            this branch is conditional on the zero bit which was set depedning on the state of bit 3 in the last instruction

If I have understood this correctly the code that the compiler has generated is wrong since it is actually setting the brach condition based on the TOK_DNE bit which is not what the c code wants (it wants it based on all other bits apart from this one...)

A work around that avoids this compiler error is to use a second variable:

    register unsigned char ucIntTest;

    while ((ucUSB_Int_status = (unsigned char)(INT_STAT & INT_ENB)) != 0) { // read present status
        ucIntTest = (ucUSB_Int_status & ~(TOK_DNE));
        if (ucIntTest != 0) {


The use of an intermediate variable separets the mask and the branch check and then CW7.2 gets it right.


Out of interest I checked what CW7.1 did with the original code and it looks like this:

moveq    #0,d5
move.b   d1,d5
move.l   d5,d3
bclr     #3,d3
tst.l    d3
bne.w   ....


Notice that it has an additional test and doesn't directly use the result of the bclr, which is then correct.



Then I tested another very simple workaround that also did it for CW7.2

    while ((ucUSB_Int_status = (unsigned char)(INT_STAT & INT_ENB)) != 0) { // read present status
        if (ucUSB_Int_status & (USB_RST | USB_ERROR | SOF_TOK | SLEEP | RESUME | ATTACH | STALL)) {

moveq    #0,d4
move.b   d1,d4
move.l   d4,d3
bclr     #3,d3
tst.b    d3
beq.w ...


This is however rather surprising since it looks as though tthe compiler to still use the bclr (it understands that all other bits are set) but it then correctly checks the result for the branch... the use of ~ had presumably caused some confusion: Very strange but hopefully the problem is solved like this!

Regards

Mark

P.S. In your project you had the GLCD active, which can presumably be removed so that the GLCD task is not trying to initialise a display that is probably not attached.


Offline quentin

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: USB Problem
« Reply #6 on: June 11, 2012, 09:34:59 AM »
Hi Mark,
thank you for your explanation.