Skip to content

Commit 3034262

Browse files
committed
Add SD with FatFs
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent b87f9e5 commit 3034262

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+40654
-0
lines changed

libraries/FatFs/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=FatFs
2+
version=0.11
3+
author=(C)ChaN
4+
maintainer=Chan<user5@elm-chan org>
5+
sentence=FAT file system based on open-source FatFS solution.
6+
paragraph=FatFs is a generic FAT file system module for small embedded systems. The FatFs is written in compliance with ANSI C and completely separated from the disk I/O layer. Therefore it is independent of hardware architecture.
7+
category=Data Storage
8+
url=http://elm-chan.org/fsw/ff/00index_e.html
9+
architectures=stm32

libraries/FatFs/src/00readme.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FatFs Module Source Files R0.11
2+
3+
4+
FILES
5+
6+
00readme.txt This file.
7+
history.txt Revision history.
8+
ffconf.h Configuration file for FatFs module.
9+
ff.h Common include file for FatFs and application module.
10+
ff.c FatFs module.
11+
diskio.h Common include file for FatFs and disk I/O module.
12+
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
13+
integer.h Integer type definitions for FatFs.
14+
option Optional external functions.
15+
16+
17+
Low level disk I/O module is not included in this archive because the FatFs
18+
module is only a generic file system layer and not depend on any specific
19+
storage device. You have to provide a low level disk I/O module that written
20+
to control the target storage device.
21+

libraries/FatFs/src/diskio.c

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*-----------------------------------------------------------------------*/
2+
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
3+
/* */
4+
/* Portions COPYRIGHT 2017 STMicroelectronics */
5+
/* Portions Copyright (C) 2014, ChaN, all right reserved */
6+
/*-----------------------------------------------------------------------*/
7+
/* If a working storage control module is available, it should be */
8+
/* attached to the FatFs via a glue function rather than modifying it. */
9+
/* This is an example of glue functions to attach various exsisting */
10+
/* storage control modules to the FatFs module with a defined API. */
11+
/*-----------------------------------------------------------------------*/
12+
13+
/**
14+
******************************************************************************
15+
* @file diskio.c
16+
* @author MCD Application Team
17+
* @version V1.4.1
18+
* @date 14-February-2017
19+
* @brief FatFs low level disk I/O module.
20+
******************************************************************************
21+
* @attention
22+
*
23+
*
24+
* Redistribution and use in source and binary forms, with or without
25+
* modification, are permitted, provided that the following conditions are met:
26+
*
27+
* 1. Redistribution of source code must retain the above copyright notice,
28+
* this list of conditions and the following disclaimer.
29+
* 2. Redistributions in binary form must reproduce the above copyright notice,
30+
* this list of conditions and the following disclaimer in the documentation
31+
* and/or other materials provided with the distribution.
32+
* 3. Neither the name of STMicroelectronics nor the names of other
33+
* contributors to this software may be used to endorse or promote products
34+
* derived from this software without specific written permission.
35+
* 4. This software, including modifications and/or derivative works of this
36+
* software, must execute solely and exclusively on microcontroller or
37+
* microprocessor devices manufactured by or for STMicroelectronics.
38+
* 5. Redistribution and use of this software other than as permitted under
39+
* this license is void and will automatically terminate your rights under
40+
* this license.
41+
*
42+
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
43+
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
44+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
45+
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
46+
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
47+
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
48+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
50+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
51+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
52+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
53+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54+
*
55+
******************************************************************************
56+
*/
57+
58+
/* Includes ------------------------------------------------------------------*/
59+
#include "diskio.h"
60+
#include "ff_gen_drv.h"
61+
62+
/* Private typedef -----------------------------------------------------------*/
63+
/* Private define ------------------------------------------------------------*/
64+
/* Private variables ---------------------------------------------------------*/
65+
extern Disk_drvTypeDef disk;
66+
67+
/* Private function prototypes -----------------------------------------------*/
68+
/* Private functions ---------------------------------------------------------*/
69+
70+
/**
71+
* @brief Gets Disk Status
72+
* @param pdrv: Physical drive number (0..)
73+
* @retval DSTATUS: Operation status
74+
*/
75+
DSTATUS disk_status (
76+
BYTE pdrv /* Physical drive nmuber to identify the drive */
77+
)
78+
{
79+
DSTATUS stat;
80+
81+
stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
82+
return stat;
83+
}
84+
85+
/**
86+
* @brief Initializes a Drive
87+
* @param pdrv: Physical drive number (0..)
88+
* @retval DSTATUS: Operation status
89+
*/
90+
DSTATUS disk_initialize (
91+
BYTE pdrv /* Physical drive nmuber to identify the drive */
92+
)
93+
{
94+
DSTATUS stat = RES_OK;
95+
96+
if(disk.is_initialized[pdrv] == 0)
97+
{
98+
disk.is_initialized[pdrv] = 1;
99+
stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
100+
}
101+
return stat;
102+
}
103+
104+
/**
105+
* @brief Reads Sector(s)
106+
* @param pdrv: Physical drive number (0..)
107+
* @param *buff: Data buffer to store read data
108+
* @param sector: Sector address (LBA)
109+
* @param count: Number of sectors to read (1..128)
110+
* @retval DRESULT: Operation result
111+
*/
112+
DRESULT disk_read (
113+
BYTE pdrv, /* Physical drive nmuber to identify the drive */
114+
BYTE *buff, /* Data buffer to store read data */
115+
DWORD sector, /* Sector address in LBA */
116+
UINT count /* Number of sectors to read */
117+
)
118+
{
119+
DRESULT res;
120+
121+
res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
122+
return res;
123+
}
124+
125+
/**
126+
* @brief Writes Sector(s)
127+
* @param pdrv: Physical drive number (0..)
128+
* @param *buff: Data to be written
129+
* @param sector: Sector address (LBA)
130+
* @param count: Number of sectors to write (1..128)
131+
* @retval DRESULT: Operation result
132+
*/
133+
#if _USE_WRITE == 1
134+
DRESULT disk_write (
135+
BYTE pdrv, /* Physical drive nmuber to identify the drive */
136+
const BYTE *buff, /* Data to be written */
137+
DWORD sector, /* Sector address in LBA */
138+
UINT count /* Number of sectors to write */
139+
)
140+
{
141+
DRESULT res;
142+
143+
res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
144+
return res;
145+
}
146+
#endif /* _USE_WRITE == 1 */
147+
148+
/**
149+
* @brief I/O control operation
150+
* @param pdrv: Physical drive number (0..)
151+
* @param cmd: Control code
152+
* @param *buff: Buffer to send/receive control data
153+
* @retval DRESULT: Operation result
154+
*/
155+
#if _USE_IOCTL == 1
156+
DRESULT disk_ioctl (
157+
BYTE pdrv, /* Physical drive nmuber (0..) */
158+
BYTE cmd, /* Control code */
159+
void *buff /* Buffer to send/receive control data */
160+
)
161+
{
162+
DRESULT res;
163+
164+
res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
165+
return res;
166+
}
167+
#endif /* _USE_IOCTL == 1 */
168+
169+
/**
170+
* @brief Gets Time from RTC
171+
* @param None
172+
* @retval Time in DWORD
173+
*/
174+
__weak DWORD get_fattime (void)
175+
{
176+
return 0;
177+
}
178+
179+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
180+

libraries/FatFs/src/diskio.h

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*-----------------------------------------------------------------------/
2+
/ Low level disk interface modlue include file (C)ChaN, 2014 /
3+
/-----------------------------------------------------------------------*/
4+
5+
#ifndef _DISKIO_DEFINED
6+
#define _DISKIO_DEFINED
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#define _USE_WRITE 1 /* 1: Enable disk_write function */
13+
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
14+
15+
#include "integer.h"
16+
17+
18+
/* Status of Disk Functions */
19+
typedef BYTE DSTATUS;
20+
21+
/* Results of Disk Functions */
22+
typedef enum {
23+
RES_OK = 0, /* 0: Successful */
24+
RES_ERROR, /* 1: R/W Error */
25+
RES_WRPRT, /* 2: Write Protected */
26+
RES_NOTRDY, /* 3: Not Ready */
27+
RES_PARERR /* 4: Invalid Parameter */
28+
} DRESULT;
29+
30+
31+
/*---------------------------------------*/
32+
/* Prototypes for disk control functions */
33+
34+
35+
DSTATUS disk_initialize (BYTE pdrv);
36+
DSTATUS disk_status (BYTE pdrv);
37+
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
38+
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
39+
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
40+
DWORD get_fattime (void);
41+
42+
/* Disk Status Bits (DSTATUS) */
43+
44+
#define STA_NOINIT 0x01 /* Drive not initialized */
45+
#define STA_NODISK 0x02 /* No medium in the drive */
46+
#define STA_PROTECT 0x04 /* Write protected */
47+
48+
49+
/* Command code for disk_ioctrl fucntion */
50+
51+
/* Generic command (Used by FatFs) */
52+
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
53+
#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
54+
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
55+
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
56+
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
57+
58+
/* Generic command (Not used by FatFs) */
59+
#define CTRL_POWER 5 /* Get/Set power status */
60+
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
61+
#define CTRL_EJECT 7 /* Eject media */
62+
#define CTRL_FORMAT 8 /* Create physical format on the media */
63+
64+
/* MMC/SDC specific ioctl command */
65+
#define MMC_GET_TYPE 10 /* Get card type */
66+
#define MMC_GET_CSD 11 /* Get CSD */
67+
#define MMC_GET_CID 12 /* Get CID */
68+
#define MMC_GET_OCR 13 /* Get OCR */
69+
#define MMC_GET_SDSTAT 14 /* Get SD status */
70+
71+
/* ATA/CF specific ioctl command */
72+
#define ATA_GET_REV 20 /* Get F/W revision */
73+
#define ATA_GET_MODEL 21 /* Get model name */
74+
#define ATA_GET_SN 22 /* Get serial number */
75+
76+
#ifdef __cplusplus
77+
}
78+
#endif
79+
80+
#endif

0 commit comments

Comments
 (0)