Having problems with optimisation on your USB project?

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

Having problems with optimisation on your USB project?

438 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by leo738 on Fri May 16 14:49:23 MST 2014
Hello All,

I've been working on a USB project & was tweaking as I was finishing up. I found invoking the minimal level of optimisation caused the USB functionality to fail. After some searching I've tracked down the culprit to a delay function in usbhw.c. This file has the header:

/*----------------------------------------------------------------------------
 *      U S B  -  K e r n e l
 *----------------------------------------------------------------------------
 * Name:    usbhw.c
 * Purpose: USB Hardware Layer Module for NXP LPC17xx
 * Version: V1.20
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC microcontroller devices only. Nothing else 
 *      gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *----------------------------------------------------------------------------
 * History:
 *          V1.20 Added USB_ClearEPBuf
 *          V1.00 Initial Version
 *----------------------------------------------------------------------------*/


& the function in particular:

void delay (uint32_t length ) {
  volatile uint32_t i;// changed to volatile to prevent removal by optimisation

  for ( i = 0; i < length; i++ );
  return;
}



Changing i to a volatile data type caused the USB functionality to work again.

A little surprised that this hasn't appeared elsewhere before, but hope it helps somebody else!

Leo
0 Kudos
Reply
0 Replies