Simple USBHost library for STM32F746NG Discovery board. Only either the Fastspeed or the Highspeed port can be used( not both together)

Dependents:   DISCO-F746NG_USB_Host

Fork of KL46Z-USBHost by Norimasa Okamoto

Committer:
DieterGraef
Date:
Fri Jun 17 09:00:35 2016 +0000
Revision:
25:7d6d9fc471bf
Parent:
24:5396b6a93262
USB Host now works with both Interfaces even in parallel. Some changes in the USB MSD driver to make it operable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 24:5396b6a93262 1 /* mbed Microcontroller Library
DieterGraef 24:5396b6a93262 2 * Copyright (c) 2006-2012 ARM Limited
DieterGraef 24:5396b6a93262 3 *
DieterGraef 24:5396b6a93262 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
DieterGraef 24:5396b6a93262 5 * of this software and associated documentation files (the "Software"), to deal
DieterGraef 24:5396b6a93262 6 * in the Software without restriction, including without limitation the rights
DieterGraef 24:5396b6a93262 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
DieterGraef 24:5396b6a93262 8 * copies of the Software, and to permit persons to whom the Software is
DieterGraef 24:5396b6a93262 9 * furnished to do so, subject to the following conditions:
DieterGraef 24:5396b6a93262 10 *
DieterGraef 24:5396b6a93262 11 * The above copyright notice and this permission notice shall be included in
DieterGraef 24:5396b6a93262 12 * all copies or substantial portions of the Software.
DieterGraef 24:5396b6a93262 13 *
DieterGraef 24:5396b6a93262 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
DieterGraef 24:5396b6a93262 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
DieterGraef 24:5396b6a93262 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
DieterGraef 24:5396b6a93262 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
DieterGraef 24:5396b6a93262 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
DieterGraef 24:5396b6a93262 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
DieterGraef 24:5396b6a93262 20 * SOFTWARE.
DieterGraef 24:5396b6a93262 21 */
DieterGraef 24:5396b6a93262 22 #include "ff.h"
DieterGraef 24:5396b6a93262 23 #include "ffconf.h"
DieterGraef 24:5396b6a93262 24 #include "mbed_debug.h"
DieterGraef 24:5396b6a93262 25
DieterGraef 24:5396b6a93262 26 #include "FATFileHandle.h"
DieterGraef 24:5396b6a93262 27
DieterGraef 24:5396b6a93262 28 FATFileHandle::FATFileHandle(FIL fh) {
DieterGraef 24:5396b6a93262 29 _fh = fh;
DieterGraef 24:5396b6a93262 30 }
DieterGraef 24:5396b6a93262 31
DieterGraef 24:5396b6a93262 32 int FATFileHandle::close() {
DieterGraef 24:5396b6a93262 33 int retval = f_close(&_fh);
DieterGraef 24:5396b6a93262 34 delete this;
DieterGraef 24:5396b6a93262 35 return retval;
DieterGraef 24:5396b6a93262 36 }
DieterGraef 24:5396b6a93262 37
DieterGraef 24:5396b6a93262 38 ssize_t FATFileHandle::write(const void* buffer, size_t length) {
DieterGraef 24:5396b6a93262 39 UINT n;
DieterGraef 24:5396b6a93262 40 FRESULT res = f_write(&_fh, buffer, length, &n);
DieterGraef 24:5396b6a93262 41 if (res) {
DieterGraef 24:5396b6a93262 42 debug_if(FFS_DBG, "f_write() failed: %d", res);
DieterGraef 24:5396b6a93262 43 return -1;
DieterGraef 24:5396b6a93262 44 }
DieterGraef 24:5396b6a93262 45 return n;
DieterGraef 24:5396b6a93262 46 }
DieterGraef 24:5396b6a93262 47
DieterGraef 24:5396b6a93262 48 ssize_t FATFileHandle::read(void* buffer, size_t length) {
DieterGraef 24:5396b6a93262 49 debug_if(FFS_DBG, "read(%d)\n", length);
DieterGraef 24:5396b6a93262 50 UINT n;
DieterGraef 24:5396b6a93262 51 FRESULT res = f_read(&_fh, buffer, length, &n);
DieterGraef 24:5396b6a93262 52 if (res) {
DieterGraef 24:5396b6a93262 53 debug_if(FFS_DBG, "f_read() failed: %d\n", res);
DieterGraef 24:5396b6a93262 54 return -1;
DieterGraef 24:5396b6a93262 55 }
DieterGraef 24:5396b6a93262 56 return n;
DieterGraef 24:5396b6a93262 57 }
DieterGraef 24:5396b6a93262 58
DieterGraef 24:5396b6a93262 59 int FATFileHandle::isatty() {
DieterGraef 24:5396b6a93262 60 return 0;
DieterGraef 24:5396b6a93262 61 }
DieterGraef 24:5396b6a93262 62
DieterGraef 24:5396b6a93262 63 off_t FATFileHandle::lseek(off_t position, int whence) {
DieterGraef 24:5396b6a93262 64 if (whence == SEEK_END) {
DieterGraef 24:5396b6a93262 65 position += _fh.fsize;
DieterGraef 24:5396b6a93262 66 } else if(whence==SEEK_CUR) {
DieterGraef 24:5396b6a93262 67 position += _fh.fptr;
DieterGraef 24:5396b6a93262 68 }
DieterGraef 24:5396b6a93262 69 FRESULT res = f_lseek(&_fh, position);
DieterGraef 24:5396b6a93262 70 if (res) {
DieterGraef 24:5396b6a93262 71 debug_if(FFS_DBG, "lseek failed: %d\n", res);
DieterGraef 24:5396b6a93262 72 return -1;
DieterGraef 24:5396b6a93262 73 } else {
DieterGraef 24:5396b6a93262 74 debug_if(FFS_DBG, "lseek OK, returning %i\n", _fh.fptr);
DieterGraef 24:5396b6a93262 75 return _fh.fptr;
DieterGraef 24:5396b6a93262 76 }
DieterGraef 24:5396b6a93262 77 }
DieterGraef 24:5396b6a93262 78
DieterGraef 24:5396b6a93262 79 int FATFileHandle::fsync() {
DieterGraef 24:5396b6a93262 80 FRESULT res = f_sync(&_fh);
DieterGraef 24:5396b6a93262 81 if (res) {
DieterGraef 24:5396b6a93262 82 debug_if(FFS_DBG, "f_sync() failed: %d\n", res);
DieterGraef 24:5396b6a93262 83 return -1;
DieterGraef 24:5396b6a93262 84 }
DieterGraef 24:5396b6a93262 85 return 0;
DieterGraef 24:5396b6a93262 86 }
DieterGraef 24:5396b6a93262 87
DieterGraef 24:5396b6a93262 88 off_t FATFileHandle::flen() {
DieterGraef 24:5396b6a93262 89 return _fh.fsize;
DieterGraef 24:5396b6a93262 90 }