-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spi_nand_flash): Add linux target support
- Loading branch information
1 parent
52be198
commit e7d6c04
Showing
22 changed files
with
987 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,44 @@ | ||
idf_build_get_property(target IDF_TARGET) | ||
|
||
set(reqs fatfs) | ||
set(inc diskio include) | ||
set(priv_inc priv_include) | ||
set(srcs "src/nand.c" | ||
"src/nand_winbond.c" | ||
"src/nand_gigadevice.c" | ||
"src/nand_alliance.c" | ||
"src/nand_micron.c" | ||
"src/nand_impl.c" | ||
"src/nand_impl_wrap.c" | ||
"src/nand_diag_api.c" | ||
"src/spi_nand_oper.c" | ||
"src/dhara_glue.c" | ||
"vfs/vfs_fat_spinandflash.c" | ||
"src/nand_impl_wrap.c" | ||
"diskio/diskio_nand.c") | ||
|
||
set(reqs fatfs) | ||
if(${target} STREQUAL "linux") | ||
|
||
list(APPEND srcs "src/nand_impl_linux.c" | ||
"src/nand_linux_mmap_emul.c") | ||
|
||
else() | ||
|
||
list(APPEND srcs "src/nand_winbond.c" | ||
"src/nand_gigadevice.c" | ||
"src/nand_alliance.c" | ||
"src/nand_micron.c" | ||
"src/nand_impl.c" | ||
"src/nand_impl_wrap.c" | ||
"src/nand_diag_api.c" | ||
"src/spi_nand_oper.c" | ||
"vfs/vfs_fat_spinandflash.c") | ||
|
||
set(priv_reqs vfs) | ||
list(APPEND inc vfs) | ||
|
||
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "5.3") | ||
list(APPEND reqs esp_driver_spi) | ||
else() | ||
list(APPEND reqs driver) | ||
endif() | ||
|
||
set(priv_reqs vfs) | ||
endif() | ||
|
||
|
||
idf_component_register(SRCS ${srcs} | ||
INCLUDE_DIRS include vfs diskio | ||
PRIV_INCLUDE_DIRS "priv_include" | ||
INCLUDE_DIRS ${inc} | ||
PRIV_INCLUDE_DIRS ${priv_inc} | ||
REQUIRES ${reqs} | ||
PRIV_REQUIRES ${priv_reqs}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
set(COMPONENTS main) | ||
|
||
project(nand_flash_host_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
| Supported Targets | Linux | | ||
| ----------------- | ----- | | ||
|
||
# Host Test for SPI NAND Flash Emulation | ||
|
||
## NAND Flash Emulation Configuration | ||
|
||
The NAND flash emulation can be configured using the `nand_mmap_emul_config_t` structure: | ||
|
||
```c | ||
// Configuration structure for NAND emulation | ||
nand_mmap_emul_config_t cfg = { | ||
.flash_file_name = "", // Empty string for temporary file, or specify path | ||
.flash_file_size = EMULATED_NAND_SIZE, // Default is 500MB | ||
.remove_dump = true // true to remove file after tests | ||
}; | ||
``` | ||
|
||
### Configuration Options: | ||
|
||
1. **flash_file_name**: | ||
- Empty string ("") - Creates temporary file with pattern "/tmp/idf-nand-XXXXXX" | ||
- Custom path - Creates file at specified location | ||
- Maximum length: 256 characters | ||
|
||
2. **flash_file_size**: | ||
- Default: EMULATED_NAND_SIZE (500MB) | ||
- Can be customized based on test requirements | ||
- Must be aligned to block size | ||
|
||
3. **remove_dump**: | ||
- true: Removes the memory-mapped file after testing | ||
- false: Keeps the file for debugging or data persistence | ||
|
||
### Usage Example: | ||
|
||
```c | ||
// Initialize with custom settings | ||
nand_mmap_emul_config_t cfg = { | ||
.flash_file_name = "/tmp/my_nand.bin", | ||
.flash_file_size = 1024 * 1024, // 1MB | ||
.remove_dump = false | ||
}; | ||
spi_nand_flash_config_t nand_flash_config = {.emul_conf = &cfg}; | ||
|
||
// Initialize nand_flash with NAND emulation parameter | ||
spi_nand_flash_device_t *handle; | ||
spi_nand_flash_init_device(&nand_flash_config, &handle) | ||
|
||
// Use NAND operations... | ||
|
||
// Cleanup | ||
ESP_ERROR_CHECK(spi_nand_flash_deinit_device(handle)); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
idf_component_register(SRCS "test_nand_flash.cpp" "test_app_main.cpp" | ||
REQUIRES fatfs | ||
WHOLE_ARCHIVE | ||
) | ||
|
||
target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2WithMain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencies: | ||
espressif/catch2: "^3.4.0" | ||
espressif/spi_nand_flash: | ||
version: '*' | ||
override_path: '../../' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <catch2/catch_session.hpp> | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
|
||
extern "C" void app_main(void) | ||
{ | ||
int argc = 1; | ||
const char *argv[2] = { | ||
"target_test_main", | ||
NULL | ||
}; | ||
|
||
auto result = Catch::Session().run(argc, argv); | ||
if (result != 0) { | ||
printf("Test failed with result %d\n", result); | ||
} else { | ||
printf("Test passed.\n"); | ||
} | ||
fflush(stdout); | ||
exit(result); | ||
} |
Oops, something went wrong.