Skip to main content
NRobb
Associate III
July 8, 2019
Solved

NUCLEO-H743ZI USB HOST MSC not firing the HOST_USER_CLASS_ACTIVE event

  • July 8, 2019
  • 3 replies
  • 1778 views

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

This topic has been closed for replies.
Best answer by Peaga

Are you using STM32CubeMX 5.2.1 and HAL 1.4.0? Please, try to add the following callbacks in "usbh_conf.c":

/**
 * @brief Port Port Enabled callback.
 * @param hhcd: HCD handle
 * @retval None
 */
void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd)
{
 USBH_LL_PortEnabled(hhcd->pData);
}
/**
 * @brief Port Port Disabled callback.
 * @param hhcd: HCD handle
 * @retval None
 */
void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd)
{
 USBH_LL_PortDisabled(hhcd->pData);
}

The "HAL_PWREx_EnableUSBVoltageDetector()" function is now added by Cube in "main.c". I'm having some issues porting from HAL 1.3.2 to HAL 1.4.0...

3 replies

PeagaBest answer
Senior
July 8, 2019

Are you using STM32CubeMX 5.2.1 and HAL 1.4.0? Please, try to add the following callbacks in "usbh_conf.c":

/**
 * @brief Port Port Enabled callback.
 * @param hhcd: HCD handle
 * @retval None
 */
void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd)
{
 USBH_LL_PortEnabled(hhcd->pData);
}
/**
 * @brief Port Port Disabled callback.
 * @param hhcd: HCD handle
 * @retval None
 */
void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd)
{
 USBH_LL_PortDisabled(hhcd->pData);
}

The "HAL_PWREx_EnableUSBVoltageDetector()" function is now added by Cube in "main.c". I'm having some issues porting from HAL 1.3.2 to HAL 1.4.0...

NRobb
NRobbAuthor
Associate III
July 9, 2019

Hi Peaga,

Thanks for the reply. I am running STM32CubeIDE with CubeMX 5.2.1 and HAL driver 1.5.0.

I added in those callbacks, and it is now working :) I can now mount and read the USB label, and I see it go through the intermediate states as well.

0690X000009YYrNQAW.png

Many thanks for the pointer :)

May I ask if this is something that would be expected to be included in the auto-generated code (as they seem to be adding code to catch the output of it), or have I missed a key section in the application notes somewhere?

Thanks again

Nick

ns.moskalev
Associate
September 2, 2019

Hello. I have the same question. Why port connection function "USBH_LL_PortEnabled (hhcd-> pData);" should be called via callback?

Please tell me an alternative way in which a different outcome is possible?