历史上的今天
今天是:2025年07月26日(星期六)
2019年07月26日 | STM32 flash读写源程序
2019-07-26 来源:eefocus
/**
******************************************************************************
* File Name : FLASH.c
* Description : read and program the stm32's flash from address
* Author : Yelsin
* Version : V1.0.0
* Date : 11-Jan-2015
* COPYRIGHT(c) 2015. All Right Reserved
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "flash.h"
#include "main.h"
/* Private define ------------------------------------------------------------*/
#define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_60 /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR ADDR_FLASH_PAGE_61 + FLASH_PAGE_SIZE /* End @ of user Flash area */
#define DATA_32 ((uint32_t)0x12345678)
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint32_t Address = 0, PageError = 0;
__IO uint32_t data32 = 0 , MemoryProgramStatus = 0;
/*Variable used for Erase procedure*/
static FLASH_EraseInitTypeDef EraseInitStruct;
/* Private function prototypes -----------------------------------------------*/
//static void Error_Handler(void);
/* Private functions ---------------------------------------------------------*/
/*Read halfword-16 bit data from flash address */
uint16_t FLASH_ReadHalfWord(uint32_t address)
{
return *(__IO uint16_t*)address;
}
/*Read WORD-32 bit data from flash address */
uint32_t FLASH_ReadWord(uint32_t address)
{
uint32_t temp1,temp2;
temp1=*(__IO uint16_t*)address;
temp2=*(__IO uint16_t*)(address+2);
return (temp2<<16)+temp1;
}
/*Read Multi half-WORD 16 bit data from flash address */
void FLASH_ReadMoreData(uint32_t startAddress,uint16_t *readData,uint16_t countToRead)
{
uint16_t dataIndex;
for(dataIndex=0;dataIndex readData[dataIndex]=FLASH_ReadHalfWord(startAddress+dataIndex*2); } } /** * @brief Factory Setting Recover Read Flash after power on * @param start Addr * @retval None */ void FactorySettingRecover(void) { uint8_t i; Address = FLASH_USER_START_ADDR; for (i=0; i GLOBALVARS[i]= FLASH_ReadWord(Address ); Address = Address + 4; } if(GLOBALVARS[PARAM_MODIFIED] == 0x55) { fDVBType = GLOBALVARS[DVBTYPE] ; fRFBandwidth = GLOBALVARS[BANDWITH] ; } } /** * @brief Flash write function * @param start area address * @retval None */ void FLASH_Write(uint32_t WriteAddr,uint32_t *Buffer,uint16_t NumberToWrite) { uint8_t i; /* Unlock the Flash to enable the flash control register access *************/ HAL_FLASH_Unlock(); /* Erase the user Flash area (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/ /* Fill EraseInit structure*/ EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; EraseInitStruct.PageAddress = FLASH_USER_START_ADDR; EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE; if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK) { /* Error occurred while page erase. to know the code error , call 'HAL_FLASH_GetError()' */ } for (i=0; i if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, WriteAddr, Buffer[i]) == HAL_OK) { WriteAddr = WriteAddr + 4; } else { /* Error occurred while writing data in Flash */ } } /* Lock the Flash to disable the flash control register access (recommended to protect the FLASH memory against possible unwanted operation) *********/ HAL_FLASH_Lock(); /* Check if the programmed data is OK*/ /* Address = FLASH_USER_START_ADDR; MemoryProgramStatus = 0x0; while (Address < FLASH_USER_END_ADDR) { data32 = *(__IO uint32_t *)Address; if (data32 != DATA_32) { MemoryProgramStatus++; } Address = Address + 4; } if (MemoryProgramStatus == 0) { }*/ } /** * @brief Save Factory Setting In Flash * @param None * @retval None */ void SaveParameterInFlash(void) { GLOBALVARS[DVBTYPE] = fDVBType; GLOBALVARS[PARAM_MODIFIED] = 0x55; Address = FLASH_USER_START_ADDR; FLASH_Write(Address,GLOBALVARS,sizeof(GLOBALVARS)) ; } /** * @brief This function is executed in case of error occurrence. * @param None * @retval None */ /*static void Error_Handler(void) { { printf("n flash Err."); } }*/ #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %drn", file, line) */ /* Infinite loop */ //while (1) { } } #endif /** * @} */
史海拾趣
|
各位兄弟们帮帮忙啊,我想问下,在Tornado2.2.1 下面有没有对应的WindNet PPPOE组件?版本多少呢,谁有没有啊??… 查看全部问答> |
|
我在看vivi中的head.S 当程序bl copy_myself 结束之后, 为何执行下列代码后,P @ jump to ram ldr r1, =on_the_ram add pc ...… 查看全部问答> |
|
用汇编语言写代码时,可以通过将汇编指令的指令周期相加得到一段代码执行的时间。那如果用C语言写的代码,譬如调用一个子函数,我们有什么方法可以确定它的执行时间吗?请高手赐教!… 查看全部问答> |
|
上周,泰克参展2011年英特尔信息技术峰会(IDF)大会,介绍并现场演示其完善的测试测量系列工具,帮助设计工程师能够按期向市场上推出下一代产品。 在今年的IDF上,英特尔重点推介了USB3和PCIE3这两大技术主 ...… 查看全部问答> |
|
本帖最后由 caveguy 于 2014-3-18 10:31 编辑 基本还是全新的,买来就上过一次电,平时工作太忙,没时间学习了,出给需要的朋友吧。 买来也就一个多月,不到俩月,器件都是很新的。买时 1580 不包邮买的,现在 1300元不包邮出掉吧, 需要的联系 ...… 查看全部问答> |




