| |||
| Home > Programming Flash with RealView Debugger > Creating algorithms for a Flash type not provided with RealView Debugger | |||
If your target uses a Flash device that cannot be programmed using the Flash algorithms provided with RealView Debugger, you must provide your own Flash programming code. To do this:
Create a C source file containing the Flash-specific C functions (see Example 5.2).
For example, you might provide these functions in a file myflash_sst.c.
Create the following files:
flash.h (see Example 5.3).
This is a C header file containing prototypes for the functions called by RealView Debugger.
rvd2apcs.s (see Example 5.4).
This is an assembly wrapper that acts as an interface between the RealView Debugger API and your Flash programming code.
The files rvd2apcs.s and flash.h are
also available in Application Note 110 Flash Programming
with RealView Debugger, which can be found from the Documentation
link on the ARM web site http://www.arm.com.
This code is designed to be linked to reside in a contiguous area of RAM on your target. Therefore, you must only specify an RO base in the linker options. See the RealView Compilation Tools Linker and Utilities Guide for more details on the RO base option.
This does not have to be free scratch memory. By default, RealView Debugger saves the contents of affected RAM and restores it after the Flash operation has completed.
Example 5.2. myflash.c
#include "flash.h"
/******************************
* Initialise the Flash device
******************************/
UINT32 RVDFlash_Init(UINT32 base_of_flash)
{
// Place your initialization code here
return 0; // success
}
/******************************
* Erase the Flash memory
******************************/
UINT32 RVDFLASH_Erase(UINT32 base_address,
UINT32 block_count,
UINT32 block_size)
{
// Place your flash erase code here
return 0; // success
}
/******************************
* Write to the Flash memory
******************************/
UINT32 RVDFLASH_Write(UINT32 base_address,
UINT32 byte_count,
UINT32 block_offset,
UINT32 from_buffer,
UINT32 verify)
{
// Place your flash write code here
return 0; // success
}
/******************************
* Validate the Flash memory
******************************/
UINT32 RVDFLASH_Validate(UINT32 base_address,
UINT32 byte_count,
UINT32 block_offset,
UINT32 from_buffer)
{
// Place your flash validate code here
return 0; // success
}
Example 5.3. flash.h
/**********************************************************************
* Flash.h
* Contains function prototypes for flash specific functions
* 27/3/2003 ARM Ltd.
* Revision: A
* Date: 21/03/2003
**********************************************************************/
typedef unsigned long int UINT32;
UINT32 RVDFlash_Init(UINT32 base_of_flash);
UINT32 RVDFLASH_Erase(UINT32 base_address,
UINT32 block_count,
UINT32 block_size);
UINT32 RVDFLASH_Write(UINT32 base_address,
UINT32 byte_count,
UINT32 block_offset,
UINT32 from_buffer,
UINT32 verify);
UINT32 RVDFLASH_Validate(UINT32 base_address,
UINT32 byte_count,
UINT32 block_offset,
UINT32 from_buffer);
/**********************************************************************
* base_of_flash: base memory address of flash device
* base_address: base memory address of first flash block
* block size: size of a single flash block in bytes
* block count: number of flash blocks
* byte_count: number of bytes to read/write
* block_offset: offset into block (in bytes) to start read/write at
* from_buffer: address of buffer to copy from
* verify: 0 if no verify requested, else same value as byte_count
* return 0=OK, else error.
**********************************************************************/
Example 5.4. rvd2apcs.s
;*************************************************************************
; RVD2APCS
; This code is intended as an Interface between the RVD API and your flash
; algorithm code.
;
; 27/3/2003 ARM Ltd.
; Revision: A
; Date: 21/03/2003
;*************************************************************************
; You must provide flash specific implementations of the exported functions
;
; Please refer to the prototypes for these functions provided in the header
; file flash.h
; The code below ensures the correct information provided by RVD is passed
; to your functions using the normal ATPCS registers.
; After calling each of these functions RVD will halt the processor and
; return control to the host by placing a breakpoint at the label
; FLASH_break
;*************************************************************************
EXPORT FLASH_init
EXPORT FLASH_erase
EXPORT FLASH_write
EXPORT FLASH_validate
EXPORT FLASH_break
AREA FLASH, CODE, READONLY
;*************************************************************************
; FLASH_init - Initialise any board specific memory access controls, etc.
;*************************************************************************
CODE32
PRESERVE8
ENTRY
FLASH_init
IMPORT RVDFlash_Init
LDR sp, =stacktop
MOV r0, r1 ; base memory address of flash device
BL RVDFlash_Init ; branch to customer function
B FLASH_break ; return
;*************************************************************************
; FLASH_erase - erase a Flash block(s)
;*************************************************************************
FLASH_erase
IMPORT RVDFLASH_Erase ; i is in r0
LDR sp, =stacktop
; STR lr, [sp, #-4]! ; preserve lr
MOV r0, r1 ; base memory address of first flash block
MOV r1, r2 ; number of flash blocks
MOV r2, r3 ; size of a single flash block in bytes
BL RVDFLASH_Erase ; branch to customer function
B FLASH_break ; return
;*************************************************************************
; FLASH_write - write data to a Flash block
;*************************************************************************
FLASH_write
IMPORT RVDFLASH_Write ; write with image
LDR sp, =stacktop
MOV r0, r1 ; base memory address of first flash block
MOV r1, r2 ; number of bytes to read/write
MOV r2, r4 ; offset into block (in bytes) to start read/write at
MOV r3, r5 ; address of buffer
STR r9, [sp, #-4]! ; verify flag
BL RVDFLASH_Write ; branch to customer function
B FLASH_break ; return
;*************************************************************************
; FLASH_validate - validate a write to a Flash block
;*************************************************************************
FLASH_validate
IMPORT RVDFLASH_Validate ; i is in r0
LDR sp, =stacktop
MOV r0, r1 ; base memory address of first flash block
MOV r1, r2 ; number of bytes to read/write
MOV r2, r4 ; offset into block (in bytes) to start read/write at
MOV r3, r5 ; address of buffer
BL RVDFLASH_Validate ; branch to customer function
B FLASH_break ; return
;*************************************************************************
; FLASH_break - end of function entry for all Flash routines *
;*************************************************************************
FLASH_break
nop
forever
b forever ; should never be reached.
;*************************************************************************
;* DEFINE BUFFER FOR WRITE/VERIFY and STACK
;*************************************************************************
AREA BUFFER, NOINIT
buffer % 1024 ; buffer for copying
AREA STACK, NOINIT
stackbottom
% 512
stacktop
% 4
END