USB0 - K60 - MQX4.2 - Only works with debugger attached.

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

USB0 - K60 - MQX4.2 - Only works with debugger attached.

Jump to solution
6,284 Views
jasonscott
Contributor IV

Good Afternoon,

Hopefully someone can give me a pointer or two on the enumeration of USB0 on the k60.

Brief background:

MQX Version: 4.2 Not using process expert.

Custom board: using the k60 processor has been tested and the USB circuit works with our boot-loader fine.

Using USB Host.

Every time i plug in a USB stick the KHCI task detects the usb as being attached and returns that it has been successful, but the usb_host_mass_device_event is not triggered.

However, it works fine with the debugger attached, and i am able to get usb_host_mass_device_event to trigger as expected.

I suspect that the clock is not properly being enabled to the usb module without using the debugger.

Here is my BSP USB init. 

Can anyone tell me what I am overlooking?

_mqx_int _bsp_usb_io_init
(
void
)
{
#if PE_LDD_VERSION
/* USB clock is configured using CPU component */

/* Check if peripheral is not used by Processor Expert USB_LDD component */
if (PE_PeripheralUsed((uint32_t)USB0_BASE_PTR) == TRUE) {
/* IO Device used by PE Component*/
return IO_ERROR;
}

/**
* Workaround for Processor Expert as USB clock divider settings has been removed
* from __pe_initialize_hardware() and Cpu_SetClockConfiguration() functions
* Needs to be replaced by dynamic calculation of dividers.
* SIM_CLKDIV2: USBDIV=1,USBFRAC=0
*/
SIM_CLKDIV2 = (uint32_t)((SIM_CLKDIV2 & (uint32_t)~0x0DUL) | (uint32_t)0x02UL); /* Update USB clock prescalers */
#endif

/* Configure USB to be clocked from PLL */
SIM_SOPT2_REG(SIM_BASE_PTR) |= SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK;

/* Enable USB-OTG IP clocking */
SIM_SCGC4_REG(SIM_BASE_PTR) |= SIM_SCGC4_USBOTG_MASK;

/* USB D+ and USB D- are standalone not multiplexed one-purpose pins */
/* VREFIN for device is standalone not multiplexed one-purpose pin */

/* {{START_VM_MOD*/
/* Configure Port A28 as USBPower Switch Enable */
PORTA_PCR28 = PORT_PCR_MUX(1) | PORT_PCR_SRE_MASK; /* Slow slew rate */
GPIOA_PSOR |= 1 << 28;
GPIOA_PDDR |= 1 << 28;
GPIOA_PCOR |= 1 << 28; /* Enable USB Output voltage */
/* END_VM_MOD}}*/

return MQX_OK;
}

Labels (2)
Tags (3)
1 Solution
5,745 Views
jasonscott
Contributor IV

We managed to get the USB working.

For those who are interested, it was actually an easy fix.

Adding the following line to the init_hardware before the _bsp_initialize_hardware() worked.

SIM_SCGC4_REG(SIM_BASE_PTR) &= ~SIM_SCGC4_USBOTG_MASK;

Im not sure why exactly this was the case.

The bootloader does enable the clock to the USB module, but i would have thought it would reset once the we initialized the bsp of our main application.

It is also possible to disable the clock using the same instruction in the bootloader before jumping to the application space.

Thanks for your help and ideas Daniel.

-Jason

View solution in original post

14 Replies
5,746 Views
jasonscott
Contributor IV

We managed to get the USB working.

For those who are interested, it was actually an easy fix.

Adding the following line to the init_hardware before the _bsp_initialize_hardware() worked.

SIM_SCGC4_REG(SIM_BASE_PTR) &= ~SIM_SCGC4_USBOTG_MASK;

Im not sure why exactly this was the case.

The bootloader does enable the clock to the USB module, but i would have thought it would reset once the we initialized the bsp of our main application.

It is also possible to disable the clock using the same instruction in the bootloader before jumping to the application space.

Thanks for your help and ideas Daniel.

-Jason

5,742 Views
jasonscott
Contributor IV

So after thinking on this scenario a bit, i started to wonder.....

If the Bootloader enables the power to the usb by setting a GPIO pin high.

   Code:

    PORTA_PCR28 = PORT_PCR_MUX(1) | PORT_PCR_SRE_MASK; /* Slow slew rate */
    GPIOA_PSOR |= 1 << 28;
    GPIOA_PDDR |= 1 << 28;
    GPIOA_PCOR |= 1 << 28;

Then it jumps to the application space.

Power will be already applied to the usb before i enter the _bsp_usb_io_init function.

Could this cause the current scenario i am seeing?

I made an attempt to reverse this by adding the following lines of code to the function.

//Set Power on to 0.

PORTA_PCR28 = PORT_PCR_MUX(1) | PORT_PCR_SRE_MASK;
GPIOA_PSOR &= ~(1 << 28);
GPIOA_PDDR &= ~(1 << 28);
GPIOA_PCOR &= ~(1 << 28);

_time_delay(1000);

//Set Power on to 1.

PORTA_PCR28 = PORT_PCR_MUX(1) | PORT_PCR_SRE_MASK;
GPIOA_PSOR |= 1 << 28;
GPIOA_PDDR |= 1 << 28;
GPIOA_PCOR |= 1 << 28;

I did not see any positive results in this test.

Still working on a resolution.

Edit:

I even went one step farther by simply toggling the USB power using.....

if (!lwgpio_init(&USB_POWER, BSP_USB_POWER, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE))
{
printf("Initializing USB GPIO as output failed.\n");
_task_block();
}

lwgpio_set_functionality(&USB_POWER, BSP_USB_POWER_MUX_GPIO);

lwgpio_set_value(&USB_POWER, LWGPIO_VALUE_HIGH);

_time_delay(3000);

lwgpio_set_value(&USB_POWER, LWGPIO_VALUE_LOW);

This was probably more of a hardware test, but it worked and i did see the power to the USB host pin go low before initializing it.

However, still did not get the usb to enumerate.

-Jason

0 Kudos
5,742 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Jason:

I would suggest you check the following :

1.  check the reset circuit.

2.  check whether the VCC pin in your debugger still power the board while debugging?

3.  make a simple project, just toggle a GPIO, not in your usb project. capture waveform with a scope, can you get the expected result?

Regards

Daniel

0 Kudos
5,742 Views
jasonscott
Contributor IV

Hi Daniel,

1) I checked the reset circuit and that is fine.

    We also use this reset circuit to program FPGA's and that is fine as well.

2) The VCC Pin for the debugger is actually disabled through the KDS debug configuration.

3) The toggling of the GPIO was done on my part to rule out a power issue for the USB. I probably confused you more with adding that last post.

Do you have any idea why the USB would be fine for the bootloader and not fine for my main application?

I would simply use the bootloader code for the USB, but it is not using the latest mqx and from what i can tell have different methods to enumerate.

-Jason

0 Kudos
5,742 Views
danielchen
NXP TechSupport
NXP TechSupport

Do you mean the MQX usb stack not support your u-disk, but bootload  usb code support? You can change another u-disk to verify that.

Regards

Daniel

0 Kudos
5,742 Views
jasonscott
Contributor IV

Hi Daniel,

I have tried various different usb sticks and it does not seem to make a difference.

I do not think there is an issue with the USB type.

There has to be something not configured correctly on my MQX 4.2 application.

I am just having trouble narrowing it down since the KHCI task is acknowledging the presence of the USB.

It just will not enumerate.

-Jason

0 Kudos
5,742 Views
danielchen
NXP TechSupport
NXP TechSupport

If you suspect RTCS may cause this issue , I would suggest you disable RTCS to check whether this issue still happen.

Regards

Daniel

0 Kudos
5,741 Views
jasonscott
Contributor IV

Disabling the RTC by setting BSPCFG_ENABLE_RTCDEV to 0, did not fix this issue.

I still suspect either the while debugging another clock setting is used

OR

the debugger adds in extra clock cycles which allows enough time that the USB enumerates.

-Jason

0 Kudos
5,742 Views
jasonscott
Contributor IV

I will give this a try here in a bit.

I thought about doing this initially, but was not sure of the repercussions of doing so.

Let me make the change and create a new build.

-Jason

0 Kudos
5,742 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Jason:

Do you mean your board work with debugger attached, but not debugging.

or

work with debugger attached, and  debugging.

Could you please clarify it?

Regards

Daniel

0 Kudos
5,742 Views
jasonscott
Contributor IV

Hi Daniel,

I meant as in the debugger is attached and actively running & debugging the application through the KDS.

If i do not run the application using the debugger, I can not the the USB to enumerate fully.

Edit: 

I would also like to mention that the bootloader is bypassed when i use the debugger. 

The bootloader moves files from the USB to a SD card.

When that operation is complete it jumps to the application space. 

We have encountered no issues with the SD card, just on the USB side.

-Jason

0 Kudos
5,742 Views
jasonscott
Contributor IV

I would also like to mention that i am using the RTCS library as well.

I remember reading somewhere that using the RTC can cause issues with the usb.

still going strong on this issue though, but it is eating up alot of time.

0 Kudos
5,742 Views
jasonscott
Contributor IV

Id also would like someone to confirm or deny that using the debugger can some how alter the clock settings because that is what i really believe is occurring, but can find no information to support this.

0 Kudos
5,742 Views
jasonscott
Contributor IV

Also Here is the USB Host Init.

not sure if im missing something here.

_mqx_int _bsp_usb_host_init(struct usb_host_if_struct *usb_if)
{
_mqx_int result = _bsp_usb_io_init();

if (result != MQX_OK) return result;

/* Do not configure enable USB regulator for host */
// SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK;

/* reset USB CTRL register */
USB_USBCTRL_REG(USB0_BASE_PTR) = 0;

/* setup interrupt */
_bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE);

return MQX_OK;
}

0 Kudos