Skip to content

Commit

Permalink
feat(spi_nand_flash): expose lower-level API and make it usable witho…
Browse files Browse the repository at this point in the history
…ut Dhara
  • Loading branch information
RathiSonika committed Nov 11, 2024
1 parent d3e5a00 commit 8df437c
Show file tree
Hide file tree
Showing 13 changed files with 858 additions and 504 deletions.
5 changes: 5 additions & 0 deletions spi_nand_flash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
set(srcs "src/nand.c"
"src/nand_winbond.c"
"src/nand_gigadevice.c"
"src/nand_alliance.c"
"src/nand_micron.c"
"src/spi_nand_oper.c"
"src/spi_nand_api.c"
"src/dhara_glue.c"
"vfs/vfs_fat_spinandflash.c"
"diskio/diskio_nand.c")
Expand Down
2 changes: 1 addition & 1 deletion spi_nand_flash/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.6.0"
version: "0.7.0"
description: Driver for accessing SPI NAND Flash
url: https://github.com/espressif/idf-extra-components/tree/master/spi_nand_flash
issues: https://github.com/espressif/idf-extra-components/issues
Expand Down
36 changes: 29 additions & 7 deletions spi_nand_flash/include/spi_nand_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*
* SPDX-FileContributor: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2015-2024 Espressif Systems (Shanghai) CO LTD
*/

#pragma once
Expand All @@ -12,12 +12,17 @@
#include "esp_err.h"
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include "dhara/map.h"

#ifdef __cplusplus
extern "C" {
#endif

#define NAND_MAX_DEVICES 1

typedef uint32_t page_t;
typedef uint32_t block_t;
typedef uint32_t sector_t;

/** @brief Structure to describe how to configure the nand access layer.
@note The spi_device_handle_t must be initialized with the flag SPI_DEVICE_HALFDUPLEX
*/
Expand Down Expand Up @@ -47,7 +52,7 @@ esp_err_t spi_nand_flash_init_device(spi_nand_flash_config_t *config, spi_nand_f
* @param sector_id The id of the sector to read.
* @return ESP_OK on success, or a flash error code if the read failed.
*/
esp_err_t spi_nand_flash_read_sector(spi_nand_flash_device_t *handle, uint8_t *buffer, dhara_sector_t sector_id);
esp_err_t spi_nand_flash_read_sector(spi_nand_flash_device_t *handle, uint8_t *buffer, sector_t sector_id);

/** @brief Copy a sector to another sector from the nand flash.
*
Expand All @@ -56,7 +61,7 @@ esp_err_t spi_nand_flash_read_sector(spi_nand_flash_device_t *handle, uint8_t *b
* @param dst_sec The destination sector id to which data should be copied.
* @return ESP_OK on success, or a flash error code if the copy failed.
*/
esp_err_t spi_nand_flash_copy_sector(spi_nand_flash_device_t *handle, dhara_sector_t src_sec, dhara_sector_t dst_sec);
esp_err_t spi_nand_flash_copy_sector(spi_nand_flash_device_t *handle, sector_t src_sec, sector_t dst_sec);

/** @brief Write a sector to the nand flash.
*
Expand All @@ -65,7 +70,7 @@ esp_err_t spi_nand_flash_copy_sector(spi_nand_flash_device_t *handle, dhara_sect
* @param sector_id The id of the sector to write.
* @return ESP_OK on success, or a flash error code if the write failed.
*/
esp_err_t spi_nand_flash_write_sector(spi_nand_flash_device_t *handle, const uint8_t *buffer, dhara_sector_t sector_id);
esp_err_t spi_nand_flash_write_sector(spi_nand_flash_device_t *handle, const uint8_t *buffer, sector_t sector_id);

/** @brief Trim sector from the nand flash.
*
Expand All @@ -77,7 +82,7 @@ esp_err_t spi_nand_flash_write_sector(spi_nand_flash_device_t *handle, const uin
* @param sector_id The id of the sector to be trimmed.
* @return ESP_OK on success, or a flash error code if the trim failed.
*/
esp_err_t spi_nand_flash_trim(spi_nand_flash_device_t *handle, dhara_sector_t sector_id);
esp_err_t spi_nand_flash_trim(spi_nand_flash_device_t *handle, sector_t sector_id);

/** @brief Synchronizes any cache to the device.
*
Expand All @@ -94,7 +99,7 @@ esp_err_t spi_nand_flash_sync(spi_nand_flash_device_t *handle);
* @param[out] number_of_sectors A pointer of where to put the return value
* @return ESP_OK on success, or a flash error code if the operation failed.
*/
esp_err_t spi_nand_flash_get_capacity(spi_nand_flash_device_t *handle, dhara_sector_t *number_of_sectors);
esp_err_t spi_nand_flash_get_capacity(spi_nand_flash_device_t *handle, sector_t *number_of_sectors);

/** @brief Retrieve the size of each sector.
*
Expand All @@ -111,6 +116,23 @@ esp_err_t spi_nand_flash_get_sector_size(spi_nand_flash_device_t *handle, uint32
*/
esp_err_t spi_nand_erase_chip(spi_nand_flash_device_t *handle);

/** @brief Retrieve the number of blocks available.
*
* @param handle The handle to the SPI nand flash chip.
* @param[out] number_of_blocks A pointer of where to put the return value
* @return ESP_OK on success, or a flash error code if the operation failed.
*/
esp_err_t spi_nand_flash_get_block_num(spi_nand_flash_device_t *handle, block_t *number_of_blocks);

/** @brief Check if the given block is bad block.
*
* @param handle The handle to the SPI nand flash chip.
* @param block The block number to verify if it is bad block
* @param[out] is_bad A pointer of where to put the return value
* @return ESP_OK on success, or a flash error code if the operation failed.
*/
esp_err_t spi_nand_flash_is_bad_block(spi_nand_flash_device_t *handle, block_t block, bool *is_bad);

/** @brief De-initialize the handle, releasing any resources reserved.
*
* @param handle The handle to the SPI nand flash chip.
Expand Down
Loading

0 comments on commit 8df437c

Please sign in to comment.