cancel
Showing results for 
Search instead for 
Did you mean: 

application status stuck on application start in usb msc host stm32f407vgt using hall library please help anyone?

VKUMA.12
Associate II

/* USER CODE BEGIN Header */

/**

 ******************************************************************************

 * @file      : main.c

 * @brief     : Main program body

 ******************************************************************************

 * @attention

 *

 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.

 * All rights reserved.</center></h2>

 *

 * This software component is licensed by ST under Ultimate Liberty license

 * SLA0044, the "License"; You may not use this file except in compliance with

 * the License. You may obtain a copy of the License at:

 *               www.st.com/SLA0044

 *

 ******************************************************************************

 */

/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/

#include "main.h"

#include "fatfs.h"

#include "usb_host.h"

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

void MX_USB_HOST_Process(void);

/* USER CODE BEGIN PFP */

//USBH_HandleTypeDef hUsbHostFS;

extern ApplicationTypeDef Appli_state ;

/* USER CODE END PFP */

USBH_HandleTypeDef husb;

extern FATFS USBHFatFS;

extern FIL USBHFile;

extern char USBHPath[4];

char check;

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_FATFS_Init();

 MX_USB_HOST_Init();

 while (1)

 {

  

  MX_USB_HOST_Process();

  switch(Appli_state)

{

case APPLICATION_IDLE:

break;

case APPLICATION_START:

break;

case APPLICATION_READY:

if(f_mount(&USBHFatFS, (TCHAR const*)USBHPath, 0) == FR_OK) 

{

HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET);

}

if(f_open(&USBHFile, "ST.TXT/0", FA_WRITE|FA_CREATE_ALWAYS) == FR_OK)

HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET);

f_close(&USBHFile);

}

break;

case APPLICATION_DISCONNECT:

HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET);

break;

}

 }

  

}

/**

 * @brief System Clock Configuration

 * @retval None

 */

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure the main internal regulator output voltage 

 */

 __HAL_RCC_PWR_CLK_ENABLE();

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLM = 4;

 RCC_OscInitStruct.PLL.PLLN = 168;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

 RCC_OscInitStruct.PLL.PLLQ = 7;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)

 {

  Error_Handler();

 }

}

/**

 * @brief GPIO Initialization Function

 * @param None

 * @retval None

 */

static void MX_GPIO_Init(void)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 /* GPIO Ports Clock Enable */

 __HAL_RCC_GPIOE_CLK_ENABLE();

 __HAL_RCC_GPIOH_CLK_ENABLE();

 __HAL_RCC_GPIOC_CLK_ENABLE();

 __HAL_RCC_GPIOA_CLK_ENABLE();

 /*Configure GPIO pin Output Level */

 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET);

 /*Configure GPIO pin Output Level */

 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);

 /*Configure GPIO pin : PE4 */

 GPIO_InitStruct.Pin = GPIO_PIN_4;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

 /*Configure GPIO pin : PC0 */

 GPIO_InitStruct.Pin = GPIO_PIN_0;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**

 * @brief This function is executed in case of error occurrence.

 * @retval None

 */

void Error_Handler(void)

{

 /* USER CODE BEGIN Error_Handler_Debug */

 /* User can add his own implementation to report the HAL error return state */

 /* USER CODE END Error_Handler_Debug */

}

#ifdef USE_FULL_ASSERT

/**

 * @brief Reports the name of the source file and the source line number

 *     where the assert_param error has occurred.

 * @param file: pointer to the source file name

 * @param line: assert_param error line source number

 * @retval None

 */

void assert_failed(uint8_t *file, uint32_t line)

 /* USER CODE BEGIN 6 */

 /* User can add his own implementation to report the file name and line number,

   tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

 /* USER CODE END 6 */

}

#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

5 REPLIES 5
VKUMA.12
Associate II

Issue resolved

Gcare.1
Associate II

Could you explain how you resolved your issue? Facing the same problem

VKUMA.12
Associate II

while(1){

MX_USB_HOST_Process();

retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath);

HAL_Delay(500);

 if((Appli_state == APPLICATION_DISCONNECT)||(Appli_state == APPLICATION_IDLE))

lcdprintchar("     ERROR    ",0,50,COLOR_BLACK,COLOR_PURPLE);

lcdprintchar("PLEASE INSERT PENDRIVE....",80,100,COLOR_BLACK,COLOR_PURPLE);

HAL_Delay(5000);

}

if(Appli_state == APPLICATION_START)

{

lcdprintchar("CONNECTED ",100,100,COLOR_BLACK,COLOR_PURPLE);

HAL_Delay(5000);

}

if(f_mount(&USBHFatFS,USBHPath,1)==FR_OK)

{

if(f_open(&USBHFile,"FILE.TXT",FA_READ)==FR_OK)

{

 

}

f_close(&USBHFile);

HAL_Delay(500);

}

}

This is working code.................

The F407-DISCO board should also have HAL examples related the the "FW Upgrade" method where IAP was demonstrated using a USB Flash Drive.

And there should also be work MSC USB HOST examples for one or more of the F4 EVAL series boards.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks alot,

The code is also working fine for me!