关于stm32f030X8系列内部flash的读写

目录

1.flash内存的大小

2.flash写入的过程

3.flash读取的过程

4.链接


1.flash内存的大小

对于大多数FXXX8系列的芯片,flash的大小基本都是64k,且大容量的每页大小为2K,中小容量的每页大小为1K,当然具体的大小还是要看官方的数据手册以及参考手册。

2.flash写入的过程

(一)解锁顺序;

void FLASH_Unlock(void);//只有解锁了,内部FLASH才允许读写
/* (1) Wait till no operation is on going */
/* (2) Check that the flash memory is unlocked */
/* (3) Perform unlock sequence */
while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (1) */ 
{
 /* For robust implementation, add here time-out management */
} 
if ((FLASH->CR & FLASH_CR_LOCK) != 0) /* (2) */
{ 
 FLASH->KEYR = FLASH_FKEY1; /* (3) */
 FLASH->KEYR = FLASH_FKEY2;
}

(二)对flash除保留地址及代码存储地址之外的主闪存编程顺序;

FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
/* (1) Set the PG bit in the FLASH_CR register to enable programming */
/* (2) Perform the data write (half-word) at the desired address */
/* (3) Wait until the BSY bit is reset in the FLASH_SR register */
/* (4) Check the EOP flag in the FLASH_SR register */
/* (5) clear it by software by writing it at 1 */
/* (6) Reset the PG Bit to disable programming */
FLASH->CR |= FLASH_CR_PG; /* (1) */
*(__IO uint16_t*)(flash_addr) = data; /* (2) */
while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (3) */
{
/* For robust implementation, add here time-out management */
}
if ((FLASH->SR & FLASH_SR_EOP) != 0) /* (4) */
{
 FLASH->SR = FLASH_SR_EOP; /* (5) */
}
else
{
 /* Manage the error cases */ 
}
FLASH->CR &= ~FLASH_CR_PG; /* (6) */

(三)按页擦除的顺序;

FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
/* (1) Set the PER bit in the FLASH_CR register to enable page erasing */
/* (2) Program the FLASH_AR register to select a page to erase */
/* (3) Set the STRT bit in the FLASH_CR register to start the erasing */
/* (4) Wait until the BSY bit is reset in the FLASH_SR register */
/* (5) Check the EOP flag in the FLASH_SR register */
/* (6) Clear EOP flag by software by writing EOP at 1 */
/* (7) Reset the PER Bit to disable the page erase */
FLASH->CR |= FLASH_CR_PER; /* (1) */ 
FLASH->AR = page_addr; /* (2) */ 
FLASH->CR |= FLASH_CR_STRT; /* (3) */ 
while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (4) */
{
 /* For robust implementation, add here time-out management */
} 
if ((FLASH->SR & FLASH_SR_EOP) != 0) /* (5) */
{ 
 FLASH->SR = FLASH_SR_EOP; /* (6)*/
} 
else
{
 /* Manage the error cases */
}
FLASH->CR &= ~FLASH_CR_PER; /* (7) */

(四)上锁顺序;

/* (1) Set the LOCK Bit to lock the FLASH control register and program memory access */
void FLASH_Lock(void)
{
  FLASH->CR |= FLASH_CR_LOCK;
}

3.flash读取的过程

uint32_t data;//用于读取flash的数据
uint32_t address;//写入的地址
data=*(uint32_t*address);//将地址中的数值赋给data

4.链接

STMCU中文官网ADF4350 pdf, ADF4350 Download, ADF4350 Description, ADF4350 Datasheet, ADF4350 view ::: ALLDATASHEET :::

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值