Future Technology Devices International Ltd. Application Note AN_147 Vinculum-Ii Using Bulk Only Mass Storage (BOMS) Class Devices Example Document Reference No.: FT_000293 Version 1.0 Issue Date: 2010-06-11 This application note illustrates the capabilities of the Vinculum II VNC2 by using a simple application example called “Hello World” that connects and stores data to a USB flash drive. The techniques used in this application note are applicable to the whole range of VNC2-based modules Future Technology Devices International Limited (FTDI) Unit 1, 2 Seaward Place, Glasgow G41 1HH, United Kingdom Tel.: +44 (0) 141 429 2777 Fax: + 44 (0) 141 429 2758 E-Mail (Support): [email protected] Web: http://www.ftdichip.com Copyright © 2010 Future Technology Devices International Limited Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 Table of Contents 1 Introduction .................................................................... 2 1.1 Overview ................................................................................... 2 2 ”Hello World” Application Layout .................................... 3 3 Hardware Setup .............................................................. 4 4 Software ......................................................................... 5 4.1 Header Files .............................................................................. 5 4.2 FTDI Files .................................................................................. 5 4.3 “Hello World” Application Code ................................................. 6 4.3.1 Drivers Includes Section ............................................................................. 6 4.3.2 Setup Section - Main Function ..................................................................... 7 4.3.3 Thread Section .......................................................................................... 8 5 Opening the Application .................................................. 9 6 Building the Application ................................................ 12 7 Flashing or Programming the VNC2 .............................. 13 8 Operation ...................................................................... 14 9 Contact Information ...................................................... 15 Appendix A – List of Figures............................................... 17 Appendix B – References ................................................... 18 Appendix C – Revision History ........................................... 19 Copyright © 2010 Future Technology Devices International Limited 1 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 1 Introduction This application note illustrates the capabilities of the Vinculum-II VNC2 by using a simple application example called “Hello World”. The application illustrates how to connect a USB flash drive (BOMS class) to a Vinculum II VNC2. The application allows a user to create a new text file on a USB flash drive which is connected to USB2 (USB Host 2) of the VNC2 daughteboard plugged on the V2-Eval board and a string “Hello World” is continuously written to the file. The supplied example code is used with the VNC2 V2-EVAL customer evaluation board with a 64-pin VNC2 based daughterboard. Any software code examples given in this document are for information only and are not supported by FTDI. 1.1 Overview This application note gives details of how to interface the Vinculum-II VNC2 device and store data to a USB flash drive (BOMS class). The document firstly describes the layout of the “Hello World” application. It then describes the hardware setup and software structure of the “Hello World” application. Additionally it illustrates the libraries (VOS Kernel Services, device drivers and runtime libraries) and outlines the general structure of the application. This is followed by how to open and build the application and how to load the “Hello World” application ROM file onto the VNC2 device. Lastly there are instructions on how to run the application. Copyright © 2010 Future Technology Devices International Limited 2 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 2 ”Hello World” Application Layout Figure 2.1 illustrates the layout of the “Hello World” application which consists of the file support block (FAT File System), BOMS class driver block and USB host block (USB1 and USB2). The USB flash drive is connected to the USB2 (USB Host1) of the 64-pin VNC2 daughterboard plugged on the V2-Eval board. Figure 2.1 – Application Layout The application requires the following device drivers: The File Support block is layered on top of the BOMS driver. The File support communicates with the device file structure and provides file, directory and disk functions (format, open, read, write and close) to an application. BOMS class driver is layered on top of the USB Host driver. The BOMS driver communicates with a mass storage class of USB device and provides access to the data on a USB drive. It also manages reading and writing data to sectors and clusters on disk The USB Host acts as an interface to the USB flash drive. It performs device enumeration and adds transactions and reports transaction status. Copyright © 2010 Future Technology Devices International Limited 3 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 3 Hardware Setup The “Hello World” application demonstration requires a Host PC, VNC2 customer evaluation board V2Eval, VNC2 64 pin QFN daughterboard, a FAT-formatted USB flash drive and USB 2.0 compliant A-B cable to connect the Host PC and the V2-Eval debugger port. This demonstration also works with the VNC2 48pin QFN daughterboard. Figure 3.1 shows the hardware set-up of the “Hello World” application demonstration: Host PC cable Flash drive Figure 3.1 – Hardware Setup Copyright © 2010 Future Technology Devices International Limited 4 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 4 Software This section explains how the “Hello World” application source code is structured. The application C code is available as a free download with the Vinculum-II Toolchain Installer from the FTDI website. The Vinculum-II Toolchain IDE is designed to support the development of user firmware applications for the FTDI Vinculum-II programmable USB Host / Slave controller devices. The tool suite is a royalty-free, „C‟ based Integrated Development Environment (IDE), which comes complete with compiler, linker and hardware debug tools. The code for this application must be compiled with the Vinculum-II Toolchain IDE Compiler (VinIDE compiler) before being programmed into the VNC2. The compiler translates source code from C program (high-level programming language) to Vinculum II instructions (assembly language). On the Host PC with the Vinculum II Toolchain, installation of the FTDI device driver is required for the FT4232H which is connected to the VNC2 debugger port. Please refer to FTDI website for driver installation. For further details please see AN_142 Vinculum II Toolchain Getting Started Guide and AN_145_Vinculumn-II Toolchain Installation Guide. 4.1 Header Files The “Hello World” application consists of HelloWorld.h file that contains declarations of functions, constant values and all global variable declarations that are used throughout the application. The HelloWorld.h file defines: The size of the stack memory the application thread needs. #define SIZEOF_FIRMWARE_TASK_MEMORY 0x1000 Number of device interfaces that are used within the application. #define NUMBER_OF_DEVICES 3 total number of device interfaces #define VOS_DEV_USB_HOST 0 devices serviced on order 0, 1,2,3,4, 0, 1, 2.... #define VOS_DEV_BOMS 1 #define VOS_DEV_GPIO 2 Please refer to AN_142 Vinculum II Toolchain Getting Started Guide for further details. 4.2 FTDI Files Device drivers, Kernel Services and Runtimes libraries are provided by the Vinculum-II Toolchain Installer in the form of archive files. Each archive file has a corresponding header file that defines its API, providing information on functions and data structures that are contained within the archive files. Both the header files and archive files are included in the “Hello World” application. The String runtime libraries contain string manipulation functions and the Kernel Services provides overall control of the device drivers. The Device drivers are: USB Host driver, the BOMS driver, FAT driver and the GPIO driver which is used for the V2-EVal board LEDs. Please refer to AN_142 Vinculum II Toolchain Getting Started Guide for further details. Copyright © 2010 Future Technology Devices International Limited 5 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 4.3 “Hello World” Application Code The application consists of HelloWorld.c file that contains Drivers includes section which has declarations of the Kernel services, Runtime libraries and Driver header files. It also contains the Setup section which includes a main function. The main function acts as an entry point each time application is run. It initializes the Kernel and drivers, configures IOs, creates a thread and starts the scheduler. And lastly, a thread section which contains firmware code to control the VNC2 device. 4.3.1 Drivers Includes Section Include statements for all header files: #include "vos.h" #include "USBHost.h" #include "USB.h" #include "BOMS.h" #include "FAT.h" #include "GPIO.h" #include "string.h" #include "HelloWorld.h" Declarations: VOS_HANDLE hUsb2, hBoms, hGpio; vos_tcb_t fat_context *tcbFirmware; fatContext; unsigned char *tx_buf = "Hello World! \r\n"; void firmware (void); Copyright © 2010 Future Technology Devices International Limited 6 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 4.3.2 Setup Section - Main Function The Setup section takes care of initialization of the Kernel, CPU clock frequency, Device drivers, IO configuration, create application thread and start kernel scheduler. Initialization of the kernel for the number of devices being used, the time slice for each thread (Quantum) and the interval for timer interrupts (tick) vos_init(10, VOS_TICK_INTERVAL, NUMBER_OF_DEVICES); Initialization of the CPU clock frequency, the default clock frequency for the CPU is 48MHz: vos_set_clock_frequency(VOS_48MHZ_CLOCK_FREQUENCY); The device can also operate at 24MHz or 12MHzfor lower power apps. VN2 IOMux configuration – this matching signals to physical pins: vos_iomux_define_output(12,IOMUX_OUT_GPIO_PORT_A_1);//LED3,GPIO port A bit 1 to pin 12 vos_iomux_define_output(13,IOMUX_OUT_GPIO_PORT_A_2); //LED4,GPIO port A bit 2 to pin 13 vos_iomux_define_output(29,IOMUX_OUT_GPIO_PORT_A_5); //LED5, GPIO port A bit 5 to pin 29 vos_iomux_define_output(31,IOMUX_OUT_GPIO_PORT_A_6); //LED6, GPIO port A bit 6 to pin 31 vos_iomux_define_output(39,IOMUX_OUT_UART_TXD); //UART Tx, // UART to V2EVAL board pins vos_iomux_define_input(40,IOMUX_IN_UART_RXD); //UART Rx vos_iomux_define_output(41,IOMUX_OUT_UART_RTS_N); //UART RTS# vos_iomux_define_input(42,IOMUX_IN_UART_CTS_N); //UART CTS# Initialization of the USBHost driver: usbhost_init(-1, VOS_DEV_USB_HOST, &usb_ctx); Initialization of the BOMs driver: boms_init(VOS_DEV_BOMS); Initialization of the GPIO driver: gpioCtx.port_identifier = GPIO_PORT_A; gpio_init(VOS_DEV_GPIO,&gpioCtx); Initialization of the FAT driver: fat_init(); Create the application thread: tcbFirmware = vos_create_thread(29, SIZEOF_FIRMWARE_TASK_MEMORY, firmware, 0); Start the scheduler: vos_start_scheduler(); Every application includes a vos_start_scheduler and should be the last instruction after all configuration is done. Copyright © 2010 Future Technology Devices International Limited 7 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 4.3.3 Thread Section This section contains firmware code to control the VNC2 device. Opens the handle to the devices: hsb = vos_dev_open(VOS_DEV_USB_HOST2); hGpio = vos_dev_open(VOS_DEV_GPIO); hBoms = vos_dev_open(VOS_DEV_BOMS); fatContext = fat_open(hBoms, 0, NULL); fat_fileOpen(fatContext, &FILE, "HelloWorld.TXT",FILE_MODE_APPEND | FILE_MODE_PLUS); Finds BOMS class device: hc_iocb_class.dev_class = USB_CLASS_MASS_STORAGE; hc_iocb_class.dev_subclass = USB_SUBCLASS_MASS_STORAGE_SCSI; hc_iocb_class.dev_protocol = USB_PROTOCOL_MASS_STORAGE_BOMS; Finds first hub device: hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS; hc_iocb.handle.dif = NULL; hc_iocb.set = &hc_iocb_class; hc_iocb.get = &ifDev2; Attach BOMS class to the USB Host and FAT class to the BOMS: boms_att.hc_handle = hUsb; boms_att.ifDev = ifDev2; boms_iocb.ioctl_code = MSI_IOCTL_BOMS_ATTACH; boms_iocb.set = &boms_att; boms_iocb.get = NULL; bomsStatus = vos_dev_ioctl(hBoms, &boms_iocb); Write to the file: fat_fileWrite(&FILE, (unsigned long)(strlen(tx_buf)), tx_buf, NULL, NULL); Closes the handle to the devices: status = fat_fileClose(&FILE); fat_close(fatContext); vos_dev_close(hBoms); Please refer to AN_142 Vinculum II Toolchain Getting Started Guide for further details. Copyright © 2010 Future Technology Devices International Limited 8 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 5 Opening the Application Following the Vinculum-II Toolchain installation process, by default, the Vinculum-II Toolchain IDE is located within the Program Files/FTDI/Vinculum II Tool Chain directory on the local hard disk; there will also be a start menu shortcut created, under the FTDI/Vinculum II Tool Chain folder heading. The Vinculum-II Toolchain Installer can be downloaded free from the FTDI website. Following a successful installation of the Vinculum-II Toolchain, launch the application by double clicking on Vinculum-II Toolchain icon on the desktop. The “Hello World” application will be saved within My Documents folder of your PC. Select File tab within the toolbar and click Open under the Project group (see Figure 5.1). Figure 5.1 – Opening Project Using File Tab Alternatively, go to the circular Vinculum button and click Open->Project Figure 5.2 – Opening Project Using Circular Vinculum Button Copyright © 2010 Future Technology Devices International Limited 9 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 This will result in the Open Existing Project dialog box (see Figure 5.3) appearing. Browse to My Documents and find the folder FTDI/Firmware/Samples/1.0.4/General. Within this will be a folder called HelloWorld containing a file HelloWorld.vproj (vproj is the file extension used by all VNC2 project files) double click the file to open the “Hello World” Application within the Vinculum-II Toolchain IDE. Figure 5.3 – Opening Existing Project Window Copyright © 2010 Future Technology Devices International Limited 10 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 To open the “Hello World” application project click the Open button and the application project opens within the VNC2 Toolchain IDE (Figure 5.4). Figure 5.4 – VNC2 Toolchain IDE Window Copyright © 2010 Future Technology Devices International Limited 11 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 6 Building the Application This section contains step-by-step instructions for building the “Hello World” application. Once an application is opened, it is necessary to clean and build the application to delete files from a previous build. This build also creates an executable file for VNC2. To build the application, select Build tab within the toolbar and click Clean and then Build under the Build group (see Figure 6.1). Figure 6.1 – Building Project Clicking Clean will delete the object and ROM file to ensure only new files are generated. Following Clean, click Build to have the Vinculum-II Toolchain IDE Compiler compile, assemble and link the source code into a file format (ROM file) that can be loaded onto the VNC2 device. This pops up a Compiling dialog box (Figure 7.2) which shows a number of warnings and compilation errors (if there are any). Figure 6.2 – Compiling Window If the “Hello World” application source code is not altered, the application should successfully build with no compilation errors or warnings (see Figure 7.2). This shows that the HelloWorld.ROM file has been successfully created. Additional information is also sent by the compiler and linker to the Message Window at the bottom of the IDE main window (see Figure 6.3). Ensure there are no errors. Figure 6.3 – Message Window Copyright © 2010 Future Technology Devices International Limited 12 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 7 Flashing or Programming the VNC2 In order to program the “Hello World” application into the VNC2 device, it is necessary to plug the 64 pin QFN daughter-board onto the VNC2 daughter-board connector – J1, J2, J3 and J4 and connect the V2Eval board debugger port to the development Host PC using the USB A-B cable. When the V2-Eval board is connected, switch it ON using SW1 (located just below the black power supply socket). The Host PC may attempt to install FTDI drivers for the FT4232H connected to the debugger port. Please visit FTDI website and download the necessary driver which matches your operating system. Go back into the IDE and select Debug tab within the toolbar and click drop-down menu in the Debugger Interface which initiates the IDE to search for connected devices. This will automatically select the debugger interface of the FTDI V2-Eval board (see Figure 7.1). Port B of the FT4232H on the V2-Eval board is connected to the VNC2 debug port. Figure 7.1 – Debugger Interface Program the flash memory of the VNC2 by selecting the Flash button from the Debug tab, Select ROM file to program dialog box (see Figure 7.2) will open showing the HelloWorld.ROM image file that was built earlier, select this file and click open Figure 7.2 – Select ROM File to Program Window The LED9 and LED10 located on the V2-Eval board will flash. The VinIDE will now program the VNC2 flash and a Flashing Rom progressing bar will appear to indicate progress and disappear after successfully completing the VNC2 programming. Additional information is shown within the Message Window at the bottom of the IDE main window. Copyright © 2010 Future Technology Devices International Limited 13 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 8 Operation The following sequence is required to run the “Hello World” application demonstration: 1. 2. 3. 4. 5. 6. 7. Apply power to the V2-Eval board Connect the USB flash drive to USB2 of the V2-Eval board LED3 located on the V2-Eval board should flash sequentially. This indicates that the USB device connected to USB2 has not been enumerated. The VNC2 device waits for the RESET button to be pressed using the SW2 switch on the V2-Eval board. Press the RESET button switch (SW2) to manually reset the V2-Eval board. The VNC2 will detect the RESET and the USB Flash connected to the V2-Eval board will be enumerated. The LED3 on the V2-Eval board should now stay ON which indicates the completion of the USB device enumeration A new text file will be created and a string “Hello World” will be written continuously until the V2-Eval board is turned OFF, unplugged from the Host PC or the USB flash is removed from the V2-Eval board. Ensure that the V2-Eval board is turned OFF before removing the flash drive. Remove the flash drive from the board and insert it into the Host PC to open the created text file (see Figure 8.1). Figure 8.1 – “Hello World” Text File Displayed Copyright © 2010 Future Technology Devices International Limited 14 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 9 Contact Information Head Office – Glasgow, UK Future Technology Devices International Limited Unit 1, 2 Seaward Place, Centurion Business Park Glasgow G41 1HH United Kingdom Tel: +44 (0) 141 429 2777 Fax: +44 (0) 141 429 2758 E-mail (Sales) E-mail (Support) E-mail (General Enquiries) Web Site URL Web Shop URL [email protected] [email protected] [email protected] http://www.ftdichip.com http://www.ftdichip.com Branch Office – Taipei, Taiwan Future Technology Devices International Limited (Taiwan) 2F, No. 516, Sec. 1, NeiHu Road Taipei 114 Taiwan , R.O.C. Tel: +886 (0) 2 8791 3570 Fax: +886 (0) 2 8791 3576 E-mail (Sales) E-mail (Support) E-mail (General Enquiries) Web Site URL [email protected] [email protected] [email protected] http://www.ftdichip.com Branch Office – Hillsboro, Oregon, USA Future Technology Devices International Limited (USA) 7235 NW Evergreen Parkway, Suite 600 Hillsboro, OR 97123-5803 USA Tel: +1 (503) 547 0988 Fax: +1 (503) 547 0987 E-Mail (Sales) E-Mail (Support) E-Mail (General Enquiries) Web Site URL [email protected] [email protected] [email protected] http://www.ftdichip.com Branch Office – Shanghai, China Future Technology Devices International Limited (China) Room 408, 317 Xianxia Road, Shanghai, 200051 China Tel: +86 21 62351596 Fax: +86 21 62351595 E-mail (Sales) E-mail (Support) E-mail (General Enquiries) Web Site URL [email protected] [email protected] [email protected] http://www.ftdichip.com Copyright © 2010 Future Technology Devices International Limited 15 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 Distributor and Sales Representatives Please visit the Sales Network page of the FTDI Web site for the contact details of our distributor(s) and sales representative(s) in your country. Vinculum is part of Future Technology Devices International Ltd. Neither the whole nor any part of the information contained in, or the product described in this manual, may be adapted or reproduced in any material or electronic form without the prior written consent of the copyright holder. This product and its documentation are supplied on an as-is basis and no warranty as to their suitability for any particular purpose is either made or implied. Future Technology Devices International Ltd will not accept any claim for damages howsoever arising as a result of use or failure of this product. Your statutory rights are not affected. This product or any variant of it is not intended for use in any medical appliance, device or system in which the failure of the product might reasonably be expected to result in personal injury. This document provides preliminary information that may be subject to change without notice. No freedom to use patents or other intellectual property rights is implied by the publication of this document. Future Technology Devices International Ltd, Unit 1, 2 Seaward Place, Centurion Business Park, Glasgow G41 1HH United Kingdom. Scotland Registered Number: SC136640 Copyright © 2010 Future Technology Devices International Limited 16 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 Appendix A – List of Figures Figure 2.1 – Application Layout .................................................................................. 3 Figure 3.1 – Hardware Setup ...................................................................................... 4 Figure 5.1 – Opening Project Using File Tab ............................................................... 9 Figure 5.2 – Opening Project Using Circular Vinculum Button .................................... 9 Figure 5.3 – Opening Existing Project Window ......................................................... 10 Figure 5.4 – VNC2 Toolchain IDE Window ................................................................ 11 Figure 6.1 – Building Project .................................................................................... 12 Figure 6.2 – Compiling Window ................................................................................ 12 Figure 6.3 – Message Window .................................................................................. 12 Figure 7.1 – Debugger Interface .............................................................................. 13 Figure 7.2 – Select ROM File to Program Window ..................................................... 13 Figure 8.1 – “Hello World” Text File Displayed ......................................................... 14 Copyright © 2010 Future Technology Devices International Limited 17 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 Appendix B – References AN_145: Vinculum-II Toolchain Installation Guide AN_142: Vinculum-II Tool Chain Getting Started Guide AN_137: Vinculum-II IO Cell Description AN_138: Vinculum-II Debug Interface Description AN_139: Vinculum-II IO Mux Explained AN_140: Vinculum-II PWM Example AN_144: VINCULUM-II IO Mux Configuration Utility User Guide Copyright © 2010 Future Technology Devices International Limited 18 Document Reference No.: FT_000293 Vinculum-II Using Bulk Only Mass Storage (BOMS) Class Devices Example Application Note AN_147 Version 1.0 Clearance No.: FTDI# 161 Appendix C – Revision History Revision 1.0 Changes Initial Release Copyright © 2010 Future Technology Devices International Limited Date 2010-06-11 19