我有一个 ESP32 板和一个通过 SPI 总线连接的 Winbond W25N01 (1Gbit) NAND 闪存芯片。我正在使用 Mongoose OS 和他们的 Winbond VFS 驱动程序。我正在使用 LittleFS。
它主要是有效的,但是在我打开大约 20 个文件后,打开更多文件时出现错误,说“超级块已变得不可写”。我已经编写了一些 Arduino 代码来进行最低限度的测试,我相信硬件很好,尽管它现在在面包板上。
我想知道我的配置和代码是否正确,不胜感激,
#include "mgos.h"
#include "mgos_system.h"
#include "mgos_vfs_dev_w25xxx.h"
#include <stdio.h>
#define W25XXX_DEBUG 1
#define LED_PIN 13
static void timer_cb(void *arg)
{
#if 1
static uint16_t ctr = 0;
FILE *fp;
char c[] = "this is a test";
char buffer[100];
char writeBuf[100];
char fileName[50];
sprintf(fileName, "/data/file-%d.txt", ctr);
LOG(LL_ERROR, ("***** File Name: %s\r\n", fileName));
/* Open file for both reading and writing */
fp = fopen(fileName, "w+");
if(fp == NULL)
{
LOG(LL_ERROR, ("fopen() failed"));
return;
}
else
{
LOG(LL_ERROR, ("fopen() SUCCESS!!"));
}
/* Write data to the file */
sprintf(writeBuf, "Here is some data for the file - %d", ctr);
fwrite(writeBuf, strlen(writeBuf) + 1, 1, fp);
/* Seek to the beginning of the file */
fseek(fp, 0, SEEK_SET);
/* Read and display data */
fread(buffer, strlen(writeBuf)+1, 1, fp);
LOG(LL_ERROR, ("Read: %s", buffer));
fclose(fp);
ctr++;
#endif
#ifdef LED_PIN
mgos_gpio_toggle(LED_PIN);
#endif
(void) arg;
}
enum mgos_app_init_result mgos_app_init(void)
{
mgos_wdt_disable();
mgos_gpio_set_mode(LED_PIN, MGOS_GPIO_MODE_OUTPUT);
mgos_set_timer(2000, MGOS_TIMER_REPEAT, timer_cb, NULL);
return MGOS_APP_INIT_SUCCESS;
}
mos.yml
author: mongoose-os
description: A Mongoose OS app skeleton
version: 1.0
libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}
# From the W25Nxxx driver code:
#define W25XXX_PAGE_SIZE 2048U
#define W25XXX_BLOCK_SIZE (64 * W25XXX_PAGE_SIZE)
#define W25XXX_DIE_SIZE (1024 * W25XXX_BLOCK_SIZE)
# Optional. List of tags for online search.
tags:
- c
# List of files / directories with C sources. No slashes at the end of dir names.
sources:
- src
# List of dirs. Files from these dirs will be copied to the device filesystem
filesystem:
- fs
config_schema:
- ["spi.enable", true]
# Other SPI interface options go here.
- ["spi.miso_gpio", 19]
- ["spi.mosi_gpio", 18]
- ["spi.sclk_gpio", 5]
- ["spi.cs0_gpio", 21]
- ["devtab.dev0.name", "spif0"]
- ["devtab.dev0.type", "w25xxx"]
- ["devtab.dev0.opts", '{"cs": 0, "freq": 10000000, "ecc_chk": 0}']
# json_scanf(opts, strlen(opts),
# "{cs: %d, freq: %d, mode: %d, "
# "bb_reserve: %u, ecc_chk: %B, spi: %T}",
# &cs_num, &spi_freq, &spi_mode, &bb_reserve, &ecc_chk,
# &spi_cfg_json);
- ["fstab.fs0.dev", "spif0"]
- ["fstab.fs0.type", "LFS"]
- ["fstab.fs0.opts", '{"bs": 131072}'] # bs 1024*64 # Fails without this line
- ["fstab.fs0.path", "/data"]
- ["fstab.fs0.create", true]
# // block device configuration
# .read_size = 16,
# .prog_size = 16,
# .block_size = 2048*64,
# .block_count = 1024,
# .lookahead = 2048,
- ["debug.level", 3]
libs:
- origin: https://github.com/mongoose-os-libs/vfs-dev-w25xxx
- origin: https://github.com/mongoose-os-libs/fstab
# Used by the mos tool to catch mos binaries incompatible with this file format
manifest_version: 2017-09-29
错误:
[Mar 17 14:44:13.752] main.c:57 ***** File Name: /data/file-20.txt
[Mar 17 14:44:13.752]
[Mar 17 14:44:13.758] mgos_vfs.c:283 /data/file-20.txt -> /data/file-20.txt pl 5 -> 2 0x3ffb7e4c (refs 1)
[Mar 17 14:44:14.055] /data/fwbuild-volumes/latest/apps/winbond-w25n-test/esp32/build_contexts/build_ctx_434460174/deps/vfs-fs-lfs/littlefs/lfs.c:1691:warn: Superblock 0x1 has become unwritable
[Mar 17 14:44:14.074] mgos_vfs.c:377 open /data/file-20.txt 0x602 0x1b6 => 0x3ffb7e4c file-20.txt -6 => -6 (refs 0)
[Mar 17 14:44:14.076] main.c:66 fopen() failed