NUCLEO-H743ZI USB HOST MSC not firing the HOST_USER_CLASS_ACTIVE event
Hi
I have been trying to get USB HOST MSC working on the NUCLEO-H743ZI and cannot get past one point. I have reduced my test to a new test project with auto-generated code via STm32CubeIDE with the following settings.
- FATFS enabled for USB only with USBH instance = "USBH Host MSC FS" and VOLUMES increased to 2
- USB_HOST set to FS Mass Storage Host Class only and VBUS driven by GPIO
- USB_OTG_FS in Host_Only mode with VBUS sensing on and SOF activated (although I tried these off as well.
- USB Clock confirmed as 48Mhz
The auto-generated code gives me the basics, and I have added a VBUS enable after initialising everything, and I can see the LED light as well as measure 5V on the USB power lines.
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ETH_Init();
MX_USART3_UART_Init();
MX_FATFS_Init();
MX_USB_HOST_Init();
/* USER CODE BEGIN 2 */
MX_DriverVbusFS(0); // Turn on USB power
/* USER CODE END 2 */With that as the basics, I can see that the USBH_UserProcess is called with HOST_USER_CONNECTION and HOST_USER_DISCONNECTION whenever I plug the USB stick on or remove it. So, I know the USB is up and running.
The initialisation does not throw any errors... (again auto-generated so I am trusting it is correct)
void MX_USB_HOST_Init(void)
{
/* USER CODE BEGIN USB_HOST_Init_PreTreatment */
/* USER CODE END USB_HOST_Init_PreTreatment */
/* Init host Library, add supported class and start the library. */
if (USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS) != USBH_OK)
{
Error_Handler();
}
if (USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS) != USBH_OK)
{
Error_Handler();
}
if (USBH_Start(&hUsbHostFS) != USBH_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USB_HOST_Init_PostTreatment */
HAL_PWREx_EnableUSBVoltageDetector();
/* USER CODE END USB_HOST_Init_PostTreatment */
}I added the HAL_PWREx_EnableUSBVoltageDetector as a result of other internet threads, but it did not fix anything, and I suspect it is for Slave mode and not Host mode,
As MSC class is registered, I was expecting that the standard auto-generated USBH_UserProcess would trigger the HOST_USER_CLASS_ACTIVE event as well, but that never gets fired.
So, I added FATS_LinkDriver (which worked) and an f_mount (which fails) and still cannot get the MSC driver to start up and fire the HOST_USER_CLASS_ACTIVE.
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
{
/* USER CODE BEGIN CALL_BACK_1 */
switch(id)
{
case HOST_USER_SELECT_CONFIGURATION:
break;
case HOST_USER_DISCONNECTION:
Appli_state = APPLICATION_DISCONNECT;
if (f_mount(NULL, "", 0) != FR_OK)
{
Error_Handler();
}
if (FATFS_UnLinkDriver(USBDISKPath) != 0)
{
Error_Handler();
}
break;
case HOST_USER_CLASS_ACTIVE:
Appli_state = APPLICATION_READY;
break;
case HOST_USER_CONNECTION:
Appli_state = APPLICATION_START;
if (FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0)
{
if (f_mount(&USBH_fatfs, USBDISKPath, 1) != FR_OK)
{
HAL_Delay(1);
}
else
{
HAL_Delay(1);
}
break;
default:
break;
}As the VBUS is working, and the USB connect/disconnect events are firing, I assume I am missing some step out, but I can't find any hints in the application notes or forums. I have tried adapting the H743 EVAL board example to the NUCLEO board, but that seems to get me to the same point.
Is there a native USB MSC example for the NUCLEO-743ZI, or is there an obvious step or set-up that I may be missing?
Thanks in advance for any pointers,
Nick
