Using USB Mass Storage Gadget This application note explains how to make STM32F7 visible as a USB storage device to a USB host such as, for instance, a Windows, Linux PC or notebook. The most typical example of when this functionality is required is a 'data harvesting' application. NEC USB controller driver. This USB driver will recognize the NEC USB controller (USB Enhanced Host. License: Free OS: Windows XP Windows Vista Windows 7 Windows 8 Windows 10 Language: EN Version: 2.0.3300.20300. There’s also full support for macOS Sierra 10.12 (it works with OS X Mountain Lion 10.8.5 or later), including the ability to create a bootable USB recovery drive in a few clicks.
When connected via USB, almost all modern smartphones and portable media devices mount on computer as MTP (Media Transfer Protocol) drives. Unlike USB Mass Storage, which provides raw access to a storage device, MTP operates at the logical file level, and only provides access to selected files and folders on a storage device.
The Startech USB 3.1 gen 2 enclosure works flawlessly for SuperSpeed Plus (10Gbps) data transfer rates between my XPS 8920 desktop and my external HDD. In order to achieve the max transfer rate the computer, the external enclosure, and the USB cable must all support the 3.1 gen 2 protocols.
This application note explains how to make STM32F7 visible as a USB storage device to a USB host such as, for instance, a Windows, Linux PC or notebook.
The most typical example of when this functionality is required is a 'data harvesting' application. In such an application, a remote STM32F7 device collects data readings from various sensors and then stores collected readings into non-volatile storage such as NOR Flash. Once in a while, a technician visits the remote site to offload harvested data and take it to the main site for further processing. Using the functionality described in this note, the data offloading is as simple as connecting the STM32F7 as a USB device to a technician's notebook, which immediately recognizes it as USB storage. Collected data can then be simply copied from the USB storage to other disks on the notebook.
A variation of the same application is a movable device that is periodically taken to the main office for data offloading. In this scenario, the embedded device is simply connected to a PC as a USB device and data is copied from the USB storage to the host computer.
Hardware Platform
The hardware platform for this application note is Emcraft STM32F7 system-on-module (SOM) plugged into the SOM-BSB-EXT baseboard.
High-Level Architecture
We will use the Linux Mass Storage Gadget (MSG) to implement what we need. The main idea is that the MSG presents a file in the local file system as a storage device to the USB host. On the target side, the content of the disk is stored in a file. The backing file is a 'Unix file' that is given to the Mass Storage Gadget as a parameter, which can be a normal file or a block device such as a disk partition.
To make data sharing workable using a Windows host, the USB storage must be formatted as a FAT file system. This way, data gathered by the target into the USB storage can be copied or manipulated otherwise, using standard Windows tools on the USB host end.
The implication of the above is that the backing file must be mounted as a FAT32 file system on the target side. This is not really a problem since Linux supports the FAT32 file system (along with many other file systems). Clearly, a file system can be mounted on a block device such as a disk or a disk partition but it is also possible to mount a file system on a normal file using the so-called 'loop' device.
The big question is where we want the backing file to reside on the STM32F7-based device. We need the file to be on a non-volatile media. It is not really a hard requirement and we could keep the backing file in a RAM-based filesystem too, however in case there is an unexpected power cut, which happens all the time in embedded applications, all data we have collected would be lost. Not really acceptable, in a generic application.
The backing file must be in Flash, then. The STM32F7 system-on-module (SOM) provides a 16 MBytes NOR Flash. In Linux, that Flash can be split on as many partitions as makes sense from the application point of view. A few first MBytes of the NOR Flash are taken by the U-boot environment variables and a bootable Linux image, however the remaining Flash is sufficient to allocate a partition specifically for hosting the USB storage backing file.
Now, having allocated a Flash partition to the USB backing file, we have two options, potentially:
The entire Flash partition could be mounted as a FAT32 file system. It won't work however, for two reasons. First and foremost, Flash needs to be erased before it can be written to. The FAT32 implementation does not assume that it can be used with a raw Flash device so, as soon as an attempt is made to write data to an unerased Flash sector, an I/O error will be reported by the kernel. Secondly, even supposing that the FAT32 implementation is somehow amended to work on top of a raw Flash device, FAT32 is not architecturally designed to be hosted in a Flash device. Some Flash sectors would be written to more frequently than others and a Flash wear scenario will quickly occur.
The backing file can be a file in a JFFS2 file system mounted on the Flash partition. This is a reasonable solution since JFFS2 takes care, transparently for upper-level software, both of erasing Flash prior to writing and of ensuring that Flash sectors are uses evenly to avoid a Flash wear.
To summarize it all, the architecture we want to implement will be as follows:
The Linux Mass Storage Gadget will be used to implement a USB storage device accessible by host software.
To ensure that the USB storage content survives power-cycles and resets, the backing file will be in Flash.
To allow upper-level software accessing the backing file transparently and avoid a Flash wear, the backing file will be a normal file in a JFFS2 file system.
The JFFS2 file system will be mounted on a dedicated partition in the NOR Flash.
The backing file will be mounted as a FAT32 file system on both the Linux and host PC sides. On the Linux side, the backing file will be mounted as a FAT2 file system using the 'loop' block device.
Software Platform
To get the required functionality in the context of the Emcraft STM32F7 SOM BSP:
Activate the cross development environment:
[yur@ubuntu linux-cortexm-2.1.0]$ . ACTIVATE.sh [yur@ubuntu linux-cortexm-2.1.0]$ cd projects/rootfs [yur@ubuntu rootfs]$
Run the busybox configuration procedure:
[yur@ubuntu rootfs]$ make bmenuconfig
In the busybox configuration menu:
Go to the Linux Module Utilities menu and enable insmod, rmmod, and lsmod;
Go to Linux System Utilities, and enable losetup.
Run the kernel configuration procedure:
[yur@ubuntu rootfs]$ make kmenuconfig
In the Linux kernel configuration menu:
Select the Enable loadable module support option
In the Enable loadable module support sub-menu select Module unloading
Go to the Device Drivers -> Block devices menu, and enable Loopback device support driver (built-in [*] variant)
Go to the Device Drivers -> USB support -> USB Gadget Support menu, and select the module [M] compilation for the USB Gadget Drivers option
In the USB Gadget Drivers sub-menu enable Mass Storage Gadget as a module [M]
Add the kernel modules to the initramfs file-system. Edit the rootfs.initramfs file, and add the appropriate links:
Edit the rootfs.dts.STM32F7 file to change the default USB HS interface role, specifically replace the dr_mode property value in the &usb_hs node reference from host to peripheral:
[yur@ubuntu rootfs]$ vi rootfs.dts.STM32F7 ... &usb_hs { status = 'okay'; dr_mode = 'peripheral'; pinctrl-names = 'default'; ...
Build:
[yur@ubuntu rootfs]$ make
Install the resultant rootfs.uImage to the target as described in Installing Linux Images to Flash.
Preparing USB Mass Storage
This section explains how to prepare the USB Mass Storage for deployment. This command sequence is a once-off procedure that needs to be performed on a device at software manufacturing time.
With the bootable Linux image (rootfs.uImage) installed, U-Boot loads the Linux image from the NOR Flash to the SDRAM and passes control to the kernel entry point:
U-Boot 2010.03-cortexm-2.1.0 (Sep 19 2016 - 11:18:48) CPU : STM32F7 (Cortex-M7) Freqs: SYSCLK=200MHz,HCLK=200MHz,PCLK1=50MHz,PCLK2=100MHz Board: STM32F7 SOM Rev 1.A, www.emcraft.com DRAM: 32 MB Flash: 16 MB In: serial Out: serial Err: serial Net: STM32_MAC Hit any key to stop autoboot: 0 ## Booting kernel from Legacy Image at 60020000 ... Image Name: Linux-4.2.0-00030-gf4d242a-dirty Image Type: ARM Linux Multi-File Image (uncompressed) Data Size: 6009372 Bytes = 5.7 MB Load Address: c0008000 Entry Point: c0008001 Contents: Image 0: 5992192 Bytes = 5.7 MB Image 1: 17168 Bytes = 16.8 kB Verifying Checksum ... OK ## Flattened Device Tree from multi component Image at 60020000 Booting using the fdt at 0x605d6f4c Loading Multi-File Image ... OK OK Loading Device Tree to c1ff8000, end c1fff30f ... OK Starting kernel ...
The kernel proceeds to boot-up, initializing the configured I/O interfaces and sub-systems:
Note that 3 logical partitions are created on the NOR Flash by this Linux configuration. The first two partitions are taken by the U-Boot environment variables and the bootable Linux image respectively, so we can't use them, however the third partition is dedicated specially to a JFFS2 file system. This is where we will store the Mass Storage Gadget backing file:
... physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chip ID 0x002101 Amd/Fujitsu Extended Query Table at 0x0040 Amd/Fujitsu Extended Query version 1.5. number of CFI chips: 1 3 ofpart partitions found on MTD device physmap-flash.0 Creating 3 MTD partitions on 'physmap-flash.0': 0x000000000000-0x000000020000 : 'flash_uboot_env' 0x000000020000-0x000000a20000 : 'flash_linux_image' 0x000000a20000-0x000001000000 : 'flash_jffs2' ...
First thing we need to do is to erase the Flash partition we are going to use for the JFFS2 file system:
/ # flash_eraseall -j /dev/mtd2 Erasing 128 Kibyte @ 5e0000 - 100% complete.Cleanmarker written at 5c0000.
We can now mount the newly created JFFS2 file system. As expected, it is empty at this time:
/ # mount -t jffs2 /dev/mtdblock2 /mnt / # ls -lt /mnt / #
Next step is to create in the JFFS2 filesystem a backing file for the FAT32 image. The JFFS2 partition is about 6 MBytes in size so let's create a 5 MBytes FAT32 file system image:
/ # dd if=/dev/zero of=/mnt/fat32.part bs=1M count=5 5+0 records in 5+0 records out 5242880 bytes (5.0MB) copied, 3.049536 seconds, 1.6MB/s / # ls -lt /mnt -rw-r--r-- 1 root root 5242880 Jan 1 00:10 fat32.part
Now, let start the Mass Storage Gadget on the backing file:
/ # insmod /lib/modules/libcomposite.ko / # insmod /lib/modules/usb_f_mass_storage.ko / # insmod /lib/modules/g_mass_storage.ko iSerialNumber=123456 file=/mnt/fat32.part stall=0 removable=1 Mass Storage Function, version: 2009/09/11 LUN: removable file: (no medium) LUN: removable file: /mnt/fat32.part Number of LUNs=1 Number of LUNs=1 g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11 g_mass_storage gadget: g_mass_storage ready dwc2 40040000.usb: bound driver g_mass_storage
Assuming the STM32F7 is connected to a host as a USB gadget, the above commands will make it immediately visible as a USB storage device to the host. Or, if the STM32F7 is not connected to a host at the time the above command is run, simply connect it to a host using an appropriate USB cable. For instance, on the STM32F7-SOM Starter Kit connect a USB 2.0 A Male to Mini-B cable between a free USB port on the host and the USB OTG interface connector on the SOM-BSB-EXT baseboard.
At this point the STM32F7 should become visible as a USB storage device to the host, however the storage still needs to be formatted as a FAT32 file system to allow using it with standard host software. The formatting is done on the host using standard software. For instance, on a Windows machine, go to My Computer and then locate an icon for the new removable disk. Ask to format it and agree with anything that Windows suggests, until the storage is formatted as a FAT32 file system.
Harvesting Data on the Target
Ok, so now everything is ready to start deploying the STM32F7 as a 'data harvesting' device. In all probability, the commands shown below would be put into the /etc/rc start-up script by any reasonably application, but in order to make the set-up command sequence easier for understanding, let's run the required commands manually.
For the sake of running a clean test, let's power-cycle the device. As expected, Linux comes up to the shell:
Now, it is time to start the Mass Storage Gadget making the FAT32 file system mounted on the backing file visible to a USB host as a storage device:
/ # insmod /lib/modules/libcomposite.ko / # insmod /lib/modules/usb_f_mass_storage.ko / # insmod /lib/modules/g_mass_storage.ko iSerialNumber=123456 file=/mnt/fat32.part stall=0 removable=1 Mass Storage Function, version: 2009/09/11 LUN: removable file: (no medium) LUN: removable file: /mnt/fat32.part Number of LUNs=1 Number of LUNs=1 g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11 g_mass_storage gadget: g_mass_storage ready dwc2 40040000.usb: bound driver g_mass_storage
Let's 'harvest' some data and store what is collected into a file in the FAT32 file system. In this demo, we emulate a data stream by taking a snapshot of the system time each second:
/ # while true; do date >> /m/data.log; sleep 1; done
Having let the 'data harvesting' run for a while, let's interrupt it (by pressing ^-C) and take a look at what data we have collected:
^C / # cat /m/data.log Sat Jan 1 01:01:35 UTC 2000 Sat Jan 1 01:01:36 UTC 2000 Sat Jan 1 01:01:37 UTC 2000 ... Sat Jan 1 01:02:04 UTC 2000 Sat Jan 1 01:02:05 UTC 2000
All looks as expected, so we are ready to try accessing the FAT32 file system from a USB host.
Processing Data on the Host
Given the above set-up, a host will be able to see the STM32F7 as a removable disk as soon as a USB connection is made between a free port on the host and the USB OTG interface on the target. A message like this will appear on the target console when a connection to the host has been made:
dwc2 40040000.usb: new device is high-speed dwc2 40040000.usb: new device is high-speed dwc2 40040000.usb: new address 4 dwc2 40040000.usb: new device is high-speed dwc2 40040000.usb: new device is high-speed dwc2 40040000.usb: new address 4 g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage
Host software should recognize the newly plugged USB device as a storage device and mount it as a FAT32 file system. Data collected on the target can be copied to other host disks for further processing.
Note that the format of Windows and Unix text files differs slightly. In Windows, lines end with both the line feed and carriage return ASCII characters, but Unix uses only a line feed. As a consequence, some Windows applications will not show the line breaks in Unix-format files. Assuming that data is stored in a text file (vs a binary file) and Windows is a data processing host, Linux data harvesting applications should take care of the difference by adding a carriage return character to data logs.
Data Synchronization Issues
It is important to note that it is not safe to update the USB storage both on the target and host sides at the same time. Here is what the Mass Storage Gadget documentation has to say about this:
AN IMPORTANT WARNING! While Mass Storage Gadget is running and the gadget is connected to a USB host, that USB host will use the backing storage as a private disk drive. It will not expect to see any changes in the backing storage other than the ones it makes. Extraneous changes are liable to corrupt the filesystem and may even crash the host. Only one system (normally, the USB host) may write to the backing storage, and if one system is writing that data, no other should be reading it. The only safe way to share the backing storage between the host and the gadget's operating system at the same time is to make it read-only on both sides.
Given that the primary use of this technology is to let the host copy harvested data for further processing, this should be an acceptable limitation for most applications. It is important to understand however that the host will see the USB storage in a state it was in when the USB cable was connected between the target and the host. Further updates made to the storage by the target will not be visible on the host until a next plug-in.
As mentioned above, updates made on the host side may be unsafe in case the target continues harvesting data when the host is connected. Probably, the best strategy is to assume a read-only mount of the USB storage on the host side and let application code on the target take care of purging data at appropriate times. Note the Mass Storage Gadget provides a special flag (ro=1) to allows mounting the USB storage for read-only access by the host.
What you need to install Windows 10 on Mac
MacBook introduced in 2015 or later
MacBook Air introduced in 2012 or later
MacBook Pro introduced in 2012 or later
Mac mini introduced in 2012 or later
iMac introduced in 2012 or later1
iMac Pro (all models)
Mac Pro introduced in 2013 or later
The latest macOS updates, which can include updates to Boot Camp Assistant. You will use Boot Camp Assistant to install Windows 10.
64GB or more free storage space on your Mac startup disk:
Your Mac can have as little as 64GB of free storage space, but at least 128GB of free storage space provides the best experience. Automatic Windows updates require that much space or more.
If you have an iMac Pro or Mac Pro with 128GB of memory (RAM) or more, your startup disk needs at least as much free storage space as your Mac has memory.2
An external USB flash drive with a storage capacity of 16GB or more, unless you're using a Mac that doesn't need a flash drive to install Windows.
A 64-bit version of Windows 10 Home or Windows 10 Pro on a disk image (ISO) or other installation media. If installing Windows on your Mac for the first time, this must be a full version of Windows, not an upgrade.
If your copy of Windows came on a USB flash drive, or you have a Windows product key and no installation disc, download a Windows 10 disk image from Microsoft.
If your copy of Windows came on a DVD, you might need to create a disk image of that DVD.
How to install Windows 10 on Mac
To install Windows, use Boot Camp Assistant, which is included with your Mac.
1. Check your Secure Boot setting
Learn how to check your Secure Boot setting. The default Secure Boot setting is Full Security. If you changed it to No Security, change it back to Full Security before installing Windows. After installing Windows, you can use any Secure Boot setting without affecting your ability to start up from Windows.
2. Use Boot Camp Assistant to create a Windows partition
Open Boot Camp Assistant, which is in the Utilities folder of your Applications folder. Follow the onscreen instructions.
If you're asked to insert a USB drive, plug your USB flash drive into your Mac. Boot Camp Assistant will use it to create a bootable USB drive for Windows installation.
When Boot Camp Assistant asks you to set the size of the Windows partition, remember the minimum storage-space requirements in the previous section. Set a partition size that meets your needs, because you can't change its size later.
3. Format the Windows (BOOTCAMP) partition
When Boot Camp Assistant finishes, your Mac restarts to the Windows installer. If the installer asks where to install Windows, select the BOOTCAMP partition and click Format. In most cases, the installer selects and formats the BOOTCAMP partition automatically.
4. Install Windows
Unplug any external devices that aren't necessary during installation. Then click Next and follow the onscreen instructions to begin installing Windows.
5. Use the Boot Camp installer in Windows
After Windows installation completes, your Mac starts up in Windows and opens a ”Welcome to the Boot Camp installer” window. Follow the onscreen instructions to install Boot Camp and Windows support software (drivers). You will be asked to restart when done.
If the Boot Camp installer never opens, open the Boot Camp installer manually and use it to complete Boot Camp installation.
If you have an external display connected to a Thunderbolt 3 port on your Mac, the display will be blank (black, gray, or blue) for up to 2 minutes during installation.
How to switch between Windows and macOS
Usb Mass Storage Support 1.3.5 Free For Mac Software
Restart, then press and hold the Option (or Alt) ⌥ key during startup to switch between Windows and macOS.
Learn more
If you have one of these Intel-based Mac models using OS X El Capitan or later, you don't need a USB flash drive to install Windows:
Usb Mass Storage Support 1.3.5 Free For Macbook Pro
MacBook introduced in 2015 or later
MacBook Air introduced in 2017 or later3
MacBook Pro introduced in 2015 or later3
iMac introduced in 2015 or later
iMac Pro (all models)
Mac Pro introduced in late 2013 or later
To remove Windows from your Mac, use Boot Camp Assistant, not any other utility.
For more information about using Windows on your Mac, open Boot Camp Assistant and click the Open Boot Camp Help button.
1. If you're using an iMac (Retina 5K, 27-inch, Late 2014) or iMac (27-inch, Late 2013) or iMac (27-inch, Late 2012) with a 3TB hard drive and macOS Mojave or later, learn about an alert you might see during installation.
Usb Mass Storage Support 1.3.5 Free For Mac Download
2. For example, if your Mac has 128GB of memory, its startup disk must have at least 128GB of storage space available for Windows. To see how much memory your Mac has, choose Apple menu > About This Mac. To see how much storage space is available, click the Storage tab in the same window.
Usb Mass Storage Support 1.3.5 Free For Mac Download
3. These Mac models were offered with 128GB hard drives as an option. Apple recommends 256GB or larger hard drives so that you can create a Boot Camp partition of at least 128GB.