STM32F0 Flash Read and write

Source: Internet
Author: User

Flash size 64k rom+8k RAM size, stm32f051 has 64k ROM, the total is divided into 64 pages, a page 1024byte, in the Flash Rom write data power-down save, equivalent to W25q80

uint32_t flash_start_addr = 0x08000000+1024*63; 10,241-page size 1k, 64K Flash has the last page at the beginning of the first address to write
/*****************************************************************************
function: Flash Write

Input: Addr: Write address 0-one page size data:4 byte data

return: None
******************************************************************************/
void Writeflash (uint32_t addr,uint32_t data)
{
Flash_unlock (); ½âëøflash±à³ì²á³ý¿øöææ÷
Flash_clearflag (flash_flag_bsy| flash_flag_eop| flash_flag_pgerr| FLASH_FLAG_WRPERR);//çå³ý±êö¾î»
Flash_erasepage (FLASH_START_ADDR); ²á³ýö¸¶¨µøö ò³
Flash_programword (flash_start_addr+ (addr*4), data); ´óö¸¶¨ò³µä0µøö ¿ªê¼ð´
Flash_clearflag (flash_flag_bsy| flash_flag_eop| flash_flag_pgerr| FLASH_FLAG_WRPERR);//çå³ý±êö¾î»
Flash_lock (); Ëø¶¨flash±à³ì²á³ý¿øöææ÷
}

/*****************************************************************************
function: Read Flash

Input: Read address

Return: Read 4 bytes of data
******************************************************************************/
uint32_t Readflash (uint16_t addr)
{
uint32_t value;
Value = * (uint32_t*) (flash_start_addr+ (addr*4));
return value;
}

STM32F0 Flash Read and write

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.