| | |
| | | * @param Size: The image size,the units of Size is Byte |
| | | * @retval The number of pages or error |
| | | */ |
| | | unsigned short int STMFLASH_ReadHalfWord(unsigned int faddr) |
| | | { |
| | | return *(volatile unsigned short int*)faddr; |
| | | } |
| | | uint32_t FLASH_Pages_Calculate(uint32_t Size) |
| | | { |
| | | uint32_t Flash_Page_Number = 0; |
| | |
| | | * @retval 0:error; 1:success |
| | | */ |
| | | |
| | | |
| | | extern uint16_t testflag; |
| | | uint32_t FLASH_Prepare(uint32_t Address, uint32_t Len) //起始地址和字长 |
| | | {uint32_t PageError = 0; |
| | | FLASH_EraseInitTypeDef EraseInitStruct; |
| | |
| | | // HAL_FLASH_Lock(); |
| | | if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK) |
| | | { |
| | | testflag=1; |
| | | HAL_FLASH_Lock(); |
| | | return 0; |
| | | }else{ |
| | | testflag=0; |
| | | HAL_FLASH_Lock(); |
| | | return 1; |
| | | } |
| | |
| | | * @retval 0:error ; 1:success |
| | | */ |
| | | #define DATA_32 ((uint32_t)0x12345678) |
| | | uint16_t test111; |
| | | uint32_t FLASH_Write( uint32_t Address, const uint8_t* pData, uint32_t Len) |
| | | { |
| | | uint32_t WriteCount = 0,temp; |
| | |
| | | for( ; WriteCount < Len; WriteCount+=4) |
| | | {temp=*(uint32_t*)FlashSource; |
| | | FLASHStatus = HAL_FLASH_Program(FLASH_TYPEPROGRAMDATA_WORD, FlashDestination, temp); |
| | | |
| | | test111=FLASHStatus; |
| | | if( FLASHStatus != HAL_OK) |
| | | { |
| | | break; |