Using USB Host Mode in FreeRTOS
This application note explains how to use the STM32H7 USB Host Mode in FreeRTOS.
1. Understanding USB Host Mode Interfaces
1.1. FreeRTOS USB Host Mode Implementation
The STM32CubeH7 software layers provides the necessary drivers for USB host on the STM32H7. The drivers and corresponding clock and pads configurations code are enabled in the BSP.
The FreeRTOS demo application enables the USB Mass Storage functionality with support for the FAT filesystem support. The USB Mass Storage and FAT filesystem drivers are also provided by the STM32CubeH7 layer.
1.2. FreeRTOS USB Host Mode C-Binding API
The FreeRTOS BSP provides the following APIs to access directories and files on a USB Flash device:
API Function | Description | Comments |
| ||
| Mount filesystem specified by path | Pass |
| ||
| Open file |
|
| ||
| Close file |
|
| ||
| Read file |
|
| ||
| Write file |
|
| ||
| Open a directory to read its content |
|
| ||
| Create a directory |
|
| ||
| Delete an existing file or directory |
|
The full description of the FAT file system API and data structures can be found in Middlewares/Third_Party/FatFs/Src/ff.h
in the project source code directory.
2. USB Host Mode CLI Command
The FreeRTOS application implements the following USB Host mode related CLI command::
Command | Description | Comments |
| Print content of the top directory and its subdirectories |
|
3. Validating USB Host Mode Operation
Use the following step-wise procedure to validate the USB Host mode operation:
Format a USB Flash partition to FAT. Make sure that the FAT partition is using the same code page as configured by the
_CODE_PAGE
parameter inProjects/STM32H7_SOM/Applications/FreeRTOS/freertos_stm32h750/Inc/ffconf.h
, e.g. fordosfstools
v4.2:$ sudo mkfs.fat --codepage=850 /dev/sdh1
Attach a USB Flash device with a formatted FAT partition to the OTG micro-USB connector of the STM32H7 BSB board.
Power up the board.
From the FreeRTOS CLI, run the usbfatls command and check that the list of the files in the FAT partition is printed to the serial console:
CLI> usbfatls
|__MULTIB~1
| |__MENU
| |__ISOS
| |__LDLINUX.SYS
| |__SYSLINUX.CFG
| |__YUMI.PNG
| |__YUMI-C~1.TXT
| |__YUMI-R~1.TXT
| |__LICENSE.TXT
| |__VESAMENU.C32
| |__CHAIN.C32
| |__MEMDISK
| |__GRUB.EXE
| |__UBUNTU~1
|__FILE.DB
|__DISK~1
| |__INFO
|__RECENT.DB
|__XEROXP~1
| |__SCAN
|__LOST.DIR
|__ANDROID
| |__DATA
CLI>