Oren Lavi

Access Error Exception

Discussion created by Oren Lavi on Jul 23, 2006
Latest reply on Dec 8, 2006 by Kyle Ludwig
Hello
I tried to write a sample code that just program 1 32bit data into flash.

I am working with the M52235EVB(25Mhz Crystal oscillator on board).
The lcf is:

MEMORY
{
flash (RX) : ORIGIN = 0x00000000, LENGTH = 0x00040000
    vectorram(RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000400
    sram    (RWX) : ORIGIN = 0x20000400, LENGTH = 0x00007C00
    ipsbar (RWX) : ORIGIN = 0x40000000, LENGTH = 0x0
}

The c initialize is:

MCF_CLOCK_SYNCR=0x4007;//Multiply By 12 (Divide By 5 Later),PLL Enable

MCF_CFM_CFMMCR=0;//No Lock,Interrupt Disable
    MCF_CFM_CFMCLKD=0x55;//Set Freq To About ~178Khz
    MCF_CFM_CFMPROT=0;//No Sector Is Protect
    MCF_CFM_CFMSACC=0xFFFFFFFF;//Flash Sectors Are Placed In Supervisor Address    
    MCF_CFM_CFMDACC=0;
MCF_CFM_CFMUSTAT = PVIOL | ACCERR;
The assembler code:

asm
{
    lea        EndProgByte,a1
    lea        ProgByte,a2
    sub.l    #2,a2
cont:    
    move.w    (a1),-(sp)//Save Line Of Prog Byte
    sub.l    #2,a1
    cmp.l    a1,a2
    bne        cont            
//After This Line ProgByte Func Is In The Ram
    move.l    a7,-(sp)//Save SP Pointer Value To SP
    rts//Jump To SP To Run Code
    
    
//Code To Copy To Ram
ProgByte:
    move.l    #0x2B70,a0
    move.l    #0x55aa,d0
    move.w    d0,(a0)
    move.l    #0x40000000,a0    
move.b #0x20,d0
add.l    #0x1D0024,a0//Offset Of CFMCMD        
EndProgByte:
    move.b d0,(a0)//Write To CFMCMD 0x20 (Program long 32bit)
}

When the PC is changing to the stack address and run the code from the stack in line (or in it's area) -->
move.w    d0,(a0)

i get Access Error Exception and the write to the flash fails.
Why is that?
Is the code order OK?
Is there simpler way to write to the CFMCMD?
In my code for start i assume that the address for prog is erase(0xffffffff) and that all the error flags are OK.


Thanks

Outcomes