Note that there are some explanatory texts on larger screens.

plurals
  1. POGCC 4.7.2 Optimization Problems
    text
    copied!<p><strong>Summary</strong></p> <p>I'm porting ST's USB OTG Library to a custom STM32F4 board using the latest version of Sourcery CodeBench Lite toolchain (GCC arm-none-eabi 4.7.2). </p> <p>When I compile the code with -O0, the program runs fine. When I compile with -O1 or -O2 it fails. When I say fail, it just stops. No hard fault, nothing (Well, obviously there is something it's doing but I don't have a emulator to use to debug and find out, I'm sorry. My hard fault handler is not being called).</p> <p><strong>Details</strong></p> <p>I'm trying to make a call to the following function...</p> <pre><code>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); </code></pre> <p>...but it doesn't seem to make it into the function body. (Is this a symptom of "stack-smashing"?)</p> <p>The structures passed to this function have the following definitions:</p> <pre><code>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); /* Control Endpoints*/ uint8_t (*Setup) (void *pdev , USB_SETUP_REQ *req); uint8_t (*EP0_TxSent) (void *pdev ); uint8_t (*EP0_RxReady) (void *pdev ); /* Class Specific Endpoints*/ 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; </code></pre> <p>I've tried to include all the source code relevant to this problem. If you want to see the entire source code you can download it here: <a href="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" rel="noreferrer">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</a></p> <p><strong>Solutions Attempted</strong></p> <p>I tried playing with <code>#pragma GCC optimize ("O0")</code>, <code>__attribute__((optimize("O0")))</code>, and declaring certain definitions as <code>volatile</code>, but nothing worked. I'd rather just modify the code to make it play nicely with the optimizer anyway.</p> <p><strong>Question</strong></p> <p>How can I modify this code to make it play nice with GCC's optimizer?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload