Skip to content

Commit 94eca67

Browse files
authored
Merge pull request stm32duino#4 from fpistm/ffconf_custom
Add several update
2 parents 9a603c7 + 32b7a48 commit 94eca67

File tree

17 files changed

+460
-119
lines changed

17 files changed

+460
-119
lines changed

README.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# STM32SD
2-
3-
## SD library for Arduino
1+
# STM32 SD library for Arduino
42

53
With an STM32 board with SD card slot availability, this library enables
64
reading and writing on SD card using SD card slot of a STM32 board (NUCLEO, DISCOVERY, ...).
@@ -10,9 +8,25 @@ This library follow Arduino API.
108
For more information about it, please visit:
119
http://www.arduino.cc/en/Reference/SD
1210

13-
## Note
11+
## Dependency
1412

15-
The library is based on FatFs, a generic FAT file system module for small embedded systems.
13+
This library is based on FatFs, a generic FAT file system module for small embedded systems.
1614
[http://elm-chan.org/fsw/ff](http://elm-chan.org/fsw/ff/00index_e.html)
1715

18-
The FatFs has been ported as Arduino library [here](https://github.com/stm32duino/FatFs). The STM32SD library depends on it.
16+
The FatFs has been ported as Arduino library [here](https://github.com/stm32duino/FatFs).
17+
The STM32SD library depends on it.
18+
19+
## Configuration
20+
21+
### FatFs
22+
The FatFs has several user defined options, which is specified from within the `ffconf.h` file.
23+
24+
This library provides a default user defined options file named `ffconf_default.h`.
25+
26+
User can provide his own defined options by adding his configuration in a file named
27+
`ffconf_custom.h` at sketch level or in variant folder.
28+
29+
### SD detect and timeout
30+
* `SD_DETECT_PIN` pin number can be defined in `variant.h` or using `build_opt.h`.
31+
32+
* `SD_DATATIMEOUT` constant for Read/Write block could be redefined in `variant.h` or using `build_opt.h`

examples/CardInfo/CardInfo.ino

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
// include the SD library:
1212
#include <STM32SD.h>
1313

14+
// If SD card slot has no detect pin then define it as SD_DETECT_NONE
15+
// to ignore it. One other option is to call 'card.init()' without parameter.
16+
#ifndef SD_DETECT_PIN
17+
#define SD_DETECT_PIN SD_DETECT_NONE
18+
#endif
19+
1420
Sd2Card card;
1521
SdFatFs fatFs;
1622

examples/Datalogger/Datalogger.ino

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
#include <STM32SD.h>
1414

15+
// If SD card slot has no detect pin then define it as SD_DETECT_NONE
16+
// to ignore it. One other option is to call 'SD.begin()' without parameter.
17+
#ifndef SD_DETECT_PIN
18+
#define SD_DETECT_PIN SD_DETECT_NONE
19+
#endif
20+
1521
uint32_t A[] = { A0, A1, A2};
1622

1723
void setup()

examples/DumpFile/DumpFile.ino

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
#include <STM32SD.h>
1515

16+
// If SD card slot has no detect pin then define it as SD_DETECT_NONE
17+
// to ignore it. One other option is to call 'SD.begin()' without parameter.
18+
#ifndef SD_DETECT_PIN
19+
#define SD_DETECT_PIN SD_DETECT_NONE
20+
#endif
21+
1622
void setup()
1723
{
1824
// Open serial communications and wait for port to open:

examples/Files/Files.ino

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
*/
1111
#include <STM32SD.h>
1212

13+
// If SD card slot has no detect pin then define it as SD_DETECT_NONE
14+
// to ignore it. One other option is to call 'SD.begin()' without parameter.
15+
#ifndef SD_DETECT_PIN
16+
#define SD_DETECT_PIN SD_DETECT_NONE
17+
#endif
18+
1319
File myFile;
1420

1521
void setup()

examples/Full/Full.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#include <STM32SD.h>
22

3+
// If SD card slot has no detect pin then define it as SD_DETECT_NONE
4+
// to ignore it. One other option is to call 'SD.begin()' without parameter.
5+
#ifndef SD_DETECT_PIN
6+
#define SD_DETECT_PIN SD_DETECT_NONE
7+
#endif
8+
39
#define COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__)))
410
#define BUFFERSIZE (COUNTOF(wtext) -1)
511

examples/ReadWrite/ReadWrite.ino

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
#include <STM32SD.h>
1313

14+
// If SD card slot has no detect pin then define it as SD_DETECT_NONE
15+
// to ignore it. One other option is to call 'SD.begin()' without parameter.
16+
#ifndef SD_DETECT_PIN
17+
#define SD_DETECT_PIN SD_DETECT_NONE
18+
#endif
19+
1420
File myFile;
1521

1622
void setup()

examples/listfiles/listfiles.ino

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
*/
1313
#include <STM32SD.h>
1414

15+
// If SD card slot has no detect pin then define it as SD_DETECT_NONE
16+
// to ignore it. One other option is to call 'SD.begin()' without parameter.
17+
#ifndef SD_DETECT_PIN
18+
#define SD_DETECT_PIN SD_DETECT_NONE
19+
#endif
20+
1521
File root;
1622

1723
void setup()

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino STM32SD
2-
version=1.0.1
2+
version=1.1.0
33
author=Several
44
maintainer=stm32duino
55
sentence=Enables reading and writing on SD card using SD card slot of the STM32 Board.

src/SD.cpp

+5-28
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,17 @@ SDClass SD;
5959

6060
/**
6161
* @brief Link SD, register the file system object to the FatFs mode and configure
62-
* relatives SD IOs except SD Detect Pin
62+
* relatives SD IOs including SD Detect Pin if any
6363
* @param None
6464
* @retval TRUE or FALSE
6565
*/
66-
uint8_t SDClass::begin()
67-
{
68-
/*##-1- Initializes SD IOs #############################################*/
69-
if (_card.init()) {
70-
return _fatFs.init();
71-
}
72-
else
73-
{
74-
return FALSE;
75-
}
76-
}
77-
78-
/**
79-
* @brief Link SD, register the file system object to the FatFs mode and configure
80-
* relatives SD IOs including SD Detect Pin
81-
* @param None
82-
* @retval TRUE or FALSE
83-
*/
84-
uint8_t SDClass::begin(uint8_t cspin)
66+
uint8_t SDClass::begin(uint32_t cspin)
8567
{
8668
/*##-1- Initializes SD IOs #############################################*/
8769
if (_card.init(cspin)) {
8870
return _fatFs.init();
8971
}
90-
else
91-
{
92-
return FALSE;
93-
}
72+
return FALSE;
9473
}
9574

9675
/**
@@ -593,11 +572,9 @@ uint8_t File::isDirectory()
593572
{
594573
return TRUE;
595574
}
596-
else
597-
{
598-
return FALSE;
599-
}
600575
}
576+
// Assume not a directory
577+
return FALSE;
601578
}
602579

603580
File File::openNextFile(uint8_t mode)

src/STM32SD.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class SDClass {
7878
public:
7979

8080
/* Initialize the SD peripheral */
81-
uint8_t begin();
82-
uint8_t begin(uint8_t cspin);
81+
uint8_t begin(uint32_t cspin = SD_DETECT_NONE);
8382
static File open(const char *filepath, uint8_t mode);
8483
static File open(const char *filepath);
8584
static uint8_t exists(const char *filepath);

src/Sd2Card.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,20 @@
3737
#include <Arduino.h>
3838
#include "Sd2Card.h"
3939

40-
uint8_t Sd2Card::init(void) {
41-
if (BSP_SD_Init() == MSD_OK) {
42-
BSP_SD_GetCardInfo(&_SdCardInfo);
43-
return TRUE;
44-
} else {
45-
return FALSE;
40+
uint8_t Sd2Card::init(uint32_t cspin) {
41+
if(cspin != SD_DETECT_NONE) {
42+
PinName p = digitalPinToPinName(cspin);
43+
if((p == NC) ||\
44+
BSP_SD_CSSet(set_GPIO_Port_Clock(STM_PORT(p)),
45+
STM_GPIO_PIN(p)) != MSD_OK) {
46+
return FALSE;
47+
}
4648
}
47-
}
48-
49-
uint8_t Sd2Card::init(uint8_t cspin) {
50-
if (BSP_SD_CSInit() == MSD_OK) {
49+
if (BSP_SD_Init() == MSD_OK) {
5150
BSP_SD_GetCardInfo(&_SdCardInfo);
5251
return TRUE;
53-
} else {
54-
return FALSE;
5552
}
53+
return FALSE;
5654
}
5755

5856
uint8_t Sd2Card::type(void) const {

src/Sd2Card.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
class Sd2Card {
5757
public:
5858

59-
uint8_t init(void);
60-
uint8_t init(uint8_t cspin);
59+
uint8_t init(uint32_t cspin = SD_DETECT_NONE);
6160

6261
/** Return the card type: SD V1, SD V2 or SDHC */
6362
uint8_t type(void) const;

0 commit comments

Comments
 (0)