查看keil帮助手册
安装keil后,可以在帮助中查看手册,也可以在浏览器中输入:
https://arm-software.github.io/CMSIS_5/Pack/html/flashAlgorithm.html
如果网页打开失败,可以试试在C:\Windows\System32\drivers\etc\hosts中添加185.199.109.153 arm-software.github.io然后保存退出,最后在cmd命令窗口执行ipconfig /flushdns,然后再打开
打开界面如下:
我们根据这个帮助来进行下载算法的工程创建,并且安装帮助文档的提示,我们需要实现 Init,UnInit,EraseSector和ProgramPage,EraseChip这几个函数,在实际操作过程中发现,还必须实现BlankCheck和Verify这两个函数,否则下载程序时,会提示超时而下载失败
Keil工程搭建
工程修改这里就不说了,玩过STM32的人,没几个不熟悉keil这个软件,按照帮助文档复制一个过来就好了,魔术棒下的设置都是设置好了的,不用修改。
FlashDev中调整设备参数
我开发板用的是一颗W25Q64
设置的参数如下:
参数后面的英文注释很好理解,但是要说一说 Device Name这个参数,这个名字跟最后显示keil里面的算法名字有关,而跟keil工程输出文件名称无关
FlashPrg中的编程算法
/**************************************************************************//**
* @file FlashPrg.c
* @brief Flash Programming Functions adapted for New Device Flash
* @version V1.0.0
* @date 10. January 2018
******************************************************************************/
/*
* Copyright (c) 2010-2018 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "FlashOS.h" // FlashOS Structures
#include "sys.h"
#include "delay.h"
#include "led.h"
#include "usart.h"