stm32读写内部flash---------------~
从固件库里修改了一个STM32读取内部FLASH的例程,用串口与电脑通讯,观察写入读出正常,但还有几个地方不太明白,请过来人指点。else语句中有一句Data--请问有什么用?
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#include "platform_config.h"
/* Private typedef -----------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
/* Private define ------------------------------------------------------------*/
#define StartAddr((u32)0x08008000)
#define EndAddr ((u32)0x08008009)
u32 *p=(u32 *)0x08008000;
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u32 EraseCounter = 0x00, Address = 0x00;
u32 Data;
vu32 NbrOfPage = 0x00;
volatile FLASH_Status FLASHStatus;
volatile TestStatus MemoryProgramStatus;
ErrorStatus HSEStartUpStatus;
/* Private function prototypes -----------------------------------------------*/
void NVIC_Configuration(void);
void RCC_Configuration(void);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name: main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
FLASHStatus = FLASH_COMPLETE;
MemoryProgramStatus = PASSED;
Data = 0x1111;
/* RCC Configuration */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
/* Unlock the Flash Program Erase controller */
FLASH_Unlock();
/* Define the number of page to be erased */
NbrOfPage = (EndAddr - StartAddr) / FLASH_PAGE_SIZE;
/* Clear All pending flags */
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
if((*(p+1)) != 0x1111)
{
/* Erase the FLASH pages */
for(EraseCounter = 0; (EraseCounter <= NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++)
{
FLASHStatus = FLASH_ErasePage(StartAddr + (FLASH_PAGE_SIZE * EraseCounter));
}
/*FLASH Word program of data 0x15041979 at addresses defined by StartAddr and EndAddr*/
Address = StartAddr;
while((Address < EndAddr) && (FLASHStatus == FLASH_COMPLETE))
{
FLASHStatus = FLASH_ProgramWord(Address, Data);
Address = Address + 4;
}
}
else
{
Data=*p;//before erase the Flash ,read out the data to Data
/* Erase the FLASH pages */
for(EraseCounter = 0; (EraseCounter <= NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++)
{
FLASHStatus = FLASH_ErasePage(StartAddr + (FLASH_PAGE_SIZE * EraseCounter));
}
Address = StartAddr;
while((Address < EndAddr) && (FLASHStatus == FLASH_COMPLETE))
{
FLASHStatus = FLASH_ProgramWord(Address, Data);
Data--;
Address = Address + 4;
}
}
while (1)
{
}
} 回复【楼主位】liu_jing_yang
-----------------------------------------------------------------------
我怎么没看出有读出啊?
页:
[1]