This repository explains how to extend a MDK-Middleware example to an user application. This application starts with USB Device MassStorage example and adds the File System for data storage on a SD Card. The BOTTON0 switches data storage access between USB Host (SD Card appears as USB memory device on Host computer) and embedded application for file access.
Initial development starts on the STM32F746G-DISCO board with a compatible board layer. A copy of this layer is then modified for the user hardware. In USB_Device.csolution.yml two target-types enable development on DISCO board or CustomHW.
The device peripherals are configured using STM32CubeMX and with it A/D converter functionality is added. For debugging ST-LINK, a CMSIS-DAP adapter, or J-Link may be used.
Watch this video to learn more...
- Install Keil Studio for VS Code from the VS Code marketplace.
- Clone this repository (for example using Git in VS Code) or download the ZIP file. Then open the base folder in VS Code.
- Open the CMSIS View. This should show the USB_Device application with the selected project MassStorage.
- The related tools and software packs are downloaded and installed. Review progress with View - Output - CMSIS Solution.
- In the CMSIS view, use the Action buttons to build, load and debug the example on the hardware.
Tip
Examples can be explored using the Keil MDK Community edition that is free-to-use for training and evaluation.
-
Initial State (USB owns the media):
When the application starts,
USBD_MSC0_SetMediaOwnerUSB()is called in the functionapp_main_thread(). The storage media is then controlled by the USB interface and the host PC can read/write files to the device. -
When Button is Pressed:
The application calls
USBD_MSC0_SetMediaOwnerFS()which transfers media ownership from USB to the user File System interface. Now the embedded application can safely access the file system. The application reads the fileTest.txtand once this is complete, it callsUSBD_MSC0_SetMediaOwnerUSB()to return ownership back to USB.
This repository is configured as a Git workspace for VS Code and can be effectively used with the VS Code Git integration via the following files:
- vcpkg-configuration.json controls the required tools with the Arm Tools Environment Manager.
.gitignoreexcludes files that contain user specific setup, for example.vscodeand*.cbuild*.yml
This is a list of the relevant files and directories:
| File/Directory | Description |
|---|---|
| vcpkg-configuration.json | List of tools installed (by Arm Tools Environment Manager) in VS Code |
| USB_Device.csolution.yml | Main solution file containing USB Device example projects |
| HID | USB HID Device example project (not used for the application) |
| MassStorage | USB Mass Storage Device example project (adapted for user application) |
| VirtualCOM | USB Virtual COM Port Device example project (not used for the application) |
| Board | Board support layers for STM32F746G-DISCO and custom hardware |
