请问大家,为什么FMC_Erase返回总是-1,主函数中PE0,PE1,PE2是我的三个按键,我主要是想实验对flash的擦写,将数据存到flash中,实现掉电数据不丢失,但现在一个插除页都是失败的,还请大家解惑。
#include <stdio.h>
#include "Nano100Series.h"
#define DATA_FLASH_TEST_BASE 0x12400;
int32_t u32Addr = DATA_FLASH_TEST_BASE;
uint32_t u32Pattern = 0xA5A5A5A5;
uint32_t u32data;
void dataflash_test()
{
SYS_UnlockReg();
FMC_Open();
FMC_Erase(u32Addr);
if(FMC_Erase(u32Addr)==-1)
{
printf("erase--error\r\n");
}
FMC_Write(u32Addr, u32Pattern);
u32data = FMC_Read(u32Addr);
if (u32data != u32Pattern)
{
printf("data different");
}
printf("one--u32pattern--%x\r\n",u32Pattern);
printf("one--dihzi--%x\r\n",&u32Addr);
printf("one--u32data--%x\r\n",u32data);
printf("one--dizhi--%x\r\n",&u32data);
FMC_Write(u32Addr+4, u32Pattern);
u32data = FMC_Read(u32Addr+4);
if (u32data != u32Pattern)
{
printf("data error-----u32addr+4\r\n");
}
printf(" two----%x----u32pattern\r\n",u32Pattern);
printf(" two----%x----dizhi\r\n",&u32Addr);
printf("two----%x----u32data\r\n",u32data);
printf("two----%x----dizhi\r\n",&u32data);
SYS_LockReg();
}
void dataflash_test_read()
{
u32data = FMC_Read(u32Addr);
printf("one--u32data--%x\r\n",&u32Addr);
printf("one--u32data--%x\r\n",&u32data);
}
void SYS_Init(void)
{
SYS_UnlockReg();
CLK_EnableXtalRC(CLK_PWRCTL_HIRC_EN_Msk);
CLK_WaitClockReady( CLK_CLKSTATUS_HIRC_STB_Msk);
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC,CLK_HCLK_CLK_DIVIDER(1));
CLK_EnableModuleClock(UART0_MODULE);
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HIRC, CLK_UART_CLK_DIVIDER(1));
SystemCoreClockUpdate();
SYS->PA_H_MFP &= ~(SYS_PA_H_MFP_PA14_MFP_Msk|SYS_PA_H_MFP_PA15_MFP_Msk);
SYS->PA_H_MFP |= (SYS_PA_H_MFP_PA14_MFP_UART0_RX|SYS_PA_H_MFP_PA15_MFP_UART0_TX);
SYS_LockReg();
}
int main(void)
{
SYS_Init();
UART_Open(UART0, 115200);
while(1)
{
if(PE1==0)
{
CLK_SysTickDelay(100);
if(PE1==0)
{
;
}
while(PE1==0);
dataflash_test();
}
if(PE0==0)
{
CLK_SysTickDelay(100);
if(PE0==0)
{
;
}
while(PE0==0);
dataflash_test_read();
}
if(PE2==0)
{
CLK_SysTickDelay(100);
if(PE2==0)
{
;
}
while(PE2==0);
NVIC_SystemReset();
}
}
}
|