cancel
Showing results for 
Search instead for 
Did you mean: 

After upgrading firmware in stm32f407vgt through pendrive fatfs of upgraded code is not working, controller hangs on f_mount, please help...............

VKUMA.12
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions

Instrument code so you know what's going on.

Make sure interrupts are functioning, and vector table address is set correctly.​

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

View solution in original post

7 REPLIES 7
Ozone
Lead

We are supposed to speak magic workd into crystal balls ? A bit more information would be helpful.

Have you validated the updat eprocess itself and the new firmware version (update) independently ?

thanks for reply......

am upgrading firmware in microcontroller using a usb pendrive, any other program other than usb works fine.

there are two program running on the controller, first is firmware upgrade program and another is the program we want to upload in microcontroller using usb

pendrive. From reference manual AN3990

Not easy to comrehend what you mean.

>... first is firmware upgrade program ...

A bootloader, to check for updates, and perform them if necessary ?

>... and another is the program we want to upload in microcontroller ...

The application supposed to run normally ?

Have you tried to debug your code ?

Where does it get stuck, or faults ?

> ... hangs on f_mount ...

Did you check why f_mount fails, down to the peripheral driver level ?

#include "main.h"
#include "fatfs.h"
#include "usb_host.h"
extern USBH_HandleTypeDef hUsbHostFS;
extern ApplicationTypeDef Appli_state;
SD_HandleTypeDef hsd;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SDIO_SD_Init(void);
void MX_USB_HOST_Process(void);
int check;	
int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_SDIO_SD_Init();
  MX_USB_HOST_Init();      //controller hangs here 
  while (1)
  {
    MX_USB_HOST_Process(); 		
		if(check==4)
		{
		retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath);
			if(f_mount(&USBHFatFS,USBHPath,0)==FR_OK)
			{
				HAL_GPIO_WritePin(GPIOE,GPIO_PIN_4,GPIO_PIN_SET);
			}
			
			if(f_open(&USBHFile,"PD60.TXT",FA_CREATE_ALWAYS|FA_WRITE)==FR_OK)
			{
				HAL_GPIO_WritePin(GPIOE,GPIO_PIN_4,GPIO_PIN_RESET);
				check = 5;
			}
			f_close(&USBHFile);
		}
		if(check==0)
		{
		
			retSD = FATFS_LinkDriver(&SD_Driver, SDPath);
			if(f_mount(&SDFatFS,SDPath,0)==FR_OK)
			{
				HAL_GPIO_WritePin(GPIOE,GPIO_PIN_4,GPIO_PIN_SET);
			}
			
			if(f_open(&SDFile,"SD60.TXT",FA_CREATE_ALWAYS|FA_WRITE)==FR_OK)
			{
				HAL_GPIO_WritePin(GPIOE,GPIO_PIN_4,GPIO_PIN_RESET);
				check = 4;
			}
			f_close(&SDFile);
			
     		retSD = FATFS_UnLinkDriver(SDPath);
 
			HAL_Delay(500);
		}	
  }
}
 
 
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 SDIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_SDIO_SD_Init(void)
{
 
  /* USER CODE BEGIN SDIO_Init 0 */
 
  /* USER CODE END SDIO_Init 0 */
 
  /* USER CODE BEGIN SDIO_Init 1 */
 
  /* USER CODE END SDIO_Init 1 */
  hsd.Instance = SDIO;
  hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
  hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
  hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
  hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 0;
  /* USER CODE BEGIN SDIO_Init 2 */
 
  /* USER CODE END SDIO_Init 2 */
 
}
 
/**
  * @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();
  __HAL_RCC_GPIOD_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, 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);
 
}
 
/* 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****/

Both code works fine independently. But when i upgrade firmware in controller through pendrive it hangs on MX_USB_HOST_Init and f_mount function.

Instrument code so you know what's going on.

Make sure interrupts are functioning, and vector table address is set correctly.​

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

Thnx for reply........

But how to change vector table address, i didnt able to find NVIC_SetVectorTable() function .

And my code starts from 0x8008000, so should i give this address on the nvic.

Thanks a lot.......................................... Clive

Issue resolved by changing offset address.