FRDM-K64K host_msd_fatfs USB not detecting device

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

FRDM-K64K host_msd_fatfs USB not detecting device

Jump to solution
2,937 Views
neilporven
Senior Contributor I

Hi everyone,

I am using the demo app host_msd_fatfs_frdmk64f to write my USB driver.  After much headaches

troubleshooting, etc... I got the project to do a usb_host_init and usb_host_register_driver_info.

I also have it running, but unfortunately when I insert a USB stick the code seems not to detect it.

I keep getting case USB_DEVICE_IDLE and the g_mass_device[i].state_change = 0.  I believe that 

it could be an issue with the interrupt of the USB.  I would like to know where does the demo software

setup the interrupt settings for the USB (USBx_INTEN).

Also, if I run the project through the P&E multilink + Kinetis KDS on the FRDM-K64F evaluation board and

I place a breakpoint inside USB_DEVICE_ATTACHED where the demo project is called from and I stick a USB

stick the software never transitions from  USB_DEVICE_IDLE?  Another interesting thing, if I place a USB device

that detects if power is present on the J22 connector (K64 USB), it shows no power on the device. I have J21

jumped and R72 with a zero OHM shorted, just in case someone is wondering.  I am powering the board through

the J27 connector.

Thank you,

Neil

0 Kudos
1 Solution
2,124 Views
neilporven
Senior Contributor I

Hi Daniel,

I found why my custom board was not detecting the attachment of the USB stick.  Apparently, the following two lines of code are needed:

OS_Task_create(USB_task, NULL, 4L, 4000L, "task_start", NULL);
OSA_Start();

I don't understand what the above lines of code do?

I did find that after the call from OSA_Start(), it never returns back.  I do see that it is locked inside the APP_task() performing the different cases, which is great for the detection to occur, but at some point I need for it to get out so that I can service other routines in my application.  Can you exlplain what the above two lines of code do and how can I make OSA_Start() return?

Thanks,

Neil

View solution in original post

0 Kudos
26 Replies
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Neil:.

I would suggest you check the jumper settings

J21  1-2,   When the FrdmK64 board is operating in USB host mode,  J21 must be shunt to supply 5V power from VBUS.

After you download the program to the board, power off the target and then connect device.

I did a quick check with this demo with Frdm-K64 board, the console output is like this. Have you modified the source code?

pastedImage_1.png

Regards

Daniel

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Hi Daniel,

I have a FRDM-K64F board which I made the modifications to use the JTAG connector and I am able

to place breakpoints and see the transitions from IDLE to ATTACHED. Unfortunately, after the state

transitions to USB_DEVICE_INTERFACE_OPENED and I let the fat_demo() run, it doesn't send anything

to RealTerm.  I don't know if by making the board modification:

                                                NOTE
To use an external debugger, such as J-Link, you may need to disconnect
the OpenSDA SWD from the K64. To do this on the FRDM-K64F board,
cut the shorting trace which connects the pins of jumper holes on
connectors J8 and J12.

and cutting the short trace J12 (SWD_DIO_TGTMCU), if it is the cause for the failed communication to RealTerm? 

Daniel, I was wondering if you know what triggers the change of state?  Is it an interrupt (which one/where)?

Is it a dedicated I/O input pin(which one/where)?

Thanks,

Neil

0 Kudos
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Neil:

Do you mean the enumeration process state? It is triggered by event.

Please refer to file usb_host_devices.c.

 USB_HostProcessState.

I don't think the short trace will result in the failed communication, but I will have a try tomorrow.

Have you tried another u disk?

Regards

Daniel

0 Kudos
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

I tried this with J-link, I can see the console output.

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Sorry Daniel, We have been dealing with hurricane Irma and haven't been able to respond.

Can you tell me  which traces do you have cut on your board?

I place a break point on usb_demo(), then once my RealTerm communication software is ready, I let it

run. Is this how you're doing it?

Can you tell me where does usb_host_devices.c exist in the project or where is it being called from?

Does USB_HostProcessState exist inside usb_host_devices.c?

Thank you,

Neil

0 Kudos
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Neil:

Please refer to  SDK_2.2_FRDM-K22F\middleware/usb_1.6.3\host\usb_host_devices.c, and Function USB_HostProcessState exists inside this file.

When you attach your device, USB_HostKhciIsrFunction will trigger a USB_KHCI_EVENT_ATTACH event, it will finally call  USB_HostProcessState to enumerate.

Regards

Daniel

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Hi Daniel,

I am not sure why you are referring to SDK_2.2_FRDM-K22F\middleware/usb_1.6.3\host\usb_host_devices.c?  I am using demo

extension.jpg

During the initialization process of the demo, I noticed that the following function _usb_khci_task_create(usb_host_ptr) returns USB_OK,

but when I run my software the same function _usb_khci_task_create(usb_host_ptr) returns USBERR_ERROR. This is returned by the 

following function:

*FUNCTION*-------------------------------------------------------------
*
* Function Name : _usb_khci_task_create
* Returned Value : error or USB_OK
* Comments :
* Create KHCI task
*END*-----------------------------------------------------------------*/
uint32_t task_id;
static usb_status _usb_khci_task_create(usb_host_handle handle)
{
//usb_status status;
//task_id = _task_create_blocked(0, 0, (uint32_t)&task_template);
task_id = OS_Task_create(USB_KHCI_TASK_ADDRESS, (void*)handle, (uint32_t)USBCFG_HOST_KHCI_TASK_PRIORITY, USB_KHCI_TASK_STACKSIZE, USB_KHCI_TASK_NAME, NULL);

if (task_id == (uint32_t)OS_TASK_ERROR)
{
return USBERR_ERROR;     <-----------------------------------------    Here !!!!!!!!!!!!!!!!!!!!!!!!!!
}

//_task_ready(_task_get_td(task_id));
//OS_Task_resume(task_id);

return USB_OK;
}

Inside OS_Task_create function there is another call which brings in param, comparing what my software shows for this parameter vs.

NXP demo, only BDTPAGE1 and Reserved 15 have different values.  I don't know if that is because my custom board processor is

the MK64FN512 vs the FRDM-K64F board processor which is MK64FN1M.   

Any idea why this function could be reporting the USBERR_ERROR?

Thank you,

Neil

0 Kudos
1,675 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Neil:

Sorry, I tested with FrdmK64 with KSDK2.2 before. Now I tested with KSDK1.3, the result is also PASS. The output is as below.

pastedImage_1.png

Regards

Daniel

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Hi Daniel,

Update on the issue on OS_Task_create function.  OS_Task_create internal call which returns the USBERR_ERROR looks for

g_freeTaskControlBlock to see if it is loaded with information or 0x00.  After much tracking, I find that there is a function called

OS_Task_init, which loads g_freeTaskControlBlock with a value.  In the test software OSA_Init() is called right after Hardware_init()

and this is where OS_Task_init() is called and g_freeTaskControlBlock loaded.  Now, that portion of the software is not returning an

error.

I am still having an issue detecting attachment of the USB, I don't know what could be happening, but I am suspecting that there is

a USB setup issue.  Let me know your thoughts on this?

Thanks,

Neil

0 Kudos
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Neil:

I would suggest you print something before usb_host_init, since you are suspecting the terminal communication problem.

add the below line before usb_host_init, and while debugging you will see this on console if communication is OK

USB_PRINTF("\r\nTesting    ");

pastedImage_1.png

If communication is OK, then we continue to check the USB detecting issue.

Note:  the demo I am testing is

KSDK_1.3.0\examples\frdmk64f\demo_apps\usb\host\msd\msd_fatfs\bm\

Regards

Daniel

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Hi Daniel,

I included the following line to the demo project as you suggested:

Test Line.jpg

That line does not appear on the Console as you can see from above.  Here is my configuration

Startup settings:

Startup.jpg

As you can see Semihosting Settings is Enabled and GCB client is checked.  I am going to search

today to see if I am missing something to be able to write to the console.

Note: I am also using the same as you

         KSDK_1.3.0\examples\frdmk64f\demo_apps\usb\host\msd\msd_fatfs\bm\

Let me know if you can see anything from my to screen shots or if you need more information?

Thanks,

Neil

0 Kudos
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

Please check whether the dbg_uart_init() function executed or not,   in main.c

pastedImage_1.png

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Hi Daniel,

I am trying to see why the demo project is not writing to the console.  I am following the steps here:

Semihosting for Kinetis Design Studio V3.0.0 and GNU ARM Embedded (launchpad) | MCU on Eclipse 

Daniel maybe you might know, but the above example was done for KDS V3.0.0, but as you know I am using KDSV3.1.0.

I don't know if the semihosting has changed from V3.0.0 to V3.1.0.  If you go into the properties of the demo project you have

the following under:   Cross Arm C Linker->Miscellaneous     you have the following

Properties.jpg

Now, I took out -specs = nano.specs from the tag and as you can see, I checked the box above.  This didn't solve

anything, but I am following the example above.  The other interesting thing, is that the demo has the following in the

tag:  static  -Xlinker --defsym=__stack_size__=0x0400  -Xlinker --defsym=__heap_size__=0x8000, which is not explained

in the above example.  In the following pdf : How to use printf() to print string to Console and UART in KDS2.0 

1.3 Use printf() in Bare Board Project
Create a bare board project: uncheck the “Kinetis SDK” and “Processor Expert” selection,
keep other configurations as default. From the linker file we can see that the default size of
stack and heap is 0x400. Generally, it can meet our requirement. If it can’t, we can increase
it in the linker file.

Somewhere else its specified that heap_size = 0x0C00

Now, moving to your question whether dbg_uart_init() is executed, Yes it is executed.  I have not stepped

into it, but I imagine this is where all the UARTs are configured.  I don't see why it should have an issue, since

this demo was meant to work with the FRDM-K64F board, but it doesn't hurt to check.

At this point, I am still not able to see anything written to the console, nor can I see anything being written to the Terminal

software.  If you can think of something please let me know, because If I can't even run a demo that is suppose to be working

how am I suppose to follow the demo and develop my application?

Thank you,

Neil

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Hi Daniel,

After stepping in dbg_uart_init() I ran into the following:

/* See fsl_debug_console.h for documentation of this function.*/
debug_console_status_t DbgConsole_Init(
uint32_t uartInstance, uint32_t baudRate, debug_console_device_type_t device)
{
if (s_debugConsole.type != kDebugConsoleNone)
{
return kStatus_DEBUGCONSOLE_Failed;
}

/* Set debug console to initialized to avoid duplicated init operation.*/
s_debugConsole.type = device;
s_debugConsole.instance = uartInstance;

/* Switch between different device. */
switch (device)

as I am stepping through the code, it falls into:  return kStatus_DEBUGCONSOLE_Failed;  the return takes me to the end of this function

which returns kStatus_DEBUGCONSOLE_Success???  How can the code find that something failed, then its return be successful????

If I look into s_debugConsole.type it equals to kDebugConsoleUART, so it never makes it to the switch statement.  This could explain why

UART0 which I believe is where TX/RX will be setup to write to the Terminal software takes place.  So the big question is, why is a demo

software failing to properly set this settings and a bigger question is why does this work for you and not for me??????????

I don't understand????? Please help this is frustrating me

Neil

0 Kudos
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

can you check the output from the terminal?

0 Kudos
1,676 Views
neilporven
Senior Contributor I

Hi Daniel,

I was able to find what was happening with my FRDM-K64F eval board.  Sometime ago I wanted to work directly with the 

K64F and wanted complete isolation from the OPENSDA side.  I had cut some traces, which I place jumpers just in the event I had

to go back.  Unfortunately for some reason, I also removed R38 from the board and I had forgotten about it.  From the FRDM-K64F

here is the portion of the schematic:

R38.jpg

I circled R38 in yellow.  Today I placed a zero ohm resistor to complete the circuit and the demo is now communicating to

the Terminal software.  I will re-visit today the portion of code that was reporting a failure to see if that has changed now and hopefully

tie the loop.

I am still having issues though detecting the USB stick on my custom board and would like to know if you can guide me where 

this happens in the demo software?  Where in the demo is the trigger?

Thanks,

Neil

0 Kudos
1,676 Views
danielchen
NXP TechSupport
NXP TechSupport

Glad to hear that the communication works now.

Please refer to the attached USB_Stack_Supported_Peripheral_List.pdf, it lists the peripheral that are verified with the USB host stack.  If your usb disk is not recognized, you can check whether it is in the supported list. Can you change other usb device to try ?

For who triggers , it should be similar to USB stack in KSDK2.2, but I need to double check it

0 Kudos
1,675 Views
neilporven
Senior Contributor I

Hi Daniel,

If I am using a 16MHz crystal vs the 50MHz signal for the EXTAL0/XTAL0, do you know all the different entry points that needs to change

on the demo software?

Thanks,

Neil

0 Kudos
1,675 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Neil:

The USB clock should be configured to 48Mhz.

Please refer to the reference manual K64P144m120SF5RM.pdf.  p188

pastedImage_1.png

What is your USB clock source? I would suggest check the Freescale KSDK USB Stack Porting New Platform User's Guide. It is under the installation folder

KSDK_1.3.0\doc\usb\

Regards

Daniel

0 Kudos
1,675 Views
neilporven
Senior Contributor I

Hi Daniel,

The USB clock source is 48MHz.  I will take a look at the documentation you suggested.  

Have you found what/where/function  that triggers the USB detection?

Thanks,

Neil

0 Kudos