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

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

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

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

836 次查看
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.  

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