最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c - little-fs file system for FRAM memory - Stack Overflow

programmeradmin0浏览0评论

I wanted to use littlef-fs project () for my fram external memory on msp430 microcontroller.

I know that that lib is dedicated for flash memory use case but I wanted to try use it for FRAM. I prepared some simulated block interface for it and tried to format the memory and mount the file system but during format I got error related to unwrittable superblock. Returned error code -28 suggests no available space on FRAM memory.

My interface looks somewhat like this:

lfs_t lfs;
lfs_file_t file;

#pragma PERSISTENT(read_cache)
static uint8_t read_cache[512] = {0};  

#pragma PERSISTENT(write_cache)
static uint8_t write_cache[512] = {0};      

#pragma PERSISTENT(lookahead_buffer)
static uint8_t lookahead_buffer[64] = {0};  

const struct lfs_config cfg = {
    // block device operations
    .read  = block_device_read,
    .prog  = block_device_write,
    .erase = block_device_erase,
    .sync  = block_device_sync,

    // block device configuration
    .read_size = 512,
    .prog_size = 512,
    .block_size = 512,
    .block_count = 6144,
    .cache_size = 512,
    .lookahead_size = 64,
    .block_cycles = -1,

    // buffers
    .read_buffer = read_cache,  
    .prog_buffer = write_cache,  
    .lookahead_buffer = lookahead_buffer,
};

// Erase function (Not needed for FRAM, just return 0)
int block_device_erase(const struct lfs_config *c, lfs_block_t block) {
    return 0;
}

// Sync function (Not needed for FRAM, just return 0)
int block_device_sync(const struct lfs_config *c) {
    return 0;
}

int block_device_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, uint8_t *buffer, lfs_size_t size) {
    // Convert LittleFS block and offset to FRAM address
    uint32_t addr = (block * BLOCK_SIZE) + off;

    // Read data from FRAM
    if (!mem_get_size()) {
        debug_printf("Memory size equal 0");
        return LFS_ERR_IO;  // Check if FRAM is available
    }
    int result = mem_read(addr, buffer, size);
    
    if(result == 0) {
        return 0;
    } else {
        return LFS_ERR_IO;
    }
}

int block_device_write(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const uint8_t *buffer, lfs_size_t size) {
    // Convert LittleFS block and offset to FRAM address
    uint32_t addr = (block * BLOCK_SIZE) + off;

    // Write data to FRAM
    if (!mem_get_size()) {
        debug_printf("Memory size equal 0");
        return LFS_ERR_IO;  // Check if FRAM is available
    }
    int result = mem_write(addr, buffer, size);
    if(result == 0) {
        return 0;
    } else {
        return LFS_ERR_IO;
    }
}

Read and write operations work just fine because I tested them separately, so I omitted the drivers details in above code. I do not need synchronization so I just return 0 in that function. I am somewhat stuck at this point. I do not have too much experience with file systems for different kind of memories. Is it doable to adjust little-fs for FRAM without changes in the library or will have to interfere with the content of the library itself to make it work?

FLASH requires erases before write operations. FRAM does not require it so I assumed that maybe returning 0 by erase function will do, but apparently I omitted some obvious issue in my code and unfortunately I couldn't find anything about little-fs for FRAM in the net.

发布评论

评论列表(0)

  1. 暂无评论