Merge pull request #4930 from mysterywolf/littlefs-check
[stm32f407-explorer] 优化FAL相关设置
This commit is contained in:
commit
b3ea49c8a3
|
@ -101,7 +101,8 @@ menu "Onboard Peripheral Drivers"
|
|||
select BSP_USING_SPI_FLASH
|
||||
select BSP_USING_FS
|
||||
select PKG_USING_FAL
|
||||
select FAL_USING_SFUD_PORT
|
||||
select FAL_USING_AUTO_INIT
|
||||
select FAL_PART_HAS_TABLE_CFG
|
||||
select PKG_USING_LITTLEFS
|
||||
select RT_USING_SYSTEM_WORKQUEUE
|
||||
default n
|
||||
|
|
|
@ -20,6 +20,8 @@ if GetDepend(['BSP_USING_SPI_FLASH']):
|
|||
|
||||
if GetDepend(['BSP_USING_FS']):
|
||||
src += Glob('ports/drv_filesystem.c')
|
||||
if GetDepend(['BSP_USING_SPI_FLASH_LITTLEFS']):
|
||||
src += Glob('ports/fal_spi_flash_sfud_port.c')
|
||||
|
||||
if GetDepend(['BSP_USING_SRAM']):
|
||||
src += Glob('ports/drv_sram.c')
|
||||
|
|
|
@ -83,7 +83,9 @@ static int onboard_spiflash_mount(void)
|
|||
{
|
||||
struct rt_device *mtd_dev = RT_NULL;
|
||||
|
||||
#ifndef FAL_USING_AUTO_INIT
|
||||
fal_init();
|
||||
#endif
|
||||
|
||||
mtd_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);
|
||||
if (!mtd_dev)
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <board.h>
|
||||
|
||||
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
|
||||
extern struct fal_flash_dev nor_flash0;
|
||||
extern struct fal_flash_dev w25q128;
|
||||
#else
|
||||
#define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024)
|
||||
#define FLASH_SIZE_GRANULARITY_64K (64 * 1024)
|
||||
|
@ -34,7 +34,7 @@ extern const struct fal_flash_dev stm32_onchip_flash_128k;
|
|||
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
|
||||
#define FAL_FLASH_DEV_TABLE \
|
||||
{ \
|
||||
&nor_flash0, \
|
||||
&w25q128, \
|
||||
}
|
||||
#else
|
||||
#define FAL_FLASH_DEV_TABLE \
|
||||
|
@ -52,7 +52,7 @@ extern const struct fal_flash_dev stm32_onchip_flash_128k;
|
|||
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
|
||||
#define FAL_PART_TABLE \
|
||||
{ \
|
||||
{FAL_PART_MAGIC_WROD, "spiflash0", FAL_USING_NOR_FLASH_DEV_NAME, 0 , 16 * 1024 * 1024, 0}, \
|
||||
{FAL_PART_MAGIC_WROD, "spiflash0", "W25Q128", 0 , 16 * 1024 * 1024, 0}, \
|
||||
}
|
||||
#else
|
||||
#define FAL_PART_TABLE \
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-08-07 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <fal.h>
|
||||
#include <sfud.h>
|
||||
|
||||
#ifdef RT_USING_SFUD
|
||||
#include <spi_flash_sfud.h>
|
||||
#endif
|
||||
|
||||
static int init(void);
|
||||
static int read(long offset, uint8_t *buf, size_t size);
|
||||
static int write(long offset, const uint8_t *buf, size_t size);
|
||||
static int erase(long offset, size_t size);
|
||||
|
||||
static sfud_flash_t sfud_dev = NULL;
|
||||
struct fal_flash_dev w25q128 =
|
||||
{
|
||||
.name = "W25Q128",
|
||||
.addr = 0,
|
||||
.len = 16 * 1024 * 1024,
|
||||
.blk_size = 4096,
|
||||
.ops = {init, read, write, erase},
|
||||
.write_gran = 1
|
||||
};
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
sfud_dev = rt_sfud_flash_find_by_dev_name("W25Q128");
|
||||
if (RT_NULL == sfud_dev)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* update the flash chip information */
|
||||
w25q128.blk_size = sfud_dev->chip.erase_gran;
|
||||
w25q128.len = sfud_dev->chip.capacity;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read(long offset, uint8_t *buf, size_t size)
|
||||
{
|
||||
assert(sfud_dev);
|
||||
assert(sfud_dev->init_ok);
|
||||
sfud_read(sfud_dev, w25q128.addr + offset, size, buf);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static int write(long offset, const uint8_t *buf, size_t size)
|
||||
{
|
||||
assert(sfud_dev);
|
||||
assert(sfud_dev->init_ok);
|
||||
if (sfud_write(sfud_dev, w25q128.addr + offset, size, buf) != SFUD_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static int erase(long offset, size_t size)
|
||||
{
|
||||
assert(sfud_dev);
|
||||
assert(sfud_dev->init_ok);
|
||||
if (sfud_erase(sfud_dev, w25q128.addr + offset, size) != SFUD_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
|
@ -15,21 +15,15 @@
|
|||
|
||||
#if defined(BSP_USING_SPI_FLASH)
|
||||
|
||||
#ifdef FAL_USING_NOR_FLASH_DEV_NAME
|
||||
#define _SPI_FLASH_NAME FAL_USING_NOR_FLASH_DEV_NAME
|
||||
#else
|
||||
#define _SPI_FLASH_NAME "W25Q128"
|
||||
#endif
|
||||
|
||||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GPIOB, GPIO_PIN_14);
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe(_SPI_FLASH_NAME, "spi10"))
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
|
||||
{
|
||||
return -RT_ERROR;
|
||||
};
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue