mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-12-16 02:43:47 +08:00
feat(fatfs): modify FATFS for ESP8266
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "sdmmc_types.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
// #include "driver/spi_master.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -32,7 +32,7 @@ extern "C" {
|
||||
*
|
||||
* 'slot' can be set to one of HSPI_HOST, VSPI_HOST.
|
||||
*/
|
||||
#define SDSPI_HOST_DEFAULT() {\
|
||||
/*#define SDSPI_HOST_DEFAULT() {\
|
||||
.flags = SDMMC_HOST_FLAG_SPI, \
|
||||
.slot = HSPI_HOST, \
|
||||
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
|
||||
@@ -47,7 +47,7 @@ extern "C" {
|
||||
.io_int_enable = &sdspi_host_io_int_enable, \
|
||||
.io_int_wait = &sdspi_host_io_int_wait, \
|
||||
.command_timeout_ms = 0, \
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Extra configuration for SPI host
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
set(srcs "diskio/diskio.c"
|
||||
"diskio/diskio_rawflash.c"
|
||||
"diskio/diskio_sdmmc.c"
|
||||
"diskio/diskio_wl.c"
|
||||
"src/ff.c"
|
||||
"port/freertos/ffsystem.c"
|
||||
@@ -14,5 +13,5 @@ endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS diskio vfs src
|
||||
REQUIRES wear_levelling sdmmc
|
||||
REQUIRES wear_levelling
|
||||
)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := diskio vfs 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);
|
||||
for (size_t i = 0; i < args->word_count; ++i) {
|
||||
uint32_t val = rand();
|
||||
uint32_t val = i * 77;
|
||||
if (args->write) {
|
||||
int cnt = fwrite(&val, sizeof(val), 1, f);
|
||||
if (cnt != 1) {
|
||||
|
||||
@@ -41,13 +41,30 @@ static void test_setup(size_t max_files)
|
||||
};
|
||||
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;
|
||||
const void* mmap_ptr;
|
||||
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;
|
||||
spi_flash_munmap(mmap_handle);
|
||||
// spi_flash_mmap_handle_t mmap_handle;
|
||||
// const void* mmap_ptr;
|
||||
// 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;
|
||||
// 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) {
|
||||
printf("Copying fatfs.img into test partition...\n");
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if 0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.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
|
||||
#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
|
||||
endif
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS += newlib/port/include newlib/include
|
||||
COMPONENT_ADD_INCLUDEDIRS := newlib/port/include newlib/include
|
||||
COMPONENT_SRCDIRS += newlib/port
|
||||
COMPONENT_ADD_LDFLAGS := $(LIB_PATH) -lnewlib
|
||||
COMPONENT_ADD_LINKER_DEPS := $(LIB_PATH)
|
||||
|
||||
@@ -110,7 +110,7 @@ typedef _fpos64_t fpos64_t;
|
||||
#ifdef __FOPEN_MAX__
|
||||
#define FOPEN_MAX __FOPEN_MAX__
|
||||
#else
|
||||
#define FOPEN_MAX 20
|
||||
#define FOPEN_MAX 10
|
||||
#endif
|
||||
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user