Access Error Exception

cancel
Showing results for 
Search instead for 
Did you mean: 

Access Error Exception

1,717 Views
UDP
Contributor I
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
Labels (1)
0 Kudos
2 Replies

169 Views
ericgregori
Contributor I
To program flash, use address 0x44020000
 
 
//*****************************************************************************
// FLASH Parameters
//*****************************************************************************
// Start address for region of flash available for web page upload
#define FLASH_START_ADDRESS     0x44020000
// End address for region of flash available for web page upload
#define FLASH_END_ADDRESS     0x4403FFFF
// Flash erase page size
#define FLASH_PAGE_SIZE      0x0800
// Number of flash pages erased per task itteration
#define PAGES_PER_SESSION     0x08
// Address for flash region as seen by CPU
#define FAT_FILE_BASE_ADDR     0x00020000
 
 
 
 
void flash_init( void )
{
 // So, for fSYS = 66 MHz, writing 0x54 to CFMCLKD will set fCLK to 196.43 kHz which is a valid frequency
 // for the timing of program and erase operations.
 // WARNING
 // For proper program and erase operations, it is critical to set fCLK between
 // 150 kHz and 200 kHz. Array damage due to overstress can occur when fCLK
 // is less than 150 kHz. Incomplete programming and erasure can occur when
 // fCLK is greater than 200 kHz.
 MCF_CFM_CFMCLKD = 0x54;
 init_serial_flash(); 
}

//*****************************************************************************
// Flash page erase function.
//
// Author: Eric Gregori  (847) 651 - 1971
//     eric.gregori@freescale.com
//*****************************************************************************
volatile void flash_page_erase( unsigned long *address, unsigned long data )
{
 mcf5xxx_irq_disable();
 
 *address = data;
 
 MCF_CFM_CFMCMD = 0x40;
 
 MCF_CFM_CFMUSTAT = 0x80;
 
 while( !(MCF_CFM_CFMUSTAT & MCF_CFM_CFMUSTAT_CCIF))
 {};
  
 mcf5xxx_irq_enable();  
}

//*****************************************************************************
// Flash write function.
//
// Author: Eric Gregori  (847) 651 - 1971
//     eric.gregori@freescale.com
//*****************************************************************************
volatile void flash_write( unsigned long *address, unsigned long data )
{
 mcf5xxx_irq_disable();
 
 *address = data;
 
 MCF_CFM_CFMCMD = 0x20;
 
 MCF_CFM_CFMUSTAT = 0x80;
 
 while( !(MCF_CFM_CFMUSTAT & MCF_CFM_CFMUSTAT_CCIF))
 {};
  
 mcf5xxx_irq_enable();  
}

//*****************************************************************************
// Flash test function, used to erase flash for demo
//
// Author: Eric Gregori  (847) 651 - 1971
//     eric.gregori@freescale.com
//*****************************************************************************
int flash_erase( void *pio  )
{
 unsigned long address;

 flash_init();
 
 for( address = FLASH_START_ADDRESS; address < FLASH_END_ADDRESS; address += FLASH_PAGE_SIZE )
  flash_page_erase( (unsigned long *)address, (unsigned long)0 );
 return(0);
}
0 Kudos

169 Views
wyliek
Contributor I
Hi

It seems that you do not run your write and erase routines in RAM. Is it not a requirement to do so when program code is running from flash?

Thanks
Kyle

Message Edited by wyliek on 2006-12-0802:27 PM

0 Kudos