原始版本

This commit is contained in:
冯佳
2025-06-19 21:56:46 +08:00
parent fe98e5f010
commit a4841450cf
4152 changed files with 1910684 additions and 0 deletions

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-12-5 SummerGift first version
*/
#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_
#include <board.h>
#include <fal_def.h>
#define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024)
#define FLASH_SIZE_GRANULARITY_64K (8 * 64 * 1024)
#define FLASH_SIZE_GRANULARITY_128K (8 * 128 * 1024)
#define STM32_FLASH_START_ADRESS_16K STM32_FLASH_START_ADRESS
#define STM32_FLASH_START_ADRESS_64K STM32_FLASH_START_ADRESS
#define STM32_FLASH_START_ADRESS_128K STM32_FLASH_START_ADRESS
extern const struct fal_flash_dev stm32_onchip_flash_16k;
extern const struct fal_flash_dev stm32_onchip_flash_64k;
extern const struct fal_flash_dev stm32_onchip_flash_128k;
extern struct fal_flash_dev w25q16jv;
/* flash device table */
#define FAL_FLASH_DEV_TABLE \
{ \
&stm32_onchip_flash_128k, \
&w25q16jv, \
}
/* ====================== Partition Configuration ========================== */
// #define FAL_PART_TABLE \
// { \
// {FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0, 384 * 1024, 0}, \
// {FAL_PART_MAGIC_WROD, "param", "onchip_flash_128k", 384 * 1024, 512 * 1024, 0}, \
// {FAL_PART_MAGIC_WROD, "easyflash", "W25Q16JV", 0, 512 * 1024, 0}, \
// {FAL_PART_MAGIC_WROD, "download", "W25Q16JV", 512 * 1024, 512 * 1024, 0}, \
// {FAL_PART_MAGIC_WROD, "filesystem", "W25Q16JV", (512 + 512) * 1024, 1 * 1024 * 1024, 0}, \
// }
#define FAL_PART_TABLE \
{ \
{FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0, 384*1024, 0}, \
{FAL_PART_MAGIC_WROD, "param", "onchip_flash_128k", 384*1024, 512*1024, 0}, \
{FAL_PART_MAGIC_WROD, "easyflash", "W25Q16JV", 0, 512*1024, 0}, \
{FAL_PART_MAGIC_WROD, "download", "W25Q16JV", 512*1024, 512*1024, 0}, \
{FAL_PART_MAGIC_WROD, "filesystem", "W25Q16JV", 1024*1024, 1024*1024, 0}, \
}
#endif /*FAL_PART_TABLE*/

View File

@ -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 <dev_spi_flash_sfud.h>
#endif
static int init(void);
static int read(long offset, rt_uint8_t *buf, rt_size_t size);
static int write(long offset, const rt_uint8_t *buf, rt_size_t size);
static int erase(long offset, rt_size_t size);
static sfud_flash_t sfud_dev = NULL;
struct fal_flash_dev w25q16jv =
{
.name = "W25Q16JV",
.addr = 0,
.len = 2 * 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("W25Q16JV");
if (RT_NULL == sfud_dev)
{
return -1;
}
/* update the flash chip information */
w25q16jv.blk_size = sfud_dev->chip.erase_gran;
w25q16jv.len = sfud_dev->chip.capacity;
return 0;
}
static int read(long offset, rt_uint8_t *buf, rt_size_t size)
{
RT_ASSERT(sfud_dev);
RT_ASSERT(sfud_dev->init_ok);
sfud_read(sfud_dev, w25q16jv.addr + offset, size, buf);
return size;
}
static int write(long offset, const rt_uint8_t *buf, rt_size_t size)
{
RT_ASSERT(sfud_dev);
RT_ASSERT(sfud_dev->init_ok);
if (sfud_write(sfud_dev, w25q16jv.addr + offset, size, buf) != SFUD_SUCCESS)
{
return -1;
}
return size;
}
static int erase(long offset, rt_size_t size)
{
RT_ASSERT(sfud_dev);
RT_ASSERT(sfud_dev->init_ok);
if (sfud_erase(sfud_dev, w25q16jv.addr + offset, size) != SFUD_SUCCESS)
{
return -1;
}
return size;
}