前一段时间出差,就把STM32放在家里做测试,程序运行在RAM上,并且另外有一个单片机监视是否出问题,如果出问题还可以重新下程序给这个STM32,我的测试代码也比较简单,就是每个Page都写一下.
#include "stm32f0xx.h" #define FLASH_PAGE_SIZE ((uint32_t)0x00000400) /* FLASH Page Size */ #define FLASH_USER_START_ADDR ((uint32_t)0x08000000) /* Start @ of user Flash area */ #define FLASH_USER_END_ADDR ((uint32_t)0x08004000) /* End @ of user Flash area */ uint32_t EraseCounter = 0x00, Address = 0x00; uint32_t NbrOfPage = 0x00; __IO FLASH_Status FLASHStatus = FLASH_COMPLETE; void Flash_Test(uint32_t Data) { FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPERR); NbrOfPage = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE; for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) { FLASH_ErasePage(FLASH_USER_START_ADDR + (FLASH_PAGE_SIZE * EraseCounter)); } Address = FLASH_USER_START_ADDR; while (Address < FLASH_USER_END_ADDR) { FLASH_ProgramWord(Address, Data); Address = Address + 4; } FLASH_Lock(); Address = FLASH_USER_START_ADDR; while (Address < FLASH_USER_END_ADDR) { Data = *(__IO uint32_t *)Address; Address = Address + 4; } } void GPIO_PB_Conf() { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_1); } int main(void) { GPIO_PB_Conf(); if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET) { GPIO_SetBits(GPIOB, GPIO_Pin_1); RCC_ClearFlag(); } else { GPIO_ResetBits(GPIOB, GPIO_Pin_1); } RCC_LSICmd(ENABLE); while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); IWDG_SetPrescaler(IWDG_Prescaler_256); IWDG_SetReload(0x07FF); IWDG_ReloadCounter(); IWDG_Enable(); while (1) { Flash_Test(0x12345678); IWDG_ReloadCounter(); Flash_Test(0x87654321); IWDG_ReloadCounter(); Flash_Test(0xFFFFFFFF); IWDG_ReloadCounter(); Flash_Test(0x00000000); IWDG_ReloadCounter(); } }
发现过了半个月,芯片只出现了局部损坏,如图:
在完整擦除过程如下:
20:27:12 : Flash page 0 @0x08000000 erased. 20:27:12 : Flash page 1 @0x08000400 erased. 20:27:17 : Flash page 0 @0x08000000 erased. 20:27:18 : Flash page 1 @0x08000400 erased. 20:27:18 : Flash page 2 @0x08000800 is not erased. Verify the memory protection. 20:27:18 : Flash page 3 @0x08000C00 erased. 20:27:18 : Flash page 4 @0x08001000 erased. 20:27:18 : Flash page 5 @0x08001400 erased. 20:27:18 : Flash page 6 @0x08001800 erased. 20:27:18 : Flash page 7 @0x08001C00 erased. 20:27:18 : Flash page 8 @0x08002000 erased. 20:27:18 : Flash page 9 @0x08002400 erased. 20:27:18 : Flash page 10 @0x08002800 erased. 20:27:18 : Flash page 11 @0x08002C00 erased. 20:27:18 : Flash page 12 @0x08003000 erased. 20:27:18 : Flash page 13 @0x08003400 is not erased. Verify the memory protection. 20:27:19 : Flash page 14 @0x08003800 is not erased. Verify the memory protection. 20:27:19 : Flash page 15 @0x08003C00 erased. 20:27:19 : Flash page 16 @0x08004000 erased. 20:27:19 : Flash page 17 @0x08004400 erased. 20:27:19 : Flash page 18 @0x08004800 erased. 20:27:19 : Flash page 19 @0x08004C00 erased. 20:27:19 : Flash page 20 @0x08005000 erased. 20:27:19 : Flash page 21 @0x08005400 erased. 20:27:19 : Flash page 22 @0x08005800 erased. 20:27:19 : Flash page 23 @0x08005C00 erased. 20:27:19 : Flash page 24 @0x08006000 erased. 20:27:19 : Flash page 25 @0x08006400 erased. 20:27:20 : Flash page 26 @0x08006800 erased. 20:27:20 : Flash page 27 @0x08006C00 erased. 20:27:20 : Flash page 28 @0x08007000 erased. 20:27:20 : Flash page 29 @0x08007400 erased. 20:27:20 : Flash page 30 @0x08007800 erased. 20:27:20 : Flash page 31 @0x08007C00 erased.
发现只坏了3个区,按照比较少的计算,我出差了15天,再根据实测的擦写正片编程时间约900ms算,约每个片区编程了1440000,只有三个坏掉了,所以保守估计十多万次是有的,所以,大家编程根本不用担心Flash寿命.何况这是F0,据说F4寿命是10倍耶,那么说这次出差回来都死不掉...