cancel
Showing results for 
Search instead for 
Did you mean: 

USBH Mass Storage Class Ask a question.

Study Yahoo
Associate III
Posted on November 23, 2017 at 08:50

We are testing usbh mass storage using the nucleo_f207zg board.

STM32Cube_FW_F2_V1.7.0 \ Projects \ STM32F207ZG-Nucleo \ Applications \ FatFs \ FatFs_USBDisk received from the homepage is detected without any problem.

However, I created it directly as a cube (attached file) -> I tested another sample,

I can not find usb. Debugging shows that the appli_state value is still 0x00.

Does the nucleo board have characteristics? I want to solve this problem by all means.

Help !!!  I also want to design another part based on Usbh mass storage.

I attached the main / usb_host / cube file and image capture image below.

Please help me. =) Have a good day!

0690X00000608vTQAQ.png0690X00000608vYQAQ.png

main.c

----------------------------------

void MountUSB(void)

{

res = f_mount(&USBDISKFatFs, USBHPath, 0);

// if(res != FR_OK)

// DisplayError();

}

void UnMountUSB(void)

{

res = f_mount(NULL, '''', 0);

// if(res != FR_OK)

// DisplayError();

}

void OpenFile()

{

res = f_open(&MyFile, ''123.txt'', FA_WRITE|FA_READ);

// if(res != FR_OK)

// DisplayError();

}

void CloseFile()

{

res = f_close(&MyFile);

// if(res != FR_OK)

// DisplayError();

}

void ReadFile(void)

{

res = f_read(&MyFile, text, sizeof(text), (void*)&bytesRead);

// if(res != FR_OK || bytesRead == 0)

// DisplayError();

}

void WriteFile(void)

{

//Increase Number

int16_t number = atoi((char const*)text);

number++;

memset(text, 0, sizeof(text));

sprintf((char *)text, ''%d'', number);

//Move cursor

res = f_lseek(&MyFile, 0);

// if(res != FR_OK)

// DisplayError();

//Write Number

int16_t len = strlen((char const *)text);

res = f_write(&MyFile, text, len, (void*)&bytesWritten);

// if(res != FR_OK || bytesWritten == 0)

// DisplayError();

}

int main(void)

{

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

MX_I2C1_Init();

MX_RTC_Init();

MX_USART2_UART_Init();

MX_USART3_UART_Init();

MX_USART6_UART_Init();

MX_USB_HOST_Init();

MX_FATFS_Init();

MX_USART1_UART_Init();

MountUSB();

while (1)

{

MX_USB_HOST_Process();

if(Appli_state == APPLICATION_READY)

{

OpenFile();

ReadFile();

WriteFile();

CloseFile();

}

}

}

usb_host.c

----------------------------------------------------

extern void MountUSB(void);

extern void UnMountUSB(void);

USBH_HandleTypeDef hUsbHostFS;

ApplicationTypeDef Appli_state = APPLICATION_IDLE;

static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id);

void MX_USB_HOST_Init(void)

{

USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS);

USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS);

USBH_Start(&hUsbHostFS);

}

void MX_USB_HOST_Process(void)

{

USBH_Process(&hUsbHostFS);

}

static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)

{

switch(id)

{

case HOST_USER_SELECT_CONFIGURATION:

// CLCD_Clear(&hi2c1);

// CLCD_PrintString(&hi2c1, 0, 0, ''CONFIGURATION'');

break;

case HOST_USER_DISCONNECTION:

// CLCD_Clear(&hi2c1);

// CLCD_PrintString(&hi2c1, 0, 0, ''DISCONNECTION'');

Appli_state = APPLICATION_DISCONNECT;

UnMountUSB();

break;

case HOST_USER_CLASS_ACTIVE:

// CLCD_Clear(&hi2c1);

// CLCD_PrintString(&hi2c1, 0, 0, ''CLASS_ACTIVE'');

Appli_state = APPLICATION_READY;

break;

case HOST_USER_CONNECTION:

// CLCD_Clear(&hi2c1);

// CLCD_PrintString(&hi2c1, 0, 0, ''CONNECTION'');

Appli_state = APPLICATION_START;

MountUSB();

break;

default:

break;

}

/* USER CODE END CALL_BACK_1 */

}

#mass-storage #nucleo #usb
0 REPLIES 0