2019-07-08 12:44 PM
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.
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
Solved! Go to Solution.
2019-07-08 03:43 PM
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...
2019-07-08 03:43 PM
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...
2019-07-09 02:25 AM
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.
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
2019-09-02 10:12 AM
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?