This section describes all the steps required to build a USB-based application. The instructions provided in this section are not intended for any particular toolchain, but instead are described in a generic way that can be adapted to any toolchain.
The best way to start building a USB-based project is to start from an existing project. If you are using µC/OS-II or µC/OS-III, Micrium provides example projects for multiple development boards and compilers. If your target board is not listed on Micrium’s web site, you can download an example project for a similar board or microcontroller.
The purpose of the sample project is to allow a host to enumerate your device. You will add a USB class instance to both, full-speed and high-speed configurations (if both are supported by your controller). Refer to the Class Instance Concept page for more details about the class instance concept. After you have successfully completed and run the sample project, you can use it as a starting point to run other USB class demos you may have purchased.
µC/USB-Device requires a Real-Time Operating System (RTOS). The following assumes that you have a working example project running on µC/OS-II or µC/OS-III.
Understanding Micrium Examples
A Micrium example project is usually placed in the following directory structure.
\Micrium \Software \EvalBoards \<manufacturer> \<board_name> \<compiler> \<project name> \*.*
Note that Micrium does not provide by default an example project with the µC/USB-Device distribution package. Micrium examples are provided to customers in specific situations. If it happens that you receive a Micrium example, the directory structure shown above is generally used by Micrium. You may use a different directory structure to store the application and toolchain projects files.
\Micrium
This is where Micrium places all software components and projects. This directory is generally located at the root directory.
\Software
This sub-directory contains all software components and projects.
\EvalBoards
This sub-directory contains all projects related to evaluation boards supported by Micrium.
\<manufacturer>
This is the name of the manufacturer of the evaluation board. In some cases this can also be the name of the microcontroller manufacturer.
\<board name>
This is the name of the evaluation board.
\<compiler>
This is the name of the compiler or compiler manufacturer used to build the code for the evaluation board.
\<project name>
The name of the project that will be demonstrated. For example a simple µC/USB-Device with µC/OS-III project might have the project name ‘uCOS-III-USBD’.
\*.*
These are the source files for the project. This directory contains configuration files app_cfg.h
, os_cfg.h
, os_cfg_app.h
, cpu_cfg.h
and other project-required sources files.
os_cfg.h
is a configuration file used to configure µC/OS-III (or µC/OS-II) parameters such as the maximum number of tasks, events, objects, which µC/OS-III services are enabled (semaphores, mailboxes, queues), and so on. os_cfg.h
is a required file for any µC/OS-III application. See the µC/OS-III documentation and books for further information.
app.c
contains the application code for the example project. As with most C programs, code execution starts at main()
. At a minimum, app.c
initializes µC/OS-III and creates a startup task that initializes other Micrium modules.
app_cfg.h
is a configuration file for your application. This file contains #defines
to configure the priorities and stack sizes of your application and the Micrium modules’ tasks.
app_<module>.c
and app_<module>.h
These optional files contain the Micrium modules’ (µC/TCP-IP, µC/FS, µC/USB-Host, etc) initialization code. They may or may not be present in the example projects.
Copying and Modifying Template Files
Copy the files from the application template and configuration folders into your application as illustrated in .
app_usbd.*
is the master template for USB application-specific initialization code. This file contains the function App_USBD_Init()
, which initializes the USB stack and class-specific demos.
app_usbd_<class>.c
contains a template to initialize and use a certain class. This file contains the class demo application. In general, the class application initializes the class, creates a class instance, and adds the instance to the full-speed and high-speed configurations. Refer to the chapter(s) of the USB class(es) you purchased for more details about the USB class demos.
usbd_cfg.h
is a configuration file used to setup µC/USB-Device stack parameters such as the maximum number of configurations, interfaces, or class-related parameters.
usbd_dev_cfg.c
and usbd_dev_cfg.h
are configuration files used to set device parameters such as vendor ID, product ID, and device release number. They are also necessary to configure the USB device controller driver parameters, such as base address, dedicated memory base address and size, controller’s speed, and endpoint capabilities.
Modify Device Configuration
Modify the device configuration file (usbd_cfg.c
) as needed for your application. See below for details.
Modify Driver Configuration
Modify the driver configuration (usbd_dev_cfg.c
) as needed for your controller. See below for details.
Modify USB Application Initialization Code
shows the code that you should modify based on your specific configuration done previously. You should modify the parts that are highlighted by the text in bold. The code snippet is extracted from the function App_USBD_Init()
defined in app_usbd.c
. The complete initialization sequence performed by App_USBD_Init()
is presented in .
Including USB Device Stack Source Code
First, include the following files in your project from the µC/USB-Device source code distribution, as indicated in .
Second, add the following include paths to your project’s C compiler settings:
\Micrium\Software\uC-USB-Device-V4\
If you are using the MSC class, add the following include path:
\Micrium\Software\uC-USB-Device-V4\Class\MSC\Storage\<storage name>
Modifying the Application Configuration File
The USB application initialization code templates assume the presence of app_cfg.h
. The following #defines
must be present in app_cfg.h
in order to build the sample application.
Besides the file app_cfg.h
, another application file, app_usbd_cfg.h
, specific to class demos should be modified according to the class(es) you want to play with. For that, the following #defines
allows you to enable class demos.
app_usbd_cfg.h
contains also other #defines
specific to each class. Refer to the proper class application configuration section presented in this table for more details.
Every USB class also needs to have certain constants defined to work correctly. presents the section to refer to based on the USB class.