Summary
I am porting the ST USB OTG library to the STM32F4 user board using the latest version of the Sourcery CodeBench Lite toolkit (GCC arm-none-eabi 4.7.2).
When I compile the code with -O0, the program works fine. When I compile with -O1 or -O2, it fails. When I talk about refusal, it just stops. There is no hard failure, nothing (well, obviously, he is doing something, but I donโt have an emulator for debugging and finding out, sorry, my hard error handler is not called).
More details
I am trying to make a call to the following function ...
void USBD_Init(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID, USBD_DEVICE *pDevice, USBD_Class_cb_TypeDef *class_cb, USBD_Usr_cb_TypeDef *usr_cb);
... but it does not seem to fall into the body of the function. (Is this a symptom of a โstack breaking"?)
The structures passed to this function have the following definitions:
typedef struct USB_OTG_handle { USB_OTG_CORE_CFGS cfg; USB_OTG_CORE_REGS regs; DCD_DEV dev; } USB_OTG_CORE_HANDLE , *PUSB_OTG_CORE_HANDLE; typedef enum { USB_OTG_HS_CORE_ID = 0, USB_OTG_FS_CORE_ID = 1 }USB_OTG_CORE_ID_TypeDef; typedef struct _Device_TypeDef { uint8_t *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length); } USBD_DEVICE, *pUSBD_DEVICE; typedef struct _Device_cb { uint8_t (*Init) (void *pdev , uint8_t cfgidx); uint8_t (*DeInit) (void *pdev , uint8_t cfgidx); uint8_t (*Setup) (void *pdev , USB_SETUP_REQ *req); uint8_t (*EP0_TxSent) (void *pdev ); uint8_t (*EP0_RxReady) (void *pdev ); uint8_t (*DataIn) (void *pdev , uint8_t epnum); uint8_t (*DataOut) (void *pdev , uint8_t epnum); uint8_t (*SOF) (void *pdev); uint8_t (*IsoINIncomplete) (void *pdev); uint8_t (*IsoOUTIncomplete) (void *pdev); uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index, uint16_t *length); } USBD_Class_cb_TypeDef; typedef struct _USBD_USR_PROP { void (*Init)(void); void (*DeviceReset)(uint8_t speed); void (*DeviceConfigured)(void); void (*DeviceSuspended)(void); void (*DeviceResumed)(void); void (*DeviceConnected)(void); void (*DeviceDisconnected)(void); } USBD_Usr_cb_TypeDef;
I tried to include all the source code related to this problem. If you want to see all the source code, you can download it here: http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/stm32_f105-07_f2_f4_usb- host-device_lib.zip
Resolved Attempts
I tried playing with #pragma GCC optimize ("O0") , __attribute__((optimize("O0"))) and declaring certain definitions as volatile , but nothing worked. I would rather just change the code so that it plays well with the optimizer.
Question
How can I change this code to work well with the GCC optimizer?