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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

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

1,122 次查看
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 回复数

262 次查看
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 项奖励
回复

244 次查看
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,112 次查看
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.  

631 次查看
emblink182
Contributor III
Thanks cgarcia for the solution, you saved a lot of my time!
0 项奖励
回复