Using USB Flash Storage with the i.MX RT1170 High-Speed USB Interface (AI processed)

Using USB Flash Storage with the i.MX RT1170 High-Speed USB Interface (AI processed)

Application Note: Using USB Flash Storage with the i.MX RT1170 High‑Speed USB Interface

Document Number: ANxxxx
Revision: 1.0
Date: January 21, 2026
Author: Embedded Systems Team


1. Introduction

This application note describes how to interface a USB Flash drive with the i.MX RT1170 microcontroller’s integrated USB 2.0 High‑Speed (HS) controller. The i.MX RT1170 includes two USB 2.0 OTG controllers with integrated PHY, each supporting host, device, and OTG roles at low‑, full‑, and high‑speed data rates.

The procedures covered here apply to both the i.MX RT1170 Evaluation Kit (EVK) and the i.MX RT1170 Evaluation Kit Board (EVKB) when running a uClinux‑based software stack. The note provides step‑by‑step instructions for accessing a USB Flash drive from both the U‑Boot bootloader and the Linux kernel, including important data‑integrity considerations.


2. Hardware Setup

2.1 Required Equipment

  • Target board: i.MX RT1170 EVK or EVKB

  • USB cable: Micro‑B to USB‑A Female adapter cable

  • USB Flash drive: Pre‑formatted with a single FAT32 partition

  • SD card: With bootable uClinux image (U‑Boot + kernel + rootfs)

2.2 Hardware Connections

  1. Insert the prepared SD card into the board’s SD slot.

  2. Connect the Micro‑B end of the adapter cable to the USB1 port (labeled USB OTG1) on the EVK/EVKB.

  3. Plug the USB Flash drive into the USB‑A Female end of the cable.

  4. Connect serial console and power to the board.


3. Accessing USB Flash from U‑Boot

3.1 Enter U‑Boot Command Line

After power‑on or reset, press any key at the U‑Boot prompt to interrupt autoboot:

text

Hit any key to stop autoboot: 0 =>

3.2 Scan for USB Devices

Execute usb start to initialize the USB controllers and scan for attached storage:

text

=> usb start starting USB... Bus usb1@40430000: USB EHCI 1.00 Bus usb2@4042c0000: USB EHCI 1.00 scanning bus usb1@40430000 for devices... 2 USB Device(s) found scanning bus usb2@4042c0000 for devices... 1 USB Device(s) found scanning usb for storage devices... 1 Storage Device(s) found

3.3 Inspect the USB Storage Device

Display details of the detected Flash drive:

text

=> usb storage Device 0: Vendor: Generic Rev: 8.07 Prod: Flash Disk Type: Removable Hard Disk Capacity: 1901.0 MB = 1.8 GB (3893248 x 512)

3.4 List Files on the USB Drive

Use fatls to view contents of the FAT32 partition:

text

=> fatls usb 0 System Volume Information/ 0 file(s), 1 dir(s)

3.5 File Transfer Example

The following sequence demonstrates reading a kernel image from the SD card, writing it to the USB drive, reading it back, and verifying data integrity:

text

// Load kernel image from SD card (mmc 0) => fatload mmc 0 ${loadaddr} rootfs.uImage 9677567 bytes read in 593 ms (15.6 MiB/s) // Write image to USB Flash drive (usb 0) => fatwrite usb 0 ${loadaddr} rootfs.uImage ${filesize} 9677567 bytes written in 2921 ms (3.2 MiB/s) // Read back from USB drive to different memory address => fatload usb 0 0x81000000 rootfs.uImage 9677567 bytes read in 375 ms (24.6 MiB/s) // Verify both memory regions are identical => cmp.b ${loadaddr} 0x81000000 ${filesize} Total of 9677567 byte(s) were the same

4. Accessing USB Flash from Linux

4.1 Boot to Linux

After U‑Boot loads the kernel from SD card, Linux initializes the USB subsystem. Observe the kernel log for USB detection:

text

usb-storage 1-1:1.0: USB Mass Storage device detected scsi host0: usb-storage 1-1:1.0 ... sd 0:0:0:0: [sda] 8228864 512-byte logical blocks: (4.21 GB/3.92 GiB) sd 0:0:0:0: [sda] Attached SCSI removable disk

The USB Flash appears as /dev/sda with a single partition /dev/sda1.

4.2 Partition Inspection

Examine the disk partition table:

text

/ # fdisk -l /dev/sda Disk /dev/sda: 4018 MB, 4213178368 bytes, 8228864 sectors 512 cylinders, 255 heads, 63 sectors/track Units: sectors of 1 * 512 = 512 bytes Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type /dev/sda1 * 0,32,33 511,254,63 2048 8228863 8226816 4017M c Win95 FAT32 (LBA)

4.3 Mounting the FAT32 Partition

Create a mount point and mount the partition:

text

/ # mkdir -p /mnt/usbflash / # mount /dev/sda1 /mnt/usbflash / # ls -l /mnt/usbflash/ drwxr-xr-x 2 root root 4096 May 25 2023 System Volume Information

4.4 Data Logging Example

Simulate a data‑harvesting application by writing timestamps to a log file:

text

/ # cd /mnt/usbflash / # while true; do date >> data.log; sleep 1; done

After a few seconds, interrupt with Ctrl+C and view the log:

text

/ # cat data.log Thu Jan 1 00:11:27 UTC 1970 Thu Jan 1 00:11:28 UTC 1970 ...

4.5 Unmounting Before Removal

Always unmount before disconnecting the USB drive:

text

/ # umount /mnt/usbflash

The kernel will indicate safe removal:

text

usb 1-1: USB disconnect, device number 2

4.6 Hot‑Plug Support

The USB host controller supports hot‑plugging. Re‑insert the drive to see automatic detection and readiness for mounting.


5. Data Synchronization Considerations

5.1 The Caching Challenge

By default, Linux uses write‑back caching for FAT file systems. Data written to a file may remain in memory before being flushed to the physical media. Unexpected power loss or device removal can cause data loss.

5.2 Synchronous Mount Option

To guarantee immediate write‑through to the USB drive, mount the partition with the sync option:

text

/ # mount -o sync /dev/sda1 /mnt/usbflash

Verify the mount flags:

text

/ # mount | grep usbflash /dev/sda1 on /mnt/usbflash type vfat (rw,sync,relatime,...)

Trade‑off: Synchronous writes eliminate data‑loss risk but significantly reduce write performance, as each write() call blocks until data is physically stored.

5.3 Manual Synchronization

If using the default asynchronous mount, force a flush of cached data with:

text

/ # sync

This command writes all pending cached data to all mounted file systems.


6. Platform‑Specific Notes

6.1 i.MX RT1170 EVK

  • USB1 (Micro‑B connector) is used in this example.

  • The same steps apply to USB2 (Micro‑AB connector) if the corresponding device‑tree configuration is enabled.

6.2 i.MX RT1170 EVKB

  • Pin‑compatible with EVK; USB interface behavior is identical.

  • Ensure the correct USB port is enabled in the board device tree if using a custom build.

6.3 Text‑File Format Note

Windows and Unix/Linux use different line endings (CR+LF vs. LF). If data logs will be processed on Windows, consider adding carriage‑return characters (\r) in the logging application or convert files after transfer.


7. Summary

This application note demonstrated how to utilize USB Flash storage with the i.MX RT1170’s High‑Speed USB interface under both U‑Boot and Linux. Key procedures include:

  • Initializing and scanning USB storage in U‑Boot

  • Transferring files between SD card and USB drive

  • Mounting and using FAT32 partitions in Linux

  • Implementing data‑integrity measures for reliable operation

Following these guidelines will enable robust USB mass‑storage functionality in i.MX RT1170‑based embedded systems.