请问STM32写flash怎么总是写不进?

stm32 内部flash空间区域为:
0x8000000 ~ 0x8001000

我的页定义为:
#define PAGE_SIZE (uint16_t)0x400 / Page size = 1KByte /

#define EEPROM_START_ADDRESS ((uint32_t)0x0800f400)

/ Pages 0 and 1 base and end addresses /
#define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x000))
#define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))

#define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + PAGE_SIZE))
#define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))


初始化时, 去对页0写VALID_PAGE标志:

HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, PAGE0_BASE_ADDRESS, VALID_PAGE);

最终是调用下面接口, 在地址0x0800f400处写入VALID_PAGE,

static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
{
/ Clean the error context /
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;

/ Proceed to program the new data /
SET_BIT(FLASH->CR, FLASH_CR_PG);

/ Write data in the address /
]iAddress = Data; //////////////////这里, 写无效//////////////////////
}


请问为什么会写入无效呢??? 盼用的朋友能指点迷津, 谢谢!!!!!!!

已邀请:

勇敢的心

赞同来自:

要先去掉写保护才行

§MiCE§

赞同来自:

要先解锁:HAL_FLASH_Unlock();才能写。

要回复问题请先登录注册