ST AN1475 Application note

AN1475
APPLICATION NOTE
DEVELOPING AN ST7265x
MASS STORAGE APPLICATION
By Microcontroller Division Applications
INTRODUCTION
This application note describes how to develop a USB Mass Storage application using an ST7265x microcontroller.
The proposed solution includes a generic USB Mass Storage Layer (MSL) compliant with the USB Mass Storage Class that can be used for all types of storage media (FLASH memory cards, hard disk drive, etc.) and a dedicated Media Access Layer (MAL) add-in for each type of storage media.
The MSL and the MAL modules are available to ST customers on request. C ontact your ST sales office to obtain the ST7265 Mass Storage software.
The MSL and the MAL must be considered as function libraries and therefore cannot be mod­ified by the user. The softwa re interfaces of these function l ibraries provide the us er with the required flexibility for designing his application:
– type and number of media, – insertion/withdrawal management, – protection management, – user interface.
Note that the MAL requires the use of certain fixed MCU pins to interface with the various me­diums. As a res ult, a specific app lication hardwa re configur ation is requ ired when us ing the MAL.
AN1475/0202 1/8
1
DEVELOPING AN ST 7265x M ASS STORAGE A PPLICATION
1 SOFTWARE ARCHITECTUR E
The ST7265 software is designed in modules. Each module has a unique and clearly defined interface. This architecture enables the user to easily replace any module and to reuse the in­dividual module in other projects. This architecture provides maximum flexibility so users are able to cust omize t heir ap plicati on as th ey wan t. The mo dule softwa re desi gn is show ed in
Figure 1.
Figure 1. ST7265 Mass Storage Application Architecture
LUN Assignment
USB Mass Storage Layer
User Application
Status
Information
Media Configuration
Media Access Layer
Storage
Media
= ST provided module
All the components des cribed above are grouped into a pr oject. The “Status Informa tion” in ­terface enables the user to monitor the execution of the software. The “Med ia Configuration” interface enables the user to customize the application configuration.
Medium-independent Medium-dependent
2/8
2
DEVELOPING AN ST7265x MASS STORAGE APPLICATION
2 PROJECT CONTENT
Files required for the various modules are grouped into different directories. Most files are user application independent; i.e. they are not des igned to be modified by the user application. Other files are application dependent and can be modified by the user. Table 1 explain s the usage of the files included in the project.
Table 1. Application Files
Directory Path/File Usage
Appli.c, Appli.h
Descript.c, Descript.h
MCL
(Application
specific)
MAS
Sto
USBlib All files.
MAL_Func.c
Mconfig.h
Int_7265.c, Int_7265.h
Micro
MAL
Class All files
Cond­comp.h
Main.c User_lib.c,
User_lib.h
Application-related routines (called from main.c) to be developed by the user.
These files contain all the descriptors for the USB enu­meration. These files are designed to be modified by the user depending on the user application.
This file contains the global Media Access Library set­tings. These files are designed to be modified by the user depending on the user application.
Definitions of the software interface described in the document. These files are designed to be modified by the user depending on the user application.
Groups all interrupt routines. These files areto be mod­ified by the user depending on the user application.
Conditional compilation definitions. This file is used to configure the USB behaviour. This file is not designed to be modified by the user.
Main software entry point. This file is not designed to be modified by the user (see Appli.c)
USB routines related to this application. These files are not designed to be modified by the user.
Media Access Library. These files are not designed to be modified by the user.
Files related to the standard Mass Storage operation. These files are not designed to be modified by the user.
Files related to the standard USB operations. These files are not designed to be modified by the user.
3/8
DEVELOPING AN ST 7265x M ASS STORAGE A PPLICATION
3 USING THE MASS STORAGE LIBRARIES
3.1 MAXIMUM NUMBER OF LOGICA L UNITS
A constant repres entin g the numb er o f m edium slots imple ment ed in th e appl ication pro ject must be defined by the user application.
#define MAX_LUN
The valid range of this variable is between 0 and 15. The MAX_LUN value is one less than the number of slots; for example, if the MAX_LUN value is 3, there are 4 slots.
3.2 MEDIA SELECTION
A Media Access Layer (MAL) add-in for each type of storage media is provided by STMicroe­lectronics. Several functions are provided with this interface and are called using a single entry function. To assign logical units to each type of media, an array pointing to the en try function must be provided by the application.
const void (*Mal_Func[MAX_LUN+1])();
The medium is identified by the index of this array. For example, the function array is assigned as:
extern void MAL_SMC_Funcs(void); include SMC support in MAL extern void MAL_MMC_Funcs(void); include MMC support in MAL
; Assign LUNs (Logical Unit Numbers) in ascending order starting with LUN0
const void (*Mal_Func[MAX_LUN+1])() = {
MAL_SMC_Funcs, MAL_MMC_Funcs };
In the above example, the MAL_SMC_Funcs() function is provided with the MAL for SMC and the MAL_MMC_Funcs() function is provided with the MAL for MMC. Thus, the SMC device wi ll be identified as LUN0 and the MMC device will be identified as LUN1.
3.3 INTERFACE DESC RIPTION
3.3.1 Hardware Interfaces
3.3.1.1 USB Interface
The pins used for the USB connection are defined in the ST7265x product datasheet.
4/8
DEVELOPING AN ST7265x MASS STORAGE APPLICATION
3.3.1.2 Compact Flash Card 8-bit Memory Mod e
Some ha rdw are inte rfa ce pins are fi xed by the M AL fir mwa re as s hown in the t able be low .
CompactFlash­Bus
ST7265x Pin PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PA0 PA1 PA2 PA3 PA5
D0 D1 D2 D3 D4 D5 D6 D7 A0 A1 A2 RE WE
Other pins are user definable in the Media Configuration Module (Mconfig.c) In this configuration, pi ns PA4, PA 6 and PA7 c an o nly be used as inputs (no interrupt capa-
bility) .
3.3.1.3 SmartMediaCard Interface
Some ha rdw are inte rfac e pins are fi xed by the M AL fir mwa re as shown i n the table below . Other pins are user definable in the Media Configuration Module (Mconfig.c)
SmartMediaBus D0 D1 D2 D3 D4 D5 D6 D7 ALE WE RE ST7265x Pin PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PA2 PA1 PA3 PA4 PA0
RBUSY
CLE
In this configuration, pi ns PA5, PA 6 and PA7 c an o nly be used as inputs (no interrupt capa­bility) .
3.3.1.4 MultiMediaCard Interface
This interf ace is used for Multimedi aCard (MMC), Secure Di gital (SD) Car d in MMC mode and Hitachi ca rds.
Some ha rdw are inte rfac e pins are fi xed by the M AL fir mwa re as shown i n the table below . Other pins are user definable in the Media Configuration Module (Mconfig.c).
MMC Bus DATA COMMAND CLOCK ST7265x Pin PE6 PE5 PE7
3.3.1.5 Sony Stick
Some ha rdw are inte rfac e pins are fi xed by the M AL fir mwa re as shown i n the table below . Other pins are user definable in the Media Configuration Module (Mconfig.c).
Sony Stick Bus BS DATA CLOCK ST7265x Pin PC1 PC2 PC3
3.3.2 Software Interfaces
The software interfaces described in this document are not media specific.
3.3.2.1 Status Information Medium Capacity
The capacity of each medium can be read from the Medium_Capacity[ ] variable
DWORD Medium_Capacity[MAX_LUN+1];
5/8
DEVELOPING AN ST 7265x M ASS STORAGE A PPLICATION
The medium is identified by the index of this array.
Current Operation
The MAL_State variable gives the internal state of the current operati on. Read, wr ite, format and verify operations are indicated with this variable. The following values are availabl e for the MAL_State function:
#define MAL_IDLE 0 // no operation #define MAL_READING 1 // upload data to USB #define MAL_WRITING 2 // download data from USB #define MAL_VERIFYING 3 // verifying #define MAL_FORMATTING 4 // formatting #define MAL_MEM_READING 5 // reading data to RAM #define MAL_MEM_WRITING 6 // writing data from RAM
Active Medium
The MAL_Mediano variable identifies the medium that is currently accessed.
unsigned charMAL_Mediano;
3.3.2.2 Media Configuration
This interface is related with the physi cal and electrical configuration of the media dev ice itself. Through this interface, the user must provide certain information to the MAL or carry out cer­tain functions required by the MAL. I ndeed, some functions depend o n the us er hardware or software implementation, and can therefore not be directly carried out by the MAL.
None of the fu nctio ns def ined in this sec tion ca n be omi tted. Ev en if no ac tion is taken, the function must be defined.
Existence of the Medium
There are two operations in this category, medium existence testing and the medium removal interrupt.
Medium ex istence testin g should be done by th e user app lica tion. The ap plica tion calls the MAL_Medium_Plug() interrupt to inform the MAL library that a medium is present:
void MAL_Medium_Plug(unsigned char slot)
The slot parameter indicates which medium is present. The user appli cation sho uld use an interrupt rout ine to mo nitor me dium rem oval. When the
medium is removed, an interrupt is triggered and an application-defined interrupt routine is called. In this interrupt routine, the user application calls the MAL_Medium_Removing() func­tion to notify the MAL that the medium is removed. The parameter indicates the slot where the medium removal has occurred. The MAL guarantees that the MAL_Medium_Removing() function returns to the medium removal interrupt routine as soon as possible. The template of this function is:
void MAL_Medium_Removing(char Index);
6/8
DEVELOPING AN ST7265x MASS STORAGE APPLICATION
The index parameter indicates the medium that has been removed.
Selection of the Medium
Medium select and deselect operations are defined as follows:
#define SELECT() #define DESELECT()
The index parameter indicates the medium to be selected or deselected. The evaluation values of these two operations are not important. The calling function is used
to detect the existence of the medium. The SELECT() function enables the chip select bit of the selected device, and the DESE-
LECT() function disab les the chip select bit of the selected devi ce. The applicati on can (op­tional) indicate the media being accessed by switching ON an LED in the SELECT() function and switching OFF the LED in the DESELECT() function.
Once the SELECT() function is executed, the media is ready to be accessed.
Detection of the Write Protection
The testing of the write protection is defined as:
#define isWRITE_PROTECT()
The index parameter indicates the medium to be tested. The value of this operati on is non-zer o if the medium is write- protected, otherwise a zero is
emitted.
Medium Initialization
The media ready function is initialized by the user application. For example, the user applica­tion must verify that the medium acc ess is author ized. Either the MAL or the MSL assumes that the medium is powered on and ready to be operated after the SELECT() function is exe­cuted.
7/8
DEVELOPING AN ST 7265x M ASS STORAGE A PPLICATION
“THE PRESENT NOTE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH INFORMATION REGARDING THE IR PRO DUCT S IN OR DER FO R THEM TO SAV E TIME . AS A RES ULT, STMIC ROEL ECTR ONI CS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CL AIM S AR IS IN G FR OM T HE CO N TENT OF S UC H A NO TE A ND /O R T HE U SE M AD E BY C US TO ME RS O F THE INFORMATION CONTAINED HEREIN IN CONNEXION WITH THEIR PRODUCTS.”
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implic ation or otherwise under any patent or patent ri ghts of STM i croelectr oni cs. Spec i fications mentioned i n this publication are subje ct to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as cri tical comp onents in life support dev i ces or systems wi thout the express written approv al of STMicroel ectronics.
The ST logo is a registered trademark of STMicroelectronics
2002 STMicroelectronics - All Rights Reserved.
STMicroelectronics Group of Compan i es
http://www.s t. com
Purchase of I
2
C Components by STMicroelectronics conveys a license under the Philips I2C Patent. Rights to use the se components in an
2
I
C system i s granted pro vi ded that the sy stem conforms to the I2C Standard Specification as defined by Philips.
Australi a - B razil - Canada - China - Finl and - France - Germany - Hong Kong - Ind ia - Israel - Italy - Japan
Malaysi a - M al ta - Morocco - Singapore - Spain - Sw eden - Switz erland - United Kingdom - U.S.A.
8/8
Loading...