2 Star 11 Fork 6

MaYuchen/BMCBootLoader

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bsp_ocflash.c 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
MaYuchen 提交于 2023-03-22 00:01 +08:00 . 增加注释。
/*
* @Author: Ma Yuchen
* @Date: 2022-11-23 12:19:05
* @LastEditors: Ma YuChen
* @LastEditTime: 2022-11-23 23:27:34
* @Description: file content
* @FilePath: \BootLoader\bsp_ocflash.c
*/
#include "bsp_ocflash.h"
#include <gd32f4xx_fmc.h>
/**
* @description: 初始化MCU内部Flash操作模块
* @return {*}
*/
void Flash_IF_Init(void)
{
fmc_unlock();
fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_OPERR | FMC_FLAG_WPERR | FMC_FLAG_PGMERR | FMC_FLAG_PGSERR | FMC_FLAG_RDDERR | FMC_FLAG_BUSY);
}
int Flash_IF_App_Erase(int StartSectorId, int EndSectorId)
{
int sectorIdIndex = StartSectorId;
while (sectorIdIndex <= EndSectorId)
{
if (FMC_READY == fmc_sector_erase(CTL_SN(sectorIdIndex)))
{
sectorIdIndex++;
}
else
{
return -1;
}
}
return 0;
}
/**
* @brief 按照4字节单位将缓存区数据烧写到Flash
*
* @param address [in out] 传输地址的指针
* @param buffer [in] 数据缓存区
* @param length [in] 数据缓存区长度
* @return int 0 正确 -1 烧写错误 -2 回读错误
*/
int Flash_IF_Write(__IO uint32_t *address, uint32_t *buffer, int length)
{
while (length > 0)
{
if (FMC_READY == fmc_word_program(*address, *buffer))
{
if (*buffer != REG32(*address))
{
return -2;
}
*address += 4;
buffer++;
length--;
}
else
{
return -1;
}
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/VoldemortCat/bmcboot-loader.git
git@gitee.com:VoldemortCat/bmcboot-loader.git
VoldemortCat
bmcboot-loader
BMCBootLoader
master

搜索帮助