STM32F746NG fatfs library

Dependents:   DISCO-F746NG_uSD Active-WolfMan_V2-5-All-Frank-Board-Functions_copy DISCO-F746NG_uSD DISCO-F746NG_uSD

Committer:
buyukesmeli
Date:
Sat Feb 03 14:38:06 2018 +0000
Revision:
0:3a2f06aeceaf
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
buyukesmeli 0:3a2f06aeceaf 1 /**
buyukesmeli 0:3a2f06aeceaf 2 ******************************************************************************
buyukesmeli 0:3a2f06aeceaf 3 * @file ff_gen_drv.c
buyukesmeli 0:3a2f06aeceaf 4 * @author MCD Application Team
buyukesmeli 0:3a2f06aeceaf 5 * @version V1.4.0
buyukesmeli 0:3a2f06aeceaf 6 * @date 23-December-2016
buyukesmeli 0:3a2f06aeceaf 7 * @brief FatFs generic low level driver.
buyukesmeli 0:3a2f06aeceaf 8 ******************************************************************************
buyukesmeli 0:3a2f06aeceaf 9 * @attention
buyukesmeli 0:3a2f06aeceaf 10 *
buyukesmeli 0:3a2f06aeceaf 11 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
buyukesmeli 0:3a2f06aeceaf 12 *
buyukesmeli 0:3a2f06aeceaf 13 * Redistribution and use in source and binary forms, with or without
buyukesmeli 0:3a2f06aeceaf 14 * modification, are permitted, provided that the following conditions are met:
buyukesmeli 0:3a2f06aeceaf 15 *
buyukesmeli 0:3a2f06aeceaf 16 * 1. Redistribution of source code must retain the above copyright notice,
buyukesmeli 0:3a2f06aeceaf 17 * this list of conditions and the following disclaimer.
buyukesmeli 0:3a2f06aeceaf 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
buyukesmeli 0:3a2f06aeceaf 19 * this list of conditions and the following disclaimer in the documentation
buyukesmeli 0:3a2f06aeceaf 20 * and/or other materials provided with the distribution.
buyukesmeli 0:3a2f06aeceaf 21 * 3. Neither the name of STMicroelectronics nor the names of other
buyukesmeli 0:3a2f06aeceaf 22 * contributors to this software may be used to endorse or promote products
buyukesmeli 0:3a2f06aeceaf 23 * derived from this software without specific written permission.
buyukesmeli 0:3a2f06aeceaf 24 * 4. This software, including modifications and/or derivative works of this
buyukesmeli 0:3a2f06aeceaf 25 * software, must execute solely and exclusively on microcontroller or
buyukesmeli 0:3a2f06aeceaf 26 * microprocessor devices manufactured by or for STMicroelectronics.
buyukesmeli 0:3a2f06aeceaf 27 * 5. Redistribution and use of this software other than as permitted under
buyukesmeli 0:3a2f06aeceaf 28 * this license is void and will automatically terminate your rights under
buyukesmeli 0:3a2f06aeceaf 29 * this license.
buyukesmeli 0:3a2f06aeceaf 30 *
buyukesmeli 0:3a2f06aeceaf 31 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
buyukesmeli 0:3a2f06aeceaf 32 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
buyukesmeli 0:3a2f06aeceaf 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
buyukesmeli 0:3a2f06aeceaf 34 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
buyukesmeli 0:3a2f06aeceaf 35 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
buyukesmeli 0:3a2f06aeceaf 36 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
buyukesmeli 0:3a2f06aeceaf 37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
buyukesmeli 0:3a2f06aeceaf 38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
buyukesmeli 0:3a2f06aeceaf 39 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
buyukesmeli 0:3a2f06aeceaf 40 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
buyukesmeli 0:3a2f06aeceaf 41 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
buyukesmeli 0:3a2f06aeceaf 42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
buyukesmeli 0:3a2f06aeceaf 43 *
buyukesmeli 0:3a2f06aeceaf 44 ******************************************************************************
buyukesmeli 0:3a2f06aeceaf 45 */
buyukesmeli 0:3a2f06aeceaf 46
buyukesmeli 0:3a2f06aeceaf 47 /* Includes ------------------------------------------------------------------*/
buyukesmeli 0:3a2f06aeceaf 48 #include "ff_gen_drv.h"
buyukesmeli 0:3a2f06aeceaf 49
buyukesmeli 0:3a2f06aeceaf 50 /* Private typedef -----------------------------------------------------------*/
buyukesmeli 0:3a2f06aeceaf 51 /* Private define ------------------------------------------------------------*/
buyukesmeli 0:3a2f06aeceaf 52 /* Private variables ---------------------------------------------------------*/
buyukesmeli 0:3a2f06aeceaf 53 Disk_drvTypeDef disk = {{0},{0},{0},0};
buyukesmeli 0:3a2f06aeceaf 54
buyukesmeli 0:3a2f06aeceaf 55 /* Private function prototypes -----------------------------------------------*/
buyukesmeli 0:3a2f06aeceaf 56 /* Private functions ---------------------------------------------------------*/
buyukesmeli 0:3a2f06aeceaf 57
buyukesmeli 0:3a2f06aeceaf 58 /**
buyukesmeli 0:3a2f06aeceaf 59 * @brief Links a compatible diskio driver/lun id and increments the number of active
buyukesmeli 0:3a2f06aeceaf 60 * linked drivers.
buyukesmeli 0:3a2f06aeceaf 61 * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits.
buyukesmeli 0:3a2f06aeceaf 62 * @param drv: pointer to the disk IO Driver structure
buyukesmeli 0:3a2f06aeceaf 63 * @param path: pointer to the logical drive path
buyukesmeli 0:3a2f06aeceaf 64 * @param lun : only used for USB Key Disk to add multi-lun management
buyukesmeli 0:3a2f06aeceaf 65 else the paramter must be equal to 0
buyukesmeli 0:3a2f06aeceaf 66 * @retval Returns 0 in case of success, otherwise 1.
buyukesmeli 0:3a2f06aeceaf 67 */
buyukesmeli 0:3a2f06aeceaf 68 uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, uint8_t lun)
buyukesmeli 0:3a2f06aeceaf 69 {
buyukesmeli 0:3a2f06aeceaf 70 uint8_t ret = 1;
buyukesmeli 0:3a2f06aeceaf 71 uint8_t DiskNum = 0;
buyukesmeli 0:3a2f06aeceaf 72
buyukesmeli 0:3a2f06aeceaf 73 if(disk.nbr <= _VOLUMES)
buyukesmeli 0:3a2f06aeceaf 74 {
buyukesmeli 0:3a2f06aeceaf 75 disk.is_initialized[disk.nbr] = 0;
buyukesmeli 0:3a2f06aeceaf 76 disk.drv[disk.nbr] = drv;
buyukesmeli 0:3a2f06aeceaf 77 disk.lun[disk.nbr] = lun;
buyukesmeli 0:3a2f06aeceaf 78 DiskNum = disk.nbr++;
buyukesmeli 0:3a2f06aeceaf 79 path[0] = DiskNum + '0';
buyukesmeli 0:3a2f06aeceaf 80 path[1] = ':';
buyukesmeli 0:3a2f06aeceaf 81 path[2] = '/';
buyukesmeli 0:3a2f06aeceaf 82 path[3] = 0;
buyukesmeli 0:3a2f06aeceaf 83 ret = 0;
buyukesmeli 0:3a2f06aeceaf 84 }
buyukesmeli 0:3a2f06aeceaf 85
buyukesmeli 0:3a2f06aeceaf 86 return ret;
buyukesmeli 0:3a2f06aeceaf 87 }
buyukesmeli 0:3a2f06aeceaf 88
buyukesmeli 0:3a2f06aeceaf 89 /**
buyukesmeli 0:3a2f06aeceaf 90 * @brief Links a compatible diskio driver and increments the number of active
buyukesmeli 0:3a2f06aeceaf 91 * linked drivers.
buyukesmeli 0:3a2f06aeceaf 92 * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits
buyukesmeli 0:3a2f06aeceaf 93 * @param drv: pointer to the disk IO Driver structure
buyukesmeli 0:3a2f06aeceaf 94 * @param path: pointer to the logical drive path
buyukesmeli 0:3a2f06aeceaf 95 * @retval Returns 0 in case of success, otherwise 1.
buyukesmeli 0:3a2f06aeceaf 96 */
buyukesmeli 0:3a2f06aeceaf 97 uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path)
buyukesmeli 0:3a2f06aeceaf 98 {
buyukesmeli 0:3a2f06aeceaf 99 return FATFS_LinkDriverEx(drv, path, 0);
buyukesmeli 0:3a2f06aeceaf 100 }
buyukesmeli 0:3a2f06aeceaf 101
buyukesmeli 0:3a2f06aeceaf 102 /**
buyukesmeli 0:3a2f06aeceaf 103 * @brief Unlinks a diskio driver and decrements the number of active linked
buyukesmeli 0:3a2f06aeceaf 104 * drivers.
buyukesmeli 0:3a2f06aeceaf 105 * @param path: pointer to the logical drive path
buyukesmeli 0:3a2f06aeceaf 106 * @param lun : not used
buyukesmeli 0:3a2f06aeceaf 107 * @retval Returns 0 in case of success, otherwise 1.
buyukesmeli 0:3a2f06aeceaf 108 */
buyukesmeli 0:3a2f06aeceaf 109 uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
buyukesmeli 0:3a2f06aeceaf 110 {
buyukesmeli 0:3a2f06aeceaf 111 uint8_t DiskNum = 0;
buyukesmeli 0:3a2f06aeceaf 112 uint8_t ret = 1;
buyukesmeli 0:3a2f06aeceaf 113
buyukesmeli 0:3a2f06aeceaf 114 if(disk.nbr >= 1)
buyukesmeli 0:3a2f06aeceaf 115 {
buyukesmeli 0:3a2f06aeceaf 116 DiskNum = path[0] - '0';
buyukesmeli 0:3a2f06aeceaf 117 if(disk.drv[DiskNum] != 0)
buyukesmeli 0:3a2f06aeceaf 118 {
buyukesmeli 0:3a2f06aeceaf 119 disk.drv[DiskNum] = 0;
buyukesmeli 0:3a2f06aeceaf 120 disk.lun[DiskNum] = 0;
buyukesmeli 0:3a2f06aeceaf 121 disk.nbr--;
buyukesmeli 0:3a2f06aeceaf 122 ret = 0;
buyukesmeli 0:3a2f06aeceaf 123 }
buyukesmeli 0:3a2f06aeceaf 124 }
buyukesmeli 0:3a2f06aeceaf 125
buyukesmeli 0:3a2f06aeceaf 126 return ret;
buyukesmeli 0:3a2f06aeceaf 127 }
buyukesmeli 0:3a2f06aeceaf 128
buyukesmeli 0:3a2f06aeceaf 129 /**
buyukesmeli 0:3a2f06aeceaf 130 * @brief Unlinks a diskio driver and decrements the number of active linked
buyukesmeli 0:3a2f06aeceaf 131 * drivers.
buyukesmeli 0:3a2f06aeceaf 132 * @param path: pointer to the logical drive path
buyukesmeli 0:3a2f06aeceaf 133 * @retval Returns 0 in case of success, otherwise 1.
buyukesmeli 0:3a2f06aeceaf 134 */
buyukesmeli 0:3a2f06aeceaf 135 uint8_t FATFS_UnLinkDriver(char *path)
buyukesmeli 0:3a2f06aeceaf 136 {
buyukesmeli 0:3a2f06aeceaf 137 return FATFS_UnLinkDriverEx(path, 0);
buyukesmeli 0:3a2f06aeceaf 138 }
buyukesmeli 0:3a2f06aeceaf 139
buyukesmeli 0:3a2f06aeceaf 140 /**
buyukesmeli 0:3a2f06aeceaf 141 * @brief Gets number of linked drivers to the FatFs module.
buyukesmeli 0:3a2f06aeceaf 142 * @param None
buyukesmeli 0:3a2f06aeceaf 143 * @retval Number of attached drivers.
buyukesmeli 0:3a2f06aeceaf 144 */
buyukesmeli 0:3a2f06aeceaf 145 uint8_t FATFS_GetAttachedDriversNbr(void)
buyukesmeli 0:3a2f06aeceaf 146 {
buyukesmeli 0:3a2f06aeceaf 147 return disk.nbr;
buyukesmeli 0:3a2f06aeceaf 148 }
buyukesmeli 0:3a2f06aeceaf 149
buyukesmeli 0:3a2f06aeceaf 150 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
buyukesmeli 0:3a2f06aeceaf 151