您好!
我尝试写入闪存、但没有成功。
有人能帮我解决问题吗?
谢谢、
格尔格利
我编写了以下代码:
#define FLASH_CONTING_BASE 0x400FD000
const unsigned int fma = flash_control_BASE + 0x000;
const unsigned int FMD = FLASH_CONTRAL_BASE + 0x004;
const unsigned int FMC = FLASH_CONTRAL_BASE + 0x008;
const unsigned int FLLPEKEY = FLASH_CONTRAL_BASE + 0x03C;
const unsigned int BOOTCFG = FLASH_CONTING_BASE + 0x1D0;
//将掩码中定义的位设置为*dst 中的*src。
void memcpy1 (void* dst、const void* src、size_t len、unsigned int mask)
{
unsigned int i_src =*(unsigned int*) src;
unsigned int i_dst =*(unsigned int*) dst;
unsigned int res =(I_dst &~遮罩)|(I_src &遮罩);
memcpy (dst、res、len);
}
空测试()
{
const int flash_address = 0x0FFFFC;
const int 值= 123456;
// const int magic = 0xA442;//-不使用,因为 BOOTCFG 密钥位为0
//从 BOOTCFG 读取 KEY 位
System_printf ("BOOTCFG key:%d\n"、(*(unsigned int*) BOOTCFG)& 0x16);
//从闪存读取数据
system_printf ("之前:%d\n"、*(int*) flash_address);
system_flush();
//将地址写入 FMA
memcpy1 ((void*) FMA、&flash_address、4、0xFFFFFF);
//将数据写入 FMD
memcpy1 ((void*) FMD、&value、4、0xFFFFFFFF);
//将 FMPKEY 和位 COMT +写入 FMC
unsigned int fmc =((*(unsigned int*) FLLPEKEY)& 0xFFFF)/* magic*/<< 16)| 0x09;
memcpy1 ((void*)(FMC)、&FMC、4、0xFFFFFF000F);
//等待操作完成
int i = 0;
while (((unsigned char*) FMC)[0]!= 0)
{
i++;
}
//再次从闪存读取数据--现在应该被修改
System_printf ("在:%d\n"、*(int*) flash_address 之后");
system_flush();
}