初中生
最后登录1970-1-1
在线时间 小时
注册时间2016-8-14
|
楼主 |
发表于 2016-11-27 18:14:19
|
显示全部楼层
我觉得自己的软件没有问题,但是保险起见,我还是粘贴上来了
flash 内容用串口输出的代码如下
/**
******************************************************************************
* @file FLASH
* @author
* @version
* @date
* @brief 要求程序可对MCU的内部Flash页进行擦除,
可写入固定数量的数据,并可将写入的数据读出。
要求读出的数据与写入的数据内容必须一致。
擦除后,写,用串口输出flash数据
0x080000000 - 0x0800FFFF 64K flash
0x080800000 - 0x080107FF 2K EEPROM
1PAGE = 128 byte
1sector(0-15) = 32page (0-31)
7s可以完成写数据和读数据,校验数据
******************************************************************************
*/
#include "main.h"
#define FLASH_USER_START_ADDR 0x08008000 /* flash起始地址 */
#define FLASH_USER_END_ADDR 0x0800A000 /* flash终止地址 */
uint8_t DATA_32[] = "STM32LO53C8";
int i =0;
uint32_t FirstPage = 0, NbOfPages = 0, Address = 0;
uint32_t PageError = 0;
__IO uint32_t data32 = 0 , MemoryProgramStatus = 0;
static FLASH_EraseInitTypeDef EraseInitStruct;
UART_HandleTypeDef UartHandle;
__IO ITStatus UartReady = RESET;
uint8_t aTxBuffer[] = " THIS IS TRUE ";
uint32_t BUFFER_data;
uint8_t aRxBuffer[RXBUFFERSIZE];
static void SystemClock_Config(void);
static void Error_Handler(void);
void UART_INT(void);
int main(void)
{
HAL_Init();
BSP_LED_Init(LED3);
SystemClock_Config();
UART_INT();
HAL_FLASH_Unlock();
NbOfPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR + 1) >> 7;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.PageAddress = FLASH_USER_START_ADDR;
EraseInitStruct.NbPages = NbOfPages;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
{
Error_Handler();
}
Address = FLASH_USER_START_ADDR;
while (Address < FLASH_USER_END_ADDR)
{
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address , (uint32_t)DATA_32) == HAL_OK)
{
Address = Address + 4;
}
else
{
Error_Handler();
}
}
HAL_FLASH_Lock();
/* 变量 MemoryProgramStatus = 0: 数据正确
MemoryProgramStatus != 0: 数据错误 ******/
Address = FLASH_USER_START_ADDR;
MemoryProgramStatus = 0x0;
BUFFER_data= *(__IO uint32_t*)(0x8008000);
if(HAL_UART_Transmit_IT(&UartHandle, (uint8_t*)BUFFER_data, 11)!= HAL_OK)
{
Error_Handler();
}
while (Address < FLASH_USER_END_ADDR)
{
data32 = *(__IO uint32_t*)Address;
if (data32 != (uint32_t)DATA_32)
{
MemoryProgramStatus++;
}
Address = Address + 4;
}
if (MemoryProgramStatus == 0)
{
BSP_LED_On(LED3);
UART_INT();
if(HAL_UART_Transmit_IT(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
{
Error_Handler();
}
}
else
{
Error_Handler();
}
while (1)
{
}
} |
|