【RT-Thread Studio】nor flash配置Fal分区
前置条件:【RT-Thread Studio】W25Q128配置
添加 FAL
软件包
配置SFUD
驱动程序,使用FAL的设备为W25Q128
将fal_cfg.h和fal_flash_sfud_port.c提取出来,放到自己创建的fal_porting目录。
修改
fal_flash_sfud_port.c
struct fal_flash_dev nor_flash0 =
{.name = FAL_USING_NOR_FLASH_DEV_NAME,.addr = 0,.len = 16 * 1024 * 1024,.blk_size = 4096,.ops = {init, read, write, erase},.write_gran = 1
};
fal_cfg.h
#define NOR_FLASH_DEV_NAME FAL_USING_NOR_FLASH_DEV_NAME/* ===================== Flash device Configuration ========================= */
extern struct fal_flash_dev nor_flash0;/* flash device table */
#define FAL_FLASH_DEV_TABLE \
{ \&nor_flash0, \
}
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
#define FAL_PART_TABLE \
{ \{FAL_PART_MAGIC_WORD, "filesystem", NOR_FLASH_DEV_NAME, 0, 16*1024*1024, 0}, \
}
#endif /* FAL_PART_HAS_TABLE_CFG */
测试应用
#include <app_fs/w25qxx.h>
#include <fal.h>static void app_fs_init(void)
{dev_spi_flash_init();fal_init();
}static int component_app_fs_init(void)
{app_fs_init();return RT_EOK;
}INIT_COMPONENT_EXPORT(component_app_fs_init);
开机日志:
[16] I/SFUD: Find a Winbond flash chip. Size is 16777216 bytes.
[24] I/SFUD: W25Q128 flash device is initialize success.
[30] I/SFUD: Probe SPI flash W25Q128 by SPI device spi10 success.
read w25q ID is:17ef
[D/FAL] (fal_flash_init:49) Flash device | W25Q128 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name | flash_dev | offset | length |
[I/FAL] -------------------------------------------------------------
[I/FAL] | filesystem | W25Q128 | 0x00000000 | 0x01000000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer (V1.0.0) initialize success.