mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-07-15 08:32:42 +08:00
feat(fatfs): modify FATFS for ESP8266
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "sdmmc_types.h"
|
#include "sdmmc_types.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/spi_master.h"
|
// #include "driver/spi_master.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -32,7 +32,7 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* 'slot' can be set to one of HSPI_HOST, VSPI_HOST.
|
* 'slot' can be set to one of HSPI_HOST, VSPI_HOST.
|
||||||
*/
|
*/
|
||||||
#define SDSPI_HOST_DEFAULT() {\
|
/*#define SDSPI_HOST_DEFAULT() {\
|
||||||
.flags = SDMMC_HOST_FLAG_SPI, \
|
.flags = SDMMC_HOST_FLAG_SPI, \
|
||||||
.slot = HSPI_HOST, \
|
.slot = HSPI_HOST, \
|
||||||
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
|
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
|
||||||
@ -47,7 +47,7 @@ extern "C" {
|
|||||||
.io_int_enable = &sdspi_host_io_int_enable, \
|
.io_int_enable = &sdspi_host_io_int_enable, \
|
||||||
.io_int_wait = &sdspi_host_io_int_wait, \
|
.io_int_wait = &sdspi_host_io_int_wait, \
|
||||||
.command_timeout_ms = 0, \
|
.command_timeout_ms = 0, \
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra configuration for SPI host
|
* Extra configuration for SPI host
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
set(srcs "diskio/diskio.c"
|
set(srcs "diskio/diskio.c"
|
||||||
"diskio/diskio_rawflash.c"
|
"diskio/diskio_rawflash.c"
|
||||||
"diskio/diskio_sdmmc.c"
|
|
||||||
"diskio/diskio_wl.c"
|
"diskio/diskio_wl.c"
|
||||||
"src/ff.c"
|
"src/ff.c"
|
||||||
"port/freertos/ffsystem.c"
|
"port/freertos/ffsystem.c"
|
||||||
@ -14,5 +13,5 @@ endif()
|
|||||||
|
|
||||||
idf_component_register(SRCS ${srcs}
|
idf_component_register(SRCS ${srcs}
|
||||||
INCLUDE_DIRS diskio vfs src
|
INCLUDE_DIRS diskio vfs src
|
||||||
REQUIRES wear_levelling sdmmc
|
REQUIRES wear_levelling
|
||||||
)
|
)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
COMPONENT_ADD_INCLUDEDIRS := diskio vfs src
|
COMPONENT_ADD_INCLUDEDIRS := diskio vfs src
|
||||||
COMPONENT_SRCDIRS := diskio vfs port/freertos src
|
COMPONENT_SRCDIRS := diskio vfs port/freertos src
|
||||||
COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o
|
COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o diskio/diskio_sdmmc.o vfs/vfs_fat_sdmmc.o
|
||||||
|
@ -694,7 +694,7 @@ static void read_write_task(void* param)
|
|||||||
|
|
||||||
srand(args->seed);
|
srand(args->seed);
|
||||||
for (size_t i = 0; i < args->word_count; ++i) {
|
for (size_t i = 0; i < args->word_count; ++i) {
|
||||||
uint32_t val = rand();
|
uint32_t val = i * 77;
|
||||||
if (args->write) {
|
if (args->write) {
|
||||||
int cnt = fwrite(&val, sizeof(val), 1, f);
|
int cnt = fwrite(&val, sizeof(val), 1, f);
|
||||||
if (cnt != 1) {
|
if (cnt != 1) {
|
||||||
|
@ -41,13 +41,30 @@ static void test_setup(size_t max_files)
|
|||||||
};
|
};
|
||||||
const esp_partition_t* part = get_test_data_partition();
|
const esp_partition_t* part = get_test_data_partition();
|
||||||
|
|
||||||
TEST_ASSERT(part->size == (fatfs_end - fatfs_start - 1));
|
TEST_ASSERT(part->size >= (fatfs_end - fatfs_start - 1));
|
||||||
|
|
||||||
spi_flash_mmap_handle_t mmap_handle;
|
// spi_flash_mmap_handle_t mmap_handle;
|
||||||
const void* mmap_ptr;
|
// const void* mmap_ptr;
|
||||||
TEST_ESP_OK(esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &mmap_ptr, &mmap_handle));
|
// TEST_ESP_OK(esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &mmap_ptr, &mmap_handle));
|
||||||
bool content_valid = memcmp(fatfs_start, mmap_ptr, part->size) == 0;
|
// bool content_valid = memcmp(fatfs_start, mmap_ptr, part->size) == 0;
|
||||||
spi_flash_munmap(mmap_handle);
|
// spi_flash_munmap(mmap_handle);
|
||||||
|
|
||||||
|
size_t max_space_size = MIN(part->size, fatfs_end - fatfs_start - 1);
|
||||||
|
bool content_valid = true;
|
||||||
|
char *buf = malloc(4096);
|
||||||
|
TEST_ASSERT_NOT_NULL(buf);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < max_space_size; i += 4096) {
|
||||||
|
size_t bytes = MIN(4096, max_space_size - i);
|
||||||
|
|
||||||
|
TEST_ESP_OK(esp_partition_read(part, i, buf, bytes));
|
||||||
|
if (memcmp(fatfs_start + i, buf, bytes)) {
|
||||||
|
content_valid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
|
||||||
if (!content_valid) {
|
if (!content_valid) {
|
||||||
printf("Copying fatfs.img into test partition...\n");
|
printf("Copying fatfs.img into test partition...\n");
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -297,4 +299,6 @@ TEST_CASE("(SD) opendir, readdir, rewinddir, seekdir work as expected using UTF-
|
|||||||
}
|
}
|
||||||
#endif // CONFIG_FATFS_API_ENCODING_UTF_8 && CONFIG_FATFS_CODEPAGE == 936
|
#endif // CONFIG_FATFS_API_ENCODING_UTF_8 && CONFIG_FATFS_CODEPAGE == 936
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -11,7 +11,7 @@ else ifdef CONFIG_NEWLIB_LIBRARY_LEVEL_FLOAT_NANO
|
|||||||
LIB_PATH := $(COMPONENT_PATH)/newlib/lib/libc_fnano.a $(COMPONENT_PATH)/newlib/lib/libm.a
|
LIB_PATH := $(COMPONENT_PATH)/newlib/lib/libc_fnano.a $(COMPONENT_PATH)/newlib/lib/libm.a
|
||||||
endif
|
endif
|
||||||
|
|
||||||
COMPONENT_ADD_INCLUDEDIRS += newlib/port/include newlib/include
|
COMPONENT_ADD_INCLUDEDIRS := newlib/port/include newlib/include
|
||||||
COMPONENT_SRCDIRS += newlib/port
|
COMPONENT_SRCDIRS += newlib/port
|
||||||
COMPONENT_ADD_LDFLAGS := $(LIB_PATH) -lnewlib
|
COMPONENT_ADD_LDFLAGS := $(LIB_PATH) -lnewlib
|
||||||
COMPONENT_ADD_LINKER_DEPS := $(LIB_PATH)
|
COMPONENT_ADD_LINKER_DEPS := $(LIB_PATH)
|
||||||
|
@ -110,7 +110,7 @@ typedef _fpos64_t fpos64_t;
|
|||||||
#ifdef __FOPEN_MAX__
|
#ifdef __FOPEN_MAX__
|
||||||
#define FOPEN_MAX __FOPEN_MAX__
|
#define FOPEN_MAX __FOPEN_MAX__
|
||||||
#else
|
#else
|
||||||
#define FOPEN_MAX 20
|
#define FOPEN_MAX 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __FILENAME_MAX__
|
#ifdef __FILENAME_MAX__
|
||||||
|
31
components/newlib/newlib/port/include/sys/unistd.h
Normal file
31
components/newlib/newlib/port/include/sys/unistd.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _ESP_SYS_UNISTD_H
|
||||||
|
#define _ESP_SYS_UNISTD_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include_next <sys/unistd.h>
|
||||||
|
|
||||||
|
int truncate(const char *, off_t __length);
|
||||||
|
int gethostname(char *__name, size_t __len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* _SYS_UNISTD_H */
|
35
components/newlib/newlib/port/include/sys/utime.h
Normal file
35
components/newlib/newlib/port/include/sys/utime.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef _UTIME_H_
|
||||||
|
#define _UTIME_H_
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct utimbuf {
|
||||||
|
time_t actime; // access time
|
||||||
|
time_t modtime; // modification time
|
||||||
|
};
|
||||||
|
|
||||||
|
int utime(const char *path, const struct utimbuf *times);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _UTIME_H_ */
|
21
components/newlib/newlib/port/pread.c
Normal file
21
components/newlib/newlib/port/pread.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "esp_vfs.h"
|
||||||
|
|
||||||
|
ssize_t pread(int fd, void *dst, size_t size, off_t offset)
|
||||||
|
{
|
||||||
|
return esp_vfs_pread(fd, dst, size, offset);
|
||||||
|
}
|
21
components/newlib/newlib/port/pwrite.c
Normal file
21
components/newlib/newlib/port/pwrite.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "esp_vfs.h"
|
||||||
|
|
||||||
|
ssize_t pwrite(int fd, const void *src, size_t size, off_t offset)
|
||||||
|
{
|
||||||
|
return esp_vfs_pwrite(fd, src, size, offset);
|
||||||
|
}
|
21
components/newlib/newlib/port/utime.c
Normal file
21
components/newlib/newlib/port/utime.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <utime.h>
|
||||||
|
#include "esp_vfs.h"
|
||||||
|
|
||||||
|
int utime(const char *path, const struct utimbuf *times)
|
||||||
|
{
|
||||||
|
return esp_vfs_utime(path, times);
|
||||||
|
}
|
@ -9,6 +9,6 @@ factory, 0, 0, 0x10000, 0xF0000
|
|||||||
ota_0, 0, ota_0, , 64K
|
ota_0, 0, ota_0, , 64K
|
||||||
ota_1, 0, ota_1, , 64K
|
ota_1, 0, ota_1, , 64K
|
||||||
# flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests
|
# flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests
|
||||||
flash_test, data, fat, , 528K
|
flash_test, data, fat, , 896K
|
||||||
|
|
||||||
# Note: still 1MB of a 4MB flash left free for some other purpose
|
# Note: still 1MB of a 4MB flash left free for some other purpose
|
||||||
|
|
Reference in New Issue
Block a user