LPC55xx SDK: usb driver not working with compiling optimization -O2

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC55xx SDK: usb driver not working with compiling optimization -O2

1,030件の閲覧回数
cgarcia
Contributor II

I downloaded SDK_2.9.1_LPCXpresso55S69 from MCUXpresso SDK Builder, target board LPC55S69 EVK.

From SDK I imported usb device example: lpcxpresso55s69_dev_cdc_vcom_bm, the example is working as expected but if compile optimization is set to O2 then the demo doesn't work.

someone has some idea how to make usb device driver works even with max compile optimization?

I attached dev_cdc_vcom_bm example as reference.

Thanks,

-Carlos

ラベル(1)
0 件の賞賛
返信
4 返答(返信)

170件の閲覧回数
sajid
Contributor I

Hi, Greetings.
I'm using an LPC5516 for my project, which also makes use of HS-USB.
USB was operational at first, and there was no optimisation level.
After that, I adjusted the optimisation level to O2, and it was functioning as well.
Following my transition to O2, I made a single code modification: I commented out a debug PRINTF in a different file that has nothing to do with USB. Suddenly, USB stopped working, meaning Device Manager could not recognise it.
Reverting to the previous modification made the USB working.

Would someone kindly assist me in solving this issue?

0 件の賞賛
返信

152件の閲覧回数
emblink182
Contributor III
Hi @sagid
I had a similar problem with USB and O2 optimization and was able to solve it.
Please take a look at this topic.

https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-o...

0 件の賞賛
返信

1,020件の閲覧回数
cgarcia
Contributor II

I found the issue in usb example demo coming form SDK_2.9.1_LPCXpresso55S69.

At initialization there is the following code:

/* enable usb0 host clock */
CLOCK_EnableClock(kCLOCK_Usbhsl0);
/*According to reference mannual, device mode setting has to be set by access usb host register */
*((uint32_t *)(USBFSH_BASE + 0x5c)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK;
/* disable usb0 host clock */
CLOCK_DisableClock(kCLOCK_Usbhsl0);

it looks to be a WA, this section of code looks to be not a good practice programming therefore optimized code is not doing exactly what is expected to do.

The solution I found:

volatile uint32_t usbfsh_offset=0x5c;
/* enable usb0 host clock */
CLOCK_EnableClock(kCLOCK_Usbhsl0);
/*According to reference mannual, device mode setting has to be set by access usb host register */
*((uint32_t *)(USBFSH_BASE + usbfsh_offset)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK;
/* disable usb0 host clock */
CLOCK_DisableClock(kCLOCK_Usbhsl0);

 

There is a lot of examples applying same WA as bad practice of coding at SDK_2.9.1_LPCXpresso55S69/boards/lpcxpresso55s69/usb_examples.

I hope this contributes to NXP team and take it for consideration for demo quality.  

539件の閲覧回数
emblink182
Contributor III
Thanks cgarcia for the solution, you saved a lot of my time!
0 件の賞賛
返信