2019-06-14 05:27 AM
Hy all
I have a STM32469NI_Disco Board and start a project using CubeMX 5.2.0 as following:
osThreadStaticDef(defaultTask, StartDefaultTask, osPriorityNormal, 0 , 4096, NULL, NULL);
/* 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*/
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!
2019-06-17 02:44 AM
Ok, I found the problem.
After USB_EnableGlobalInt(), the Interrupt was triggered. Deep in some of the methods called by the interrupt handler there are several debug messages posted. The methods USBH_UsrLog() and USBH_ErrLog() are using "printf" which is normally not correctly redirected.
According to a CubeMX example you have to add this code somewhere:
#ifdef __GNUC__
/* With GCC, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart6, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}