1、找到Keil的官方Flash下载算法路径进行修改
下载算法的模版在keil安装目录\ARM\Flash下的_Template文件夹,把此文件夹复制出来,进行修改。也可以自行修改此工程名。
C:\keil5\ARM\Flash\_Template\NewDevice.uvprojx
2、选择自己的板子的芯片
3、添加SPI和W25QXX驱动
添加W25QXX的驱动代码, 去正点原子的论坛下载STM32F29的寄存器工程,拷贝出HARDWARE文件夹下的SPI和W25QXX驱动,和SYSTEM文件夹。
4、添加相关驱动文件
5、修改FlashDev.c代码
修改FlashDev.c 中外部flash的大小
#include "../FlashOS.H" // FlashOS Structures
struct FlashDevice const FlashDevice = {
FLASH_DRV_VERS, // Driver Version, do not modify!
"STM32F429_W25QXX", // Device Name
EXTSPI,
0x90000000,// Device Start Address
0x01000000,// Device Size in Bytes (16M)
4096,// Programming Page Size
0, // Reserved, must be 0
0xFF, // Initial Content of Erased Memory
2000,// Program Page Timeout 2000 mSec
3000, // Erase Sector Timeout 3000 mSec
0x001000,0x000000,// Sector Size 4kB (4 Sectors)
SECTOR_END
};
6、修改FlashPrg.c代码
按照模版添加驱动代码
#include "../FlashOS.H" // FlashOS Structures
#include "sys.h"
#include "delay.h"
#include "w25qxx.h"
#include "spi1.h"
#include "usart.h"
#define PAGE_SIZE 4096
uint8_t aux_buf[PAGE_SIZE];
uint32_t base_adr;
int Init (unsigned long adr, unsigned long clk, unsigned long fnc) {
/* Add your Code */
Stm32_Clock_Init(360,25,2,8);//设置时钟,180Mhz
delay_init(180); //初始化延时函数
//uart_init(90,115200); //初始化串口波特率为115200
W25QXX_Init(); //W25QXX初始化
return (0); // Finished without Errors
}
int UnInit (unsigned long fnc) {
/* Add your Code */
return (0); // Finished without Errors
}
int EraseChip (void) {
/* Add your Code */
W25QXX_Erase_Chip();
return (0); // Finished without Errors
}
int EraseSector (unsigned long adr) {
/* Add your Code */
W25QXX_Erase_Sector((adr-base_adr)/4096);
return (0); // Finished without Errors
}
int ProgramPage (unsigned long adr, unsigned long sz, unsigned char *buf) {
/* Add your Code */
W25QXX_Write_NoCheck(buf,adr-base_adr,sz);
return (0); // Finished without Errors
}
int BlankCheck (unsigned long adr, unsigned long sz, unsigned char pat) {
return (1); /* Always Force Erase */
}
unsigned long Verify (unsigned long adr, // Verify Function
unsigned long sz,
unsigned char *buf)
{
return 0;//直接返回0,表示成功
}
8、编译后将xxx.FLM拷贝到C:\keil5\\Keil_v5\ARM\Flash
目录
工程编译完成后在C:\keil5\ARM\Flash_Template
的目录下把STM32F429_W25QXX.FLM拷贝到C:\keil5\ARM\Flash
的目录中
即可在Keil中添加调用了
代码下载
Github地址:https://gitee.com/Aladdin-Wang/hellotouchGFX.git