USB COMMAND_DONE semaphore not working

cancel
Showing results for 
Search instead for 
Did you mean: 

USB COMMAND_DONE semaphore not working

1,500 Views
arnogir
Senior Contributor II

Hello

I'm facing a problem on USB stack.

Fisrt, my configuration:

K70, MQX 4.1

I try to update usb files from MQX4.2 (not usbv2, just Usb) but problem still present.

So when USB is plugged, like done in HVAC demo, I do following:

_io_usb_mfs_install(..)

usb_fs_ptr->DEV_FD_PTR = fopen(block_device_name, 0);

Wtih the same key, sometime return will be null, sometime return will be OK.

I debug on under layer:

_io_fopen -> _io_usb_mfs_open -> _io_usb_mfs_open_internal.

In this function, we wait a semaphore (_lwsem_wait_ticks(&info_ptr-> COMMAND_DONE, ...)

This semaphore is post in _io_usb_ctrl_callback.

When all work, in  io_usb_mfs_open_interna we wait COMMAND_DONE, then the _io_usb_ctrl_callback is called (from _task_build_internal/_usb_khci_task/_usb_khci_process_tr_complete_io/_usb_ctrl_callback.

But when not working, the function _io_usb_ctrl_callback is called before the fopen call the lwsem wait.

So the post not trig the wait semaphore...

To resume, if the _lwsem_post arrive before the _lwsem_wait_ticks, we will blocked!

This semaphore behavior is Ok? Could you help me to find frome where problem comes?

Thank you

0 Kudos
17 Replies

932 Views
arnogir
Senior Contributor II

Seems I change all this, No problem occurs. (Never!)

But when I change frequency from 120MHz to 150Mhz, problems occurs.

On USB, the difference are on _bsp_usb_io_init. But why because it seems 50MHz is acceptable for USB??

#if (MQX_CPU == PSP_CPU_MK70F150M)
/* PR#51: Clock up from120MHz to 150MhZ */
/* Configure USB divider to be 150MHz * 1 / 3 = 50 MHz */
SIM_CLKDIV2_REG(SIM_BASE_PTR)
&= ~(SIM_CLKDIV2_USBFSDIV_MASK | SIM_CLKDIV2_USBFSFRAC_MASK);
SIM_CLKDIV2_REG(SIM_BASE_PTR)
|= SIM_CLKDIV2_USBFSDIV(2);// | SIM_CLKDIV2_USBFSFRAC_MASK;

#else /* (MQX_CPU == PSP_CPU_MK70F120M) */
/* Configure USB divider to be 120MHz * 2 / 5 = 48 MHz */
SIM_CLKDIV2_REG(SIM_BASE_PTR)
&= ~(SIM_CLKDIV2_USBFSDIV_MASK | SIM_CLKDIV2_USBFSFRAC_MASK);
SIM_CLKDIV2_REG(SIM_BASE_PTR)
|= SIM_CLKDIV2_USBFSDIV(4) | SIM_CLKDIV2_USBFSFRAC_MASK;
#endif

0 Kudos

932 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Arnaud Girard:

Glad to hear it can work when you change frequency to 48M.

USB clock should be configured to 48Mhz.

Please refer to the reference manual for K70P256M150sf3. Page 216

pastedImage_1.png

Have a great day!

Regards

Daniel

0 Kudos

932 Views
arnogir
Senior Contributor II

Hi,

Ok, I haven't check that, I just check the USB v2 which indicate we can work up tp 60MHz:smileyblush:

I had try to change the Clock configuration to make a check during my research,

But with any other value than 1/3, USB never working:smileyconfused:

On 150MHz CPU clock, the value was like bellow. May be there are forbidden couple of value?

Which value can I set with 150MHz CPU clock to have a working USB?

SIM_CLKDIV2_REG(SIM_BASE_PTR) &= ~(SIM_CLKDIV2_USBFSDIV_MASK | SIM_CLKDIV2_USBFSFRAC_MASK);
SIM_CLKDIV2_REG(SIM_BASE_PTR)
|= SIM_CLKDIV2_USBFSDIV(2);// | SIM_CLKDIV2_USBFSFRAC_MASK;

Else, the configuration macro CPU_USB_CLK_HZ_CONFIG_0 is set to

PE_CpuClockConfigurations.cpu_usb_clk_hz, but this parameter is never used??..

0 Kudos

932 Views
arnogir
Senior Contributor II

Hi,

Last week, on production line, I was about half board which had a USB key difficult to running.

Today, With modification done, at this time, all board running correctly:

- Clock from 150MHz to 120MHz..

- BSPCFG_DSPI1_USE_DMA à 0

- MQX_USE_LWMEM_ALLOCATOR 1

- MQX_USE_MEM 1

....

0 Kudos

932 Views
arnogir
Senior Contributor II

Hello

I'm still investigating.

I had found some problem but all is not yet perfect:

- I had a "printf("%/n xxxxx"); => the "%" was not correct, then with compilation optimisation to "-03" this make crash sometime.

- Imade my test with two different configuration. the fist with OS Usbh on "Debug" configuration, the second on "Release" configuration.

- I update My Mqx/Usb directory with USB from MQX4.2 (On this project, I'm on MQX 4.1.1) => there is some difference on mem initialisation size(pass _PTR or not...)

- I commented #define KHCICFG_4BYTE_ALIGN_FIX

So with "Debug" configuration, USB work (Sometime the USB key is not recognize, but if I restart board, according I plug the key before or after the Power On, according the Key manufacturer itself, I always success). With "Release" configuration, the USB not work fine.

Then the UsbH code have Something bad with Compiler optimization set to -o3.

So I test on HVAC demo on TWRK70, problem not occurs on it. Then it is with my specific application. I think I had a bad alignment or bad initialisation variable which not important without optimization, but it is with optimization....

The question is: How debug this!

0 Kudos

932 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Arnaud:

Which USB Flash driver you are using ? Have you tried other USB disks?

Regards

Daniel

0 Kudos

932 Views
arnogir
Senior Contributor II

Hello

I'm using Usb (v1, not v2) KHCI MQX 4.1.1. I test with 4 different USB stick.

I'm currently trying with following change:

- Return from 150MHz to 120Mhz CPU Clock (USB from 50MHz to 48Mhz)

- BSPCFG_DSPI1_USE_DMA 0

- MQX_USE_LWMEM_ALLOCATOR 1 (Tower k70 User config set it)

- MQX_USE_MEM  1 (Tower k70 User config set it)

- Add define of _HOST_DEBUG_

I'm compiling it before test!...

May be try with MQX_USE_UNCACHED_MEM  set to 1... (I don't know the impact)

-Also I would try by update MFS/Ffs from MQX 4.2.0.2

0 Kudos

932 Views
danielchen
NXP TechSupport
NXP TechSupport

I suggest you try to enbale USBCFG_HOST_BUFF_PROPERTY_CACHEABLE   in usb_host_ocnfig.h   , to see whether it helps

Regards

Daniel

0 Kudos

932 Views
arnogir
Senior Contributor II

Sorry but I not found USBCFG_HOST_BUFF_PROPERTY_CACHEABLE neither usb_host_config.h :-(

0 Kudos

932 Views
danielchen
NXP TechSupport
NXP TechSupport

I am not sure whether it can fix your issue ,   but when using DDR build, it's using cache, we need to enable USBCFG_HOST_BUFF_PROPERTY_CACHEABLE.  Sorry this file is in usb_v2.   I think in old usb stack, there should be a similar macro to define this.

0 Kudos

932 Views
arnogir
Senior Contributor II

I not find an equivalent in Usb v1

0 Kudos

932 Views
arnogir
Senior Contributor II

Hi,

I comment the following define

KHCICFG_4BYTE_ALIGN_FIX

Then HVAC demo work on Tower K70 in both configuration( SDramData and DDRData).

I just remember I had the same problem 2 year ago:

https://community.nxp.com/message/455760?commentID=455760#comment-455760

Then a part of the problem was resolved by comment the #define. But it seems this not solve all.

So I restart from scratch on my investigations! :-(

0 Kudos

932 Views
arnogir
Senior Contributor II

Waiting for someone to answer me, I activate the LOG USB.

I attached these 2 Log file.

 - The Log_Ok.txt generatetd when Key is plugged and is correctly mounted (SdrRam Data configuration)

 - The Log_Not_Ok.txt generatetd when Key is plugged and is not correctly mounted (DDr Data configuration)

 

WHen it is not Ok, the problem come from _usb_host_ch9_clear_feature which is called. This function is called because function _usb_khci_atom_tr is called in  _usb_khci_task, but in it, the swicth on bd is 0x0e:

res = KHCI_ATOM_TR_STALL;

The bd is the famous buffer placed in RAM (0x1FFF 0000). I suspect some other think which come write in it in DDR setup case. But who and why???....

0 Kudos

932 Views
arnogir
Senior Contributor II

After many test, this confirm all work correctly when use sram linker option, and not working on ddrdata linker.

I need ddram for my application( PEG) I try many combination of mapping but without succes,

I can't find which element in DDR configuration make fail the USB.

Is Somebody can reproduce the problem? and help me to find the good configuration?

=> TWRK70 with MQX 4.1.1 and HVAC demo.

0 Kudos

932 Views
arnogir
Senior Contributor II

Hello

I'm always investigating on my Bug.

Then I made many manipulation:

1) On Tower K70 try the HVAC demo in SRAM Debug mode : Usb mount file system without any problems (Ok)

2) On Tower K70 try the HVAC demo in DDRAM Debug mode : Init of USB is Ok, but when I plug a Key, never usb_host_mass_device_event is called, then USB and file system is not Mount !!!! (NOT OK)

3) I try with my project which link on the same OS than the previous to be running on Tower system. I reduce it to just start the USB_Task. I linked with USB file from HVAC demo =>same result than point 1, its is ok.

4) Same like 3, but now I used m written US driver (derived from HVAC demo USB file but with our own coding rules etc..). This is Ok, it work correctly => same result than point 1. => The my Own USB driver is Ok.

5) Same than 4 but on "DDRData" => Same result than 2 => No callback function is called.

Then these tests allow to say:

- Why on HVAC demo USB not working in DDRData configuration???

- My USB driver work correctly.

Then I will check difference between original OS (tower K70) and my OS configured for my target. But it is strange demon not working in DDRDAta???

0 Kudos

932 Views
arnogir
Senior Contributor II

Note

Like in the HVAC exemple, there are a delay(500) just before the fopen.

So I try by removing this delay, then the first lwsem is always OK, but after, there are another lwsem, which will failled.

Help please!

0 Kudos

932 Views
arnogir
Senior Contributor II

Hi

I try to activate KHCI_DEBUG, but error occurs on compile because we need the type TR_MSG_TYPE. But it is never define!

:-(

Anybody has some idea to help me to find the problem?

0 Kudos