Skip to content

Commit 3690eab

Browse files
committed
feat(fatfs): modify FATFS for ESP8266
1 parent 3bbadfa commit 3690eab

File tree

14 files changed

+166
-17
lines changed

14 files changed

+166
-17
lines changed

components/esp8266/include/driver/sdspi_host.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "esp_err.h"
2020
#include "sdmmc_types.h"
2121
#include "driver/gpio.h"
22-
#include "driver/spi_master.h"
22+
// #include "driver/spi_master.h"
2323

2424
#ifdef __cplusplus
2525
extern "C" {
@@ -32,7 +32,7 @@ extern "C" {
3232
*
3333
* 'slot' can be set to one of HSPI_HOST, VSPI_HOST.
3434
*/
35-
#define SDSPI_HOST_DEFAULT() {\
35+
/*#define SDSPI_HOST_DEFAULT() {\
3636
.flags = SDMMC_HOST_FLAG_SPI, \
3737
.slot = HSPI_HOST, \
3838
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
@@ -47,7 +47,7 @@ extern "C" {
4747
.io_int_enable = &sdspi_host_io_int_enable, \
4848
.io_int_wait = &sdspi_host_io_int_wait, \
4949
.command_timeout_ms = 0, \
50-
}
50+
}*/
5151

5252
/**
5353
* Extra configuration for SPI host

components/fatfs/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
set(srcs "diskio/diskio.c"
22
"diskio/diskio_rawflash.c"
3-
"diskio/diskio_sdmmc.c"
43
"diskio/diskio_wl.c"
54
"src/ff.c"
65
"port/freertos/ffsystem.c"
@@ -14,5 +13,5 @@ endif()
1413

1514
idf_component_register(SRCS ${srcs}
1615
INCLUDE_DIRS diskio vfs src
17-
REQUIRES wear_levelling sdmmc
16+
REQUIRES wear_levelling
1817
)

components/fatfs/component.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
COMPONENT_ADD_INCLUDEDIRS := diskio vfs src
22
COMPONENT_SRCDIRS := diskio vfs port/freertos src
3-
COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o
3+
COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o diskio/diskio_sdmmc.o vfs/vfs_fat_sdmmc.o

components/fatfs/test/test_fatfs_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static void read_write_task(void* param)
694694

695695
srand(args->seed);
696696
for (size_t i = 0; i < args->word_count; ++i) {
697-
uint32_t val = rand();
697+
uint32_t val = i * 77;
698698
if (args->write) {
699699
int cnt = fwrite(&val, sizeof(val), 1, f);
700700
if (cnt != 1) {

components/fatfs/test/test_fatfs_rawflash.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,30 @@ static void test_setup(size_t max_files)
4141
};
4242
const esp_partition_t* part = get_test_data_partition();
4343

44-
TEST_ASSERT(part->size == (fatfs_end - fatfs_start - 1));
44+
TEST_ASSERT(part->size >= (fatfs_end - fatfs_start - 1));
4545

46-
spi_flash_mmap_handle_t mmap_handle;
47-
const void* mmap_ptr;
48-
TEST_ESP_OK(esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &mmap_ptr, &mmap_handle));
49-
bool content_valid = memcmp(fatfs_start, mmap_ptr, part->size) == 0;
50-
spi_flash_munmap(mmap_handle);
46+
// spi_flash_mmap_handle_t mmap_handle;
47+
// const void* mmap_ptr;
48+
// TEST_ESP_OK(esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &mmap_ptr, &mmap_handle));
49+
// bool content_valid = memcmp(fatfs_start, mmap_ptr, part->size) == 0;
50+
// spi_flash_munmap(mmap_handle);
51+
52+
size_t max_space_size = MIN(part->size, fatfs_end - fatfs_start - 1);
53+
bool content_valid = true;
54+
char *buf = malloc(4096);
55+
TEST_ASSERT_NOT_NULL(buf);
56+
57+
for (size_t i = 0; i < max_space_size; i += 4096) {
58+
size_t bytes = MIN(4096, max_space_size - i);
59+
60+
TEST_ESP_OK(esp_partition_read(part, i, buf, bytes));
61+
if (memcmp(fatfs_start + i, buf, bytes)) {
62+
content_valid = false;
63+
break;
64+
}
65+
}
66+
67+
free(buf);
5168

5269
if (!content_valid) {
5370
printf("Copying fatfs.img into test partition...\n");

components/fatfs/test/test_fatfs_sdmmc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#if 0
16+
1517
#include <stdio.h>
1618
#include <stdlib.h>
1719
#include <string.h>
@@ -297,4 +299,6 @@ TEST_CASE("(SD) opendir, readdir, rewinddir, seekdir work as expected using UTF-
297299
}
298300
#endif // CONFIG_FATFS_API_ENCODING_UTF_8 && CONFIG_FATFS_CODEPAGE == 936
299301

300-
#endif
302+
#endif
303+
304+
#endif

components/newlib/component.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ else ifdef CONFIG_NEWLIB_LIBRARY_LEVEL_FLOAT_NANO
1111
LIB_PATH := $(COMPONENT_PATH)/newlib/lib/libc_fnano.a $(COMPONENT_PATH)/newlib/lib/libm.a
1212
endif
1313

14-
COMPONENT_ADD_INCLUDEDIRS += newlib/port/include newlib/include
14+
COMPONENT_ADD_INCLUDEDIRS := newlib/port/include newlib/include
1515
COMPONENT_SRCDIRS += newlib/port
1616
COMPONENT_ADD_LDFLAGS := $(LIB_PATH) -lnewlib
1717
COMPONENT_ADD_LINKER_DEPS := $(LIB_PATH)

components/newlib/newlib/include/stdio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typedef _fpos64_t fpos64_t;
110110
#ifdef __FOPEN_MAX__
111111
#define FOPEN_MAX __FOPEN_MAX__
112112
#else
113-
#define FOPEN_MAX 20
113+
#define FOPEN_MAX 10
114114
#endif
115115

116116
#ifdef __FILENAME_MAX__
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
#ifndef _ESP_SYS_UNISTD_H
17+
#define _ESP_SYS_UNISTD_H
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#include_next <sys/unistd.h>
24+
25+
int truncate(const char *, off_t __length);
26+
int gethostname(char *__name, size_t __len);
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
#endif /* _SYS_UNISTD_H */
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef _UTIME_H_
16+
#define _UTIME_H_
17+
18+
#include <sys/time.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
struct utimbuf {
25+
time_t actime; // access time
26+
time_t modtime; // modification time
27+
};
28+
29+
int utime(const char *path, const struct utimbuf *times);
30+
31+
#ifdef __cplusplus
32+
};
33+
#endif
34+
35+
#endif /* _UTIME_H_ */

components/newlib/newlib/port/pread.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <unistd.h>
16+
#include "esp_vfs.h"
17+
18+
ssize_t pread(int fd, void *dst, size_t size, off_t offset)
19+
{
20+
return esp_vfs_pread(fd, dst, size, offset);
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <unistd.h>
16+
#include "esp_vfs.h"
17+
18+
ssize_t pwrite(int fd, const void *src, size_t size, off_t offset)
19+
{
20+
return esp_vfs_pwrite(fd, src, size, offset);
21+
}

components/newlib/newlib/port/utime.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <utime.h>
16+
#include "esp_vfs.h"
17+
18+
int utime(const char *path, const struct utimbuf *times)
19+
{
20+
return esp_vfs_utime(path, times);
21+
}

tools/unit-test-app/partition_table_unit_test_app.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ factory, 0, 0, 0x10000, 0xF0000
99
ota_0, 0, ota_0, , 64K
1010
ota_1, 0, ota_1, , 64K
1111
# flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests
12-
flash_test, data, fat, , 528K
12+
flash_test, data, fat, , 896K
1313

1414
# Note: still 1MB of a 4MB flash left free for some other purpose

0 commit comments

Comments
 (0)