手把手教你制作TouchGFX的SPI_FLASH下载算法

手把手教你制作TouchGFX的SPI_FLASH下载算法

1、找到Keil的官方SPI Flash下载算法路径进行修改

C:\keil5\ARM\Flash\_Template\NewDevice.uvprojx

手把手教你制作TouchGFX的SPI_FLASH下载算法_第1张图片
2、选择自己的板子的芯片
手把手教你制作TouchGFX的SPI_FLASH下载算法_第2张图片
3、拷贝出正点原子的HARDWARE文件夹下的SPI和W25QXX驱动,和SYSTEM文件夹中的文件到本工程中。
手把手教你制作TouchGFX的SPI_FLASH下载算法_第3张图片
4、添加相关头文件路径
手把手教你制作TouchGFX的SPI_FLASH下载算法_第4张图片
5、添加相关驱动文件
手把手教你制作TouchGFX的SPI_FLASH下载算法_第5张图片
6、修改FlashDev.c代码

#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
};

7、修改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拷贝到…\Keil_v5\ARM\Flash目录
工程编译完成后在C:\keil5\ARM\Flash_Template的目录下把STM32F429_W25QXX.FLM拷贝到C:\keil5\ARM\Flash的目录中
即可在Keil中添加调用了

###本文参考了KK大佬的文章
https://blog.csdn.net/sinat_31039061/article/details/107220994

你可能感兴趣的:(Touch,GFX,stm32,单片机)