Skip to main content
Caan
Associate III
March 4, 2026
Question

Unable to make USB HS Mass storage run with touchgfx

  • March 4, 2026
  • 0 replies
  • 150 views

I have successfully run the USB HS Mass storage on a new project without the use of freertos and touchgfx , But when the touchgfx code  for STM32H750B-DK is modified to run the code I am getting hard faults

static uint8_t usb_done = 0;

extern ApplicationTypeDef Appli_state;
extern USBH_HandleTypeDef hUsbHostHS;
extern FATFS USBHFatFS;
extern char USBHPath[4];

void Debug_Print(char *str)
{
 HAL_UART_Transmit(&huart4, (uint8_t*)str, strlen(str), 100);
}




static uint8_t file_written = 0;

void StartDefaultTask(void *argument)
{
 Debug_Print("Task Started\r\n");

 for(;;)
 {
 USBH_Process(&hUsbHostHS);

 if (Appli_state == APPLICATION_READY && file_written == 0)
 {
 Debug_Print("USB Detected\r\n");

 if (USBH_MSC_IsReady(&hUsbHostHS))
 {
 Debug_Print("MSC Ready\r\n");

 FRESULT res;
 FIL file;
 UINT bw;

 /* Mount USB */
 Debug_Print("Mounting...\r\n");
 res = f_mount(&USBHFatFS, USBHPath, 1);

 if (res == FR_OK)
 {
 Debug_Print("Mount OK\r\n");

 /* Create file */
 res = f_open(&file,
 "0:/log.txt",
 FA_CREATE_ALWAYS | FA_WRITE);

 if (res == FR_OK)
 {
 Debug_Print("File Opened\r\n");

 char data[] = "Hello from STM32H750 + FreeRTOS\r\n";

 res = f_write(&file, data, strlen(data), &bw);

 if (res == FR_OK)
 Debug_Print("Write OK\r\n");
 else
 Debug_Print("Write ERROR\r\n");

 f_close(&file);
 Debug_Print("File Closed\r\n");
 }
 else
 {
 Debug_Print("File Open ERROR\r\n");
 }

 file_written = 1;
 }
 else
 {
 Debug_Print("Mount FAILED\r\n");
 }
 }
 }

 if (Appli_state == APPLICATION_DISCONNECT)
 {
 Debug_Print("USB Removed\r\n");
 file_written = 0;
 }
 char msg[50];
 sprintf(msg, "State: %d\r\n", hUsbHostHS.gState);
 Debug_Print(msg);

 }
}

I have tried to increase the stack size 

osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
 .name = "defaultTask",
 .stack_size = 32768,------>increased
 .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for GUITask */
osThreadId_t GUITaskHandle;
const osThreadAttr_t GUITask_attributes = {
 .name = "GUITask",
 .stack_size = 8192 * 4,
 .priority = (osPriority_t) osPriorityNormal,
};

As soon as the mass storage is added the system goes in hardfault 
State is printed =1 (serial output)