CubeMX generated code with USB Host, ends in HardFault_Handler()
Hy all
I have a STM32469NI_Disco Board and start a project using CubeMX 5.2.0 as following:
- Select board by Board Selector.
- Let initialize standard peripherals.
- Connectivity - USB_OTG_FS: Select "Host_Only" and "Activate_VBUS"
- Middleware - USB_HOST: Select "Mass Storage Host Class" for FS IP.
- Generate Code for Atollic TrueSTUDIO (or Keil, if you like).
- Open the Project
- Fix the errors generated by CubeMX:
- Src\freertos.c: Task name, replace "1" by an name e.g. "StartDefaultTask" and add a prototype in the header. Correct the osThreadStaticDef arguments to:
osThreadStaticDef(defaultTask, StartDefaultTask, osPriorityNormal, 0 , 4096, NULL, NULL);- Add code to enable the USB power in Src\usbh_conf.c, USBH_LL_DriverVBUS(..):
/* USER CODE BEGIN 0 */
if(state == 0)
{
HAL_GPIO_WritePin(OTG_FS1_PowerSwitchOn_GPIO_Port, OTG_FS1_PowerSwitchOn_Pin, GPIO_PIN_RESET);
}
else
{
HAL_GPIO_WritePin(OTG_FS1_PowerSwitchOn_GPIO_Port, OTG_FS1_PowerSwitchOn_Pin, GPIO_PIN_SET);
}
/* USER CODE END 0*/- Compile and start debug.
The program will, after a thumb driver connected, fall in to the HardFault_Handler().
The call hierarchy is:
MX_USB_HOST_Init() -> USBH_Start() -> USBH_LL_Start() -> HAL_HCD_Start() -> __HAL_HCD_ENABLE() -> USB_EnableGlobalInt()
USBx->GAHBCFG |= USB_OTG_GAHBCFG_GINT; // Crash!I can't find the cause of the crash and currently even don't know how to precede.
The effect is the same if I generate the Project for CMSIS_v1, CMSIS_v2 or for Keil instead of TrueSTUDIO.
Someone have an Idea what I could try as next?
Thanks and best regards!
