/*
正点原子STM32F407最小系统板
STM32F407ZGT6
168MHz
Flash size 1024Kbytes
RAM size 192KB
*/
include "main.h"
include <string.h>
include "systick.h"
include "led.h"
include "key.h"
include "timer2.h"
include "usart1.h"
include "stm_flash.h"
/*
设置 FLASH 保存地址(必须为偶数,且所在扇区,要大于本代码所占用到的扇区.否则,
写操作的时候,可能会导致擦除整个扇区,从而引起部分程序丢失.引起死机.
*/
//0xC000 = 49152 = 49152/1024 = 48kb
define STM_FLASH_START_ADDR 0X0800C000 //扇区3 0x0800 C000 - 0x0800 FFFF
uint32_t w_data[3];
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
sys_tick_init();
timer2_init();
usart1_init(115200);
led_init();
key_init();
uint8_t test2_data = 65;
w_data[0] = 0x01;
w_data[1] = test2_data;
w_data[2] = 0x03;
while (1)
{
int8_t ret = 0;
KEY_PRESSED_FLAG[0] = 0;
KEY_PRESSED_FLAG[1] = 0;
key_scan();
if(KEY_PRESSED_FLAG[0] == 1)
{
//写入
uint32_t write_data[2];
write_data[0]=0x11121314;
write_data[1]=0x21222324;
ret = stm_flash_write(STM_FLASH_START_ADDR,w_data,3);
KEY_PRESSED_FLAG[0] = 0;
delay_ms(50);
printf("stm_flash_write finsh! %d \n",ret);
delay_ms(100);
}
else if(KEY_PRESSED_FLAG[1] == 1)
{
//读取
uint32_t read_data[1];
stm_flash_read(STM_FLASH_START_ADDR+4,read_data,1);
uint8_t test_data = read_data[0]&0xff;
double d_data1 = (double)test_data/100;
KEY_PRESSED_FLAG[1] = 0;
printf("stm_flash_read:%d\r\n",test_data);
printf("stm_flash_read:%f\r\n",d_data1);
//printf("stm_flash_read:%8X\r\n",read_data[0]);
delay_ms(100);
}
delay_ms(100);
}
}
标签:read,stm,flash,PRESSED,测试,include,data From: https://www.cnblogs.com/ike_li/p/18345992