MCF52213 USB doesn't work

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF52213 USB doesn't work

2,281 Views
gaminn
Contributor IV

Hello,

last week I posted here a question about MCF52213 USB (I downloaded USB stack with PHDC - http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MEDICALUSB and I wasn't able to detect any logic level on USB_DM and USB_DP pins).

 

Now I downloaded CMX USB stack, modified USB host mass storage example (it was designed for MCF52221) and run it on my MCF52213. It's like with the USB stack mentioned above - no logic level on USB pins (they should be pulled down - the routine that enables pull downs is executed). Also when I attach my USB flash drive to MCF52213 it does nothing - USB flash drive only pulls up on USB_DM pin, but no communication comes after.

 

I really don't know where to look for any problem. VDDUSB is tied to VDD of the MCU (so it has 3.3 V), VSSUSB in on GND. MCU is clocked using 8 MHz crystal multiplied by 6 by PLL (= 48 MHz). USB module clock source is system clock (so it should be 48 MHz).

 

Please give me any suggestions.

 

Martin

Labels (1)
0 Kudos
Reply
8 Replies

1,125 Views
JCRib
Contributor II

Hello Martin,

 

I'm going to use a MCF51JM along with the CMX stack to implement USB host functions for mass storage devices.

 

Can you tell me if it's possible to get it working:

 

1) without using a crystal (the host needs a 48MHz clock?)

 

2) with an 8 MHz crystal and multiplying it by 6 (your first MCU was bad, so that could have been the problem)

 

 

Best regards,

 

Jose

0 Kudos
Reply

1,125 Views
gaminn
Contributor IV

Please see the code (project in CodeWarrior) I load into MCF52213.

0 Kudos
Reply

1,125 Views
gaminn
Contributor IV

I asked Freescale Technical Support - they told me to use external 48 MHz crystal and external pull downs.

 

So now I have 48 MHz crystal and I run USB module with oscillator clock (MCF_USB_USB_CTRL = MCF_USB_USB_CTRL_CLKSRC_OSC:smileywink:.  System clock is 48 MHz (oscillator output is divided by 6 and multiplied by 6 by PLL). SYNSR register has 0x38 value, so oscillator works and PLL is sourced by it. Another proof that system clock (and also oscillator clock) is 48 MHz is that I configure UART module and it works on desired 115200kbaud rate.

 

I added 39 ohm resistors on USB_DM and USB_DP lines and I pulled them down usign 18 kohm resistors.

 

But my problem remains - when I connect 3.3 V on either USB_DM or USB_DP (I hope it simmulates attaching USB device), nothing happens - ATTACH bit in INT_STAT register of USB module is not set. I have oscilloscope connected to USB_DM and USB_DP pins and there are no changes on the lines (except when I connect 3.3 V to simmulate attaching USB device).

 

Please help me, it is more than one month since I started to make USB module working but no success. What do I do wrong? Here is CW project (5.9).

 

Thank you

 

Martin

0 Kudos
Reply

1,125 Views
gaminn
Contributor IV

OK, my MCU was bad - it had broken USB module (even the rest of it worked well) - I replaced it by a new one and USB module works. Now I can see SOF tokens every 1 ms on the bus when I attach my USB flash drive.

 

But MCU is not able to enumerate the flash drive. As I mentioned above, I use CMX USB stack (MSD host example for MCF52221). Immediatelly after attaching my USB drive the program in MCU reaches following code (it goes inside if):

 

 

    if (MCF_USB_INT_STAT & MCF_USB_INT_STAT_STALL)    {        /* device has an error */      MCF_USB_INT_STAT=MCF_USB_INT_STAT_STALL;      MKDBG_TRACE(ev_got_stall, ep);      tr_error=tre_stall;      return((hcc_u16)-1u);    }

 

 

It's piece of code in usb_host_start_transaction() function. Because of this error (tre_stall) initialization of the device fails. Initialization ends by sending print("Mass-storage driver initialization failure.\r\n"); print("Please connect another device.\r\n"); through RS232.

 

What cause the problem? The code I use was intended to be used on MCF52221 and 80 MHz system clock. My MCU has 48 MHz system clock, so I modified provided timer function (now it times correctly - tested). But something else is bad probably...what?

 

Martin

 

0 Kudos
Reply

1,125 Views
gaminn
Contributor IV

Hello,

 

I still have the problem with USB host using CMX stack. After I connect USB drive, I can see it pulls up USB_DP line, after usb bus reset comes for 11 ms (as it is in host_reset_bus() function). But there is no communication between MCF52213 and usb drive after that. Host only starts to transmit SOF packets immediatelly after the reset.

 

During reset, there is 2 ms rise of voltage on USB_DM pin (marked ??? on the picture). Maybe this is the problem. But really don't know how to fix it.

 

 

Thank you

 

Martin

 

 

 

 

0 Kudos
Reply

1,125 Views
gaminn
Contributor IV

I have noticed there is a debug possibility implemented in the CMX USB stack. I'm posting here the debug log - hope somebody can help me.

 

0 Kudos
Reply

1,125 Views
gaminn
Contributor IV

I'm trying to write my own USB host but I'm not able to send any token. First, usb_host_init() function is called, then program waits in usb_host_scan_for_device() till device is attached. After device is attached I can see 11 ms reset on the USB bus, but USB Setup token which should be sent after never comes. Program loops forever in while loop "Wait for transaction end" (down in the code). Please, what is the problem? Thank you.

 

 

void usb_host_init(void) {  /* Clear all pending events. */  MCF_USB_OTG_INT_STAT = 0xff;    /* select USB clock source */  MCF_USB_OTG_USB_CTRL = MCF_USB_OTG_USB_CTRL_CLK_SRC_OSCCLK;  /* use first rx and tx buffer */  MCF_USB_OTG_CTL |= MCF_USB_OTG_CTL_ODD_RST;    /* set BDT address */  MCF_USB_OTG_BDT_PAGE_01 = (uint8)(((uint32)BDT_BASE) >> 8);  MCF_USB_OTG_BDT_PAGE_02 = (uint8)(((uint32)BDT_BASE) >> 16);  MCF_USB_OTG_BDT_PAGE_03 = (uint8)(((uint32)BDT_BASE) >> 24);  /* Set SOF threshold */  MCF_USB_OTG_SOF_THLD = 74;    /* Enable pull-down resistors. */  MCF_USB_OTG_OTG_CTRL = MCF_USB_OTG_OTG_CTRL_DP_LOW | MCF_USB_OTG_OTG_CTRL_DM_LOW | MCF_USB_OTG_OTG_CTRL_OTG_EN;  /* Enable host operation mode. */  MCF_USB_OTG_CTL = MCF_USB_OTG_CTL_HOST_MODE_EN; }int32 usb_host_scan_for_device(void){  volatile uint32 x;  uint8 ep = 0;  uint8 usb_buffer[20] = "";  /* If we can not clear the attach flag, then a device is connected. */  MCF_USB_OTG_INT_STAT = MCF_USB_OTG_INT_STAT_ATTACH;  /* Some delay is needed between clearing the ATTACH flag, and checking     it again. Unfortunately there is no information about the length of      the delay. */  for(x=0; x< 6000; x++);  if (MCF_USB_OTG_INT_STAT & MCF_USB_OTG_INT_STAT_ATTACH)  {    usb_host_ms_delay(100);       print("Device attached.\n\r");        /* clear low speed bit to make JSTATE detection consistent. */ MCF_USB_OTG_ADDR=0; /* let settle D+ and D- to the right state */ usb_host_ms_delay(1); /* Check if device is low or high speed. */ if ((MCF_USB_OTG_CTL & MCF_USB_OTG_CTL_JSTATE) == 0) {   MCF_USB_OTG_ADDR = MCF_USB_OTG_ADDR_LS_EN;   }    // reset    MCF_USB_OTG_CTL |= MCF_USB_OTG_CTL_RESET; usb_host_ms_delay(11); MCF_USB_OTG_CTL &= ~MCF_USB_OTG_CTL_RESET; MCF_USB_OTG_INT_STAT = MCF_USB_OTG_INT_STAT_USB_RST;      print("Bus reset.\n\r");   BDT_BASE[((ep << 5) + (1 << 4) + (0 << 3)) >> 3] = 0x00080080;   BDT_BASE[(((ep << 5) + (1 << 4) + (0 << 3)) >> 3) + 1] = (uint32) usb_buffer;   // Endpoint 0   MCF_USB_OTG_ENDPT0 = 0x4D;      // Set address   MCF_USB_OTG_ADDR &= ~MCF_USB_OTG_ADDR_ADDR(0xFF);   MCF_USB_OTG_ADDR = MCF_USB_OTG_ADDR_ADDR(0x00);      // Send token   MCF_USB_OTG_TOKEN = MCF_USB_OTG_TOKEN_TOKEN_ENDPT(ep) + MCF_USB_OTG_TOKEN_TOKEN_PID(USB_TOKEN_SETUP);      // Wait for transaction end   // TOK DNE bit is set when the current token being processed has completed, so wait until it is set   while(!(MCF_USB_OTG_INT_STAT & MCF_USB_OTG_INT_STAT_TOK_DNE));       MCF_USB_OTG_INT_STAT |= MCF_USB_OTG_INT_STAT_TOK_DNE;       print("Setup token sent.\n\r");      while(MCF_USB_OTG_INT_STAT & MCF_USB_OTG_INT_STAT_ATTACH)    {     MCF_USB_OTG_INT_STAT = MCF_USB_OTG_INT_STAT_ATTACH;     for(x=0; x< 6000; x++);    }      print("Device dettached.\n\r");     }}

 

 

 

0 Kudos
Reply

1,125 Views
DMV
Contributor I

See Post

https://community.freescale.com/message/67885#67885

 

Seems like same issue I found in JM128 CMX USB Lite?

0 Kudos
Reply