在stm32xxx_hal_flash.h 或者 stm32xxx_hal_flash_ex.h 里面 #define FLASH_SIZE (uint32_t)((*((uint32_t *)FLASHSIZE_BASE)&0xFFFF) * 1024U) #define FLASH_PAGE_SIZE ((uint32_t)128U) /*!< FLASH Page Size in bytes */
1、FLASH的分区以及扇区大小 FLASH擦除是按照扇区擦的,所以这个很重要,在工程中全局搜索 FLASH_PAGE_SIZE 宏就可以查看该芯片的页(扇区)大小,改宏在 stm32xxx_hal_flash.h中有定义 2、FLASH擦拭后的状态 F1和F4系列的芯片FLASH在擦除后会是0xFFFFFFFF,而L1系列的芯片FLASH在擦除后是0x00000000!!! 3、FLASH...
对STM32 内部FLASH进行编程操作,需要遵循以下流程: FLASH解锁 清除相关标志位 擦除FLASH(先擦除后写入的原因是为了工业上制作方便,即物理实现方便) 写入FLASH 锁定FLASH 实例: #define FLASH_PAGE_SIZE ((uint16_t)0x400) //如果一页为1K大小 #define WRITE_START_ADDR ((uint32_t)0x08008000)//写入的起始...
volatile FLASH_Status FLASHStatus = FLASH_COMPLETE;/*FLASH擦除完成标志*/ void main() { /*解锁FLASH*/ FLASH_Unlock(); /*计算需要擦除FLASH页的个数 */ NbrOfPage = (WRITE_END_ADDR - WRITE_START_ADDR) / FLASH_PAGE_SIZE; /* 清除所有挂起标志位 */ FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH...
/* FLASH页大小:1K */ #define STM32FLASH_PAGE_SIZE FLASH_PAGE_SIZE /* FLASH总页数 */ #define STM32FLASH_PAGE_NUM (STM32FLASH_SIZE / STM32FLASH_PAGE_SIZE) /// 导出函数声明 void FLASH_Init(void); uint32_t FLASH_Read(uint32_t Address, void *Buffer, uint32_t Size); ...
spi_flash_pagewrite(pbuff,addr,num); } else //写入字节数大于1页 { //1.写入整页 while(numofpage--) { //调用函数,进行整页写入 spi_flash_pagewrite(pbuff,addr,pagesize); //参数修改 pbuff+=pagesize; addr+=pagesize; } //2.写入剩余字节数 ...
5 #define FLASH_PAGE_SIZE 256 //W25Q64每页256个字节 6 7 #define W25X_WriteEnable 0x06 8 #define W25X_WriteDisable 0x04 9 #define W25X_ReadStatusReg 0x05 10 #define W25X_WriteStatusReg 0x01 11 #define W25X_ReadData 0x03 12 #define W25X_FastReadData 0x0B ...
*/ page = (Addr - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE;} return page;} ...
51.Flash_Read(secpos,tmp,FLASH_PAGE_SIZE);//读出整个扇区 52.for(i=0;i//校验数据 53.if(tmp[secoff+i]!=0XFF)break;//需要擦除 54.} 55.if(i//需要擦除 56.FLASHStatus=FLASH_ErasePage(secpos);//擦除这个扇区 57.if(FLASHStatus!=FLASH_COMPLETE) ...
STMFLASH_Read(STM32_FLASH_BASE + sectornum * STM_SECTOR_SIZE, STMFLASH_BUF, STM_SECTOR_SIZE / 2); for(i=0; i<secremain; i++) { if(STMFLASH_BUF[secoff + i] != 0xFFFF) break; } if(i < secremain) { FLASH_PageErase(STM32_FLASH_BASE + sectornum * STM_SECTOR_SIZE); ...