152 lines
4.9 KiB
C
152 lines
4.9 KiB
C
/**************************************************************************//**
|
||
* @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 "w25qxx.h"
|
||
#include "spi.h"
|
||
#include "usart.h"
|
||
|
||
#define PAGE_SIZE 4096
|
||
/*
|
||
Mandatory Flash Programming Functions (Called by FlashOS):
|
||
int Init (unsigned long adr, // Initialize Flash
|
||
unsigned long clk,
|
||
unsigned long fnc);
|
||
int UnInit (unsigned long fnc); // De-initialize Flash
|
||
int EraseSector (unsigned long adr); // Erase Sector Function
|
||
int ProgramPage (unsigned long adr, // Program Page Function
|
||
unsigned long sz,
|
||
unsigned char *buf);
|
||
|
||
Optional Flash Programming Functions (Called by FlashOS):
|
||
int BlankCheck (unsigned long adr, // Blank Check
|
||
unsigned long sz,
|
||
unsigned char pat);
|
||
int EraseChip (void); // Erase complete Device
|
||
unsigned long Verify (unsigned long adr, // Verify Function
|
||
unsigned long sz,
|
||
unsigned char *buf);
|
||
|
||
- BlanckCheck is necessary if Flash space is not mapped into CPU memory space
|
||
- Verify is necessary if Flash space is not mapped into CPU memory space
|
||
- if EraseChip is not provided than EraseSector for all sectors is called
|
||
*/
|
||
|
||
|
||
/*
|
||
* Initialize Flash Programming Functions
|
||
* Parameter: adr: Device Base Address
|
||
* clk: Clock Frequency (Hz)
|
||
* fnc: Function Code (1 - Erase, 2 - Program, 3 - Verify)
|
||
* Return Value: 0 - OK, 1 - Failed
|
||
*/
|
||
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);//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>,180Mhz
|
||
delay_init(180); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||
//uart_init(90,115200); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>Ϊ115200
|
||
W25QXX_Init(); //W25QXX<58><58>ʼ<EFBFBD><CABC>
|
||
return (0); // Finished without Errors
|
||
}
|
||
|
||
|
||
/*
|
||
* De-Initialize Flash Programming Functions
|
||
* Parameter: fnc: Function Code (1 - Erase, 2 - Program, 3 - Verify)
|
||
* Return Value: 0 - OK, 1 - Failed
|
||
*/
|
||
|
||
int UnInit (unsigned long fnc) {
|
||
|
||
/* Add your Code */
|
||
return (0); // Finished without Errors
|
||
}
|
||
|
||
|
||
/*
|
||
* Erase complete Flash Memory
|
||
* Return Value: 0 - OK, 1 - Failed
|
||
*/
|
||
|
||
int EraseChip (void) {
|
||
|
||
/* Add your Code */
|
||
W25QXX_Erase_Chip();
|
||
return (0); // Finished without Errors
|
||
}
|
||
|
||
|
||
/*
|
||
* Erase Sector in Flash Memory
|
||
* Parameter: adr: Sector Address
|
||
* Return Value: 0 - OK, 1 - Failed
|
||
*/
|
||
|
||
int EraseSector (unsigned long adr) {
|
||
|
||
/* Add your Code */
|
||
W25QXX_Erase_Sector((adr-base_adr)/4096);
|
||
return (0); // Finished without Errors
|
||
}
|
||
|
||
|
||
/*
|
||
* Program Page in Flash Memory
|
||
* Parameter: adr: Page Start Address
|
||
* sz: Page Size
|
||
* buf: Page Data
|
||
* Return Value: 0 - OK, 1 - Failed
|
||
*/
|
||
|
||
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
|
||
}
|
||
/*
|
||
* Blank Check Checks if Memory is Blank
|
||
* Parameter: adr: Block Start Address
|
||
* sz: Block Size (in bytes)
|
||
* pat: Block Pattern
|
||
* Return Value: 0 - OK, 1 - Failed
|
||
*/
|
||
|
||
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;//ֱ<>ӷ<EFBFBD><D3B7><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>ʾ<EFBFBD>ɹ<EFBFBD>
|
||
}
|
||
|