小弟从网上找的例程是F103的 我用的是F107VCT6,看了半天代码,自己又找了一个103做实验,103调通了,可是107失败了,程序没变,请问还有哪些地方需要更改一下,下面附上flash.c,二楼放MAIN.c //从指定地址开始读取多个数据 void FLASH_ReadMoreData(uint32_t startAddress,uint16_t *readData,uint16_t countToRead) { uint16_t dataIndex; for(dataIndex=0;dataIndex<countToRead;dataIndex++) { readData[dataIndex]=FLASH_ReadHalfWord(startAddress+dataIndex*2); } } //读取指定地址的半字(16位数据) uint16_t FLASH_ReadHalfWord(uint32_t address) { return*(__IO uint16_t*)address; } //读取指定地址的全字(32位数据) uint32_t FLASH_ReadWord(uint32_t address) { uint32_t temp1,temp2; temp1=*(__IO uint16_t*)address; temp2=*(__IO uint16_t*)(address+2); return(temp2<<16)+temp1; } //从指定地址开始写入多个数据 void FLASH_WriteMoreData(uint32_t startAddress,uint16_t *writeData,uint16_t countToWrite) { if(startAddress<FLASH_BASE||((startAddress+countToWrite*2)>=(FLASH_BASE+1024*FLASH_SIZE))) { return;//非法地址 } FLASH_Unlock(); //解锁写保护 uint32_t offsetAddress=startAddress-FLASH_BASE; //计算去掉0X08000000后的实际偏移地址 uint32_t sectorPosition=offsetAddress/SECTOR_SIZE; //计算扇区地址,对于STM32F103VET6为0~255 uint32_t sectorStartAddress=sectorPosition*SECTOR_SIZE+FLASH_BASE; //对应扇区的首地址 FLASH_ErasePage(sectorStartAddress);//擦除这个扇区 uint16_t dataIndex; for(dataIndex=0;dataIndex<countToWrite;dataIndex++) { FLASH_ProgramHalfWord(startAddress+dataIndex*2,writeData[dataIndex]); } FLASH_Lock();//上锁写保护 } |
//从指定地址开始读取多个数据
void FLASH_ReadMoreData(uint32_t startAddress,uint16_t *readData,uint16_t countToRead)
{
uint16_t dataIndex;
for(dataIndex=0;dataIndex<countToRead;dataIndex++)
{
readData[dataIndex]=FLASH_ReadHalfWord(startAddress+dataIndex*2);
}
}
//读取指定地址的半字(16位数据)
uint16_t FLASH_ReadHalfWord(uint32_t address)
{
return*(__IO uint16_t*)address;
}
//读取指定地址的全字(32位数据)
uint32_t FLASH_ReadWord(uint32_t address)
{
uint32_t temp1,temp2;
temp1=*(__IO uint16_t*)address;
temp2=*(__IO uint16_t*)(address+2);
return(temp2<<16)+temp1;
}
//从指定地址开始写入多个数据
void FLASH_WriteMoreData(uint32_t startAddress,uint16_t *writeData,uint16_t countToWrite)
{
if(startAddress<FLASH_BASE||((startAddress+countToWrite*2)>=(FLASH_BASE+1024*FLASH_SIZE)))
{
return;//非法地址
}
FLASH_Unlock(); //解锁写保护
uint32_t offsetAddress=startAddress-FLASH_BASE; //计算去掉0X08000000后的实际偏移地址
uint32_t sectorPosition=offsetAddress/SECTOR_SIZE; //计算扇区地址,对于STM32F103VET6为0~255
uint32_t sectorStartAddress=sectorPosition*SECTOR_SIZE+FLASH_BASE; //对应扇区的首地址
FLASH_ErasePage(sectorStartAddress);//擦除这个扇区
uint16_t dataIndex;
for(dataIndex=0;dataIndex<countToWrite;dataIndex++)
{
FLASH_ProgramHalfWord(startAddress+dataIndex*2,writeData[dataIndex]);
}
FLASH_Lock();//上锁写保护
}
int yeshu2=59;
uint16_t WriteToFlash1[]={1,2,3,4};
uint16_t WriteToFlash2[]={5,6,7,8};
uint16_t xianshi[5]={0,0,0,0,0};
uint16_t Flash1=0;
uint16_t Flash2=0;
uint16_t Flash3=0;
uint16_t Flash4=0;
int main(void)
{
uart_init(115200);
lcd12864_config();
SPI_GPIO_2_Init();
RS_485_TX_EN;
Disp_logo();
WriteIns(0x01);
FLASH_WriteMoreData(yeshu1*SECTOR_SIZE+USER_FLASH_START_ADDR,WriteToFlash1,4);
USART_SendData(UART5,'a');
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);//等待发送结束
FLASH_WriteMoreData(yeshu2*SECTOR_SIZE+USER_FLASH_START_ADDR,WriteToFlash2,4);
USART_SendData(UART5,'b');
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);//等待发送结束
FLASH_ReadMoreData(yeshu2*SECTOR_SIZE+USER_FLASH_START_ADDR,xianshi,4);
USART_SendData(UART5,'c');
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);//等待发送结束
Flash1= FLASH_ReadHalfWord(yeshu1*SECTOR_SIZE+USER_FLASH_START_ADDR);
USART_SendData(UART5,Flash1);
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);//等待发送结束
Flash2= FLASH_ReadHalfWord(yeshu1*SECTOR_SIZE+USER_FLASH_START_ADDR+2);
USART_SendData(UART5,'e');
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);//等待发送结束
Flash3= FLASH_ReadHalfWord(yeshu1*SECTOR_SIZE+USER_FLASH_START_ADDR+4);
USART_SendData(UART5,'f');
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);//等待发送结束
Flash4= FLASH_ReadHalfWord(yeshu1*SECTOR_SIZE+USER_FLASH_START_ADDR+6);
USART_SendData(UART5,'g');
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);//等待发送结束
Disp_Digital(Flash1 ,0x80);
Disp_Digital(Flash2 ,0x90);
Disp_Digital(Flash3 ,0x88);
Disp_Digital(Flash4 ,0x98);