Files
STM32F4-Base/Drivers/BSP/GD5F2GQ5UE/fal_flash_gd5f2gq5ue.c

86 lines
2.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 模块名称FAL Flash 设备适配
* 模块功能:将 GD5F2GQ5UE 驱动接口适配到 FAL 框架
* 适用平台STM32F407ZGT6
* 作者:王建锋
* 创建日期2026-07-16
* 修改记录:
* 2026-07-16 王建锋 创建初始版本
*/
/* 头文件包含区 */
#include "fal_def.h"
#include "gd5f2gq5ue.h"
/* ======================== FAL 操作函数适配 ======================== */
/*
* 函数功能Flash 设备初始化适配
* 入口参数:无
* 返回值0 - 成功,其他 - 错误码
* 限定条件SPI 和 GPIO 已由 CubeMX 初始化完成
* 函数说明:调用底层驱动的初始化函数
*/
static int gd5f_fal_init(void)
{
return gd5f2gq5ue_init();
}
/*
* 函数功能Flash 读取适配
* 入口参数offset - 起始字节偏移 long
* p_buf - 数据缓冲区 uint8_t*
* size - 读取字节数 size_t
* 返回值0 - 成功,其他 - 错误码
* 限定条件gd5f_fal_init() 已成功调用
* 函数说明:直接转发到底层驱动的读取函数
*/
static int gd5f_fal_read(long offset, uint8_t *p_buf, size_t size)
{
return gd5f2gq5ue_read(offset, p_buf, size);
}
/*
* 函数功能Flash 写入适配
* 入口参数offset - 起始字节偏移 long
* p_buf - 数据缓冲区 const uint8_t*
* size - 写入字节数 size_t
* 返回值0 - 成功,其他 - 错误码
* 限定条件:目标区域已擦除
* 函数说明:直接转发到底层驱动的写入函数
*/
static int gd5f_fal_write(long offset, const uint8_t *p_buf, size_t size)
{
return gd5f2gq5ue_write(offset, p_buf, size);
}
/*
* 函数功能Flash 擦除适配
* 入口参数offset - 起始字节偏移 long
* size - 擦除字节数 size_t
* 返回值0 - 成功,其他 - 错误码
* 限定条件gd5f_fal_init() 已成功调用
* 函数说明:直接转发到底层驱动的擦除函数
*/
static int gd5f_fal_erase(long offset, size_t size)
{
return gd5f2gq5ue_erase(offset, size);
}
/* ======================== FAL Flash 设备定义 ======================== */
/* GD5F2GQ5UE FAL 设备实例总容量256MB块大小128KB */
const struct fal_flash_dev gd5f2gq5ue_flash = {
.name = "gd5f2gq5ue",
.addr = 0,
.len = GD5F_TOTAL_SIZE,
.blk_size = GD5F_BLOCK_SIZE,
.ops = {
.init = gd5f_fal_init,
.read = gd5f_fal_read,
.write = gd5f_fal_write,
.erase = gd5f_fal_erase,
},
.write_gran = 8,
};