6.8.4. Assembly wrapper

Example 6.4 shows a template for an assembly wrapper (rvd2apcs.s) that acts as an interface between the RealView Debugger API and your Flash programming code.

The rvd2apcs.s file is 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.

Example 6.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
Copyright © 2002-2007 ARM Limited. All rights reserved.ARM DUI 0182I
Non-Confidential