cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H745: USB MSC stuck at configASSERT

FabianEbs
Associate III

Hello :)

I have created a project for a STM32H745I_Disco board in TouchGFX, imported it to STM32CubeIDE and enabled:

  • USB_OTG_FS -- Host_Only and VBUS sensing
  • USB_HOST_M7 -- Mass Storage Host Class + Platform settings for enable Pin
  • FATFS_M7 -- USB Disk, USE_LFN on, MAX_SS to 4096
  • USART2 -- for debugging, asynchronous and 9600 Baudrate 

After this, I generated the code. I had to manually add the usb files (STM32_USB_Host_Lib, USB_HOST, FATFS) to the project for it to compile successfully.

Now i want to write to a flash drive connected to the USB_FS port, using the default fatfs functions. All I did in the code is use f_mount, f_open, f_write and f_close for my flash drive, in usb_host.c in USBH_UserProcess under the HOST_USER_CLASS_ACTIVE case, like this:

 

 

  case HOST_USER_CLASS_ACTIVE:
  Appli_state = APPLICATION_READY;

  FIL file;
  FRESULT res;
  char data[] = "Hello, World!";
  UINT bytesWritten;

  // Attempt to mount the file system
  if (f_mount(&USBHFatFS, (TCHAR const*)USBHPath, 0) != FR_OK) {
      printf("Mount failed!\n");
      return;
  }

  // Attempt to open the file
  printf("Attempting to open the file...\n");
  res = f_open(&file, "test.txt", FA_CREATE_ALWAYS | FA_WRITE);
  if (res != FR_OK) {
      printf("File open failed with error: %d\n", res);
      return; // Exit if opening the file fails
  }
  printf("File opened successfully!\n");

  // Attempt to write to the file
  printf("Preparing to write data to the file...\n");
  res = f_write(&file, data, sizeof(data) - 1, &bytesWritten);
  if (res != FR_OK) {
      printf("Write operation failed with error: %d\n", res);
  } else {
      printf("File written successfully! Bytes written: %u\n", bytesWritten);
  }

  // Attempt to close the file
  res = f_close(&file);
  if (res != FR_OK) {
      printf("File close failed with error: %d\n", res);
  } else {
      printf("File closed successfully!\n");
  }
  break;

 

When debugging, the code is stuck in tasks.c at line 3157:  configASSERT( pxUnblockedTCB ); so is it some problem with RTOS scheduling?

When removing parts of my code, f_mount only works fine. Starting from f_open, the code gets stuck.

I have attached my .ioc file, but I really just adjusted the parts mentioned above.

 

What am I doing wrong here?

1 ACCEPTED SOLUTION

Accepted Solutions

I was able to make it work by following this tutorial: https://embetronicx.com/tutorials/microcontrollers/stm32/stm32-usb-host-msc-connect-pendrive-to-stm32/ 

Apparently my f_open and f_write implementation was not correct.

View solution in original post

4 REPLIES 4
FBL
ST Employee

Hi @FabianEbs 

Have you tried this example.

The issue could be linked to the stack/heap size for tasks, you can refer to the config in FreeRTOSConfig.h

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @FBL 

 

Thanks a lot for your response!

stack/heap size seems fine:

#define configUSE_PREEMPTION                     1
#define configSUPPORT_STATIC_ALLOCATION          1
#define configSUPPORT_DYNAMIC_ALLOCATION         1
#define configUSE_IDLE_HOOK                      0
#define configUSE_TICK_HOOK                      0
#define configCPU_CLOCK_HZ                       ( SystemCoreClock )
#define configTICK_RATE_HZ                       ((TickType_t)1000)
#define configMAX_PRIORITIES                     ( 56 )
#define configMINIMAL_STACK_SIZE                 ((uint16_t)128)
#define configTOTAL_HEAP_SIZE                    ((size_t)0x8000)
#define configMAX_TASK_NAME_LEN                  ( 16 )
#define configUSE_TRACE_FACILITY                 1
#define configUSE_16_BIT_TICKS                   0
#define configUSE_MUTEXES                        1
#define configQUEUE_REGISTRY_SIZE                8
#define configUSE_RECURSIVE_MUTEXES              1
#define configUSE_COUNTING_SEMAPHORES            1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION  0

ill compare my project with the one you mentioned. i used this example for the setup: https://controllerstech.com/stm32-usb-host-msc/#info_box  

I was able to make it work by following this tutorial: https://embetronicx.com/tutorials/microcontrollers/stm32/stm32-usb-host-msc-connect-pendrive-to-stm32/ 

Apparently my f_open and f_write implementation was not correct.

Here is my usb_host.c file for future reference :)