11/**
22 ******************************************************************************
3- * @file sd_diskio .c
3+ * @file sd_diskio_template_bspv1 .c
44 * @author MCD Application Team
5- * @version V2.0.2
6- * @date 10-November-2017
7- * @brief SD Disk I/O driver
5+ * @brief SD Disk I/O template driver based on BSP v1 api. This file needs
6+ * to be renamed and copied into the application project alongside
7+ * the respective header file
88 ******************************************************************************
99 * @attention
1010 *
11- * <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
12- * All rights reserved.</center></h2>
11+ * Copyright (c) 2017-2019 STMicroelectronics. All rights reserved.
1312 *
14- * Redistribution and use in source and binary forms, with or without
15- * modification, are permitted, provided that the following conditions are met:
16- *
17- * 1. Redistribution of source code must retain the above copyright notice,
18- * this list of conditions and the following disclaimer.
19- * 2. Redistributions in binary form must reproduce the above copyright notice,
20- * this list of conditions and the following disclaimer in the documentation
21- * and/or other materials provided with the distribution.
22- * 3. Neither the name of STMicroelectronics nor the names of other
23- * contributors to this software may be used to endorse or promote products
24- * derived from this software without specific written permission.
25- * 4. This software, including modifications and/or derivative works of this
26- * software, must execute solely and exclusively on microcontroller or
27- * microprocessor devices manufactured by or for STMicroelectronics.
28- * 5. Redistribution and use of this software other than as permitted under
29- * this license is void and will automatically terminate your rights under
30- * this license.
31- *
32- * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
33- * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
34- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35- * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
36- * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
37- * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
40- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13+ * This software component is licensed by ST under BSD 3-Clause license,
14+ * the "License"; You may not use this file except in compliance with the
15+ * License. You may obtain a copy of the License at:
16+ * opensource.org/licenses/BSD-3-Clause
4417 *
4518 ******************************************************************************
46- */
47-
19+ **/
4820/* Includes ------------------------------------------------------------------*/
4921#include "ff_gen_drv.h"
5022#include "sd_diskio.h"
6133#define SD_TIMEOUT 30 * 1000
6234#endif
6335
64- /* Block Size in Bytes */
6536#define SD_DEFAULT_BLOCK_SIZE 512
6637
6738/*
@@ -105,7 +76,6 @@ const Diskio_drvTypeDef SD_Driver =
10576/* Private functions ---------------------------------------------------------*/
10677static DSTATUS SD_CheckStatus (BYTE lun )
10778{
108- (void )lun ;
10979 Stat = STA_NOINIT ;
11080
11181 if (BSP_SD_GetCardState () == MSD_OK )
@@ -125,6 +95,7 @@ DSTATUS SD_initialize(BYTE lun)
12595{
12696 Stat = STA_NOINIT ;
12797#if !defined(DISABLE_SD_INIT )
98+
12899 if (BSP_SD_Init () == MSD_OK )
129100 {
130101 Stat = SD_CheckStatus (lun );
@@ -156,7 +127,6 @@ DSTATUS SD_status(BYTE lun)
156127 */
157128DRESULT SD_read (BYTE lun , BYTE * buff , DWORD sector , UINT count )
158129{
159- (void )lun ;
160130 DRESULT res = RES_ERROR ;
161131
162132 if (BSP_SD_ReadBlocks ((uint32_t * )buff ,
@@ -169,6 +139,7 @@ DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
169139 }
170140 res = RES_OK ;
171141 }
142+
172143 return res ;
173144}
174145
@@ -183,7 +154,6 @@ DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
183154#if _USE_WRITE == 1
184155DRESULT SD_write (BYTE lun , const BYTE * buff , DWORD sector , UINT count )
185156{
186- (void )lun ;
187157 DRESULT res = RES_ERROR ;
188158
189159 if (BSP_SD_WriteBlocks ((uint32_t * )buff ,
@@ -196,6 +166,7 @@ DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
196166 }
197167 res = RES_OK ;
198168 }
169+
199170 return res ;
200171}
201172#endif /* _USE_WRITE == 1 */
@@ -210,9 +181,9 @@ DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
210181#if _USE_IOCTL == 1
211182DRESULT SD_ioctl (BYTE lun , BYTE cmd , void * buff )
212183{
213- (void )lun ;
214184 DRESULT res = RES_ERROR ;
215- SD_CardInfo CardInfo ;
185+ BSP_SD_CardInfo CardInfo ;
186+
216187 if (Stat & STA_NOINIT ) return RES_NOTRDY ;
217188
218189 switch (cmd )
@@ -240,7 +211,7 @@ DRESULT SD_ioctl(BYTE lun, BYTE cmd, void *buff)
240211 case GET_BLOCK_SIZE :
241212 BSP_SD_GetCardInfo (& CardInfo );
242213 * (DWORD * )buff = CardInfo .LogBlockSize / SD_DEFAULT_BLOCK_SIZE ;
243- res = RES_OK ;
214+ res = RES_OK ;
244215 break ;
245216
246217 default :
0 commit comments