vvhhbc1 发表于 2015-11-19 09:44:14

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

本帖最后由 vvhhbc1 于 2015-11-22 21:45 编辑

stm32f030c8 内部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 */
*(__IO uint16_t*)Address = Data;   //////////////////这里, 写无效//////////////////////
}


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

chifen 发表于 2015-11-19 10:49:47

写内部 flash要先解锁,

Paderboy 发表于 2015-11-19 10:52:31

要先解锁,然后再擦除你要存储的区域。。。然后写入。再上锁。。。

发表于 2015-11-19 14:05:26

参考例程:
页: [1]
查看完整版本: 请问STM32写flash怎么总是写不进?