This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UCD3138128 - Live Switch Function Triggering Access Exception

Other Parts Discussed in Thread: UCD3138128

Hi,


I am trying to switch from the firmware in block(0,1) to another firmware in block(2,3).

My switching function always trigger an illegal access exception and i don't know why :-(

I am posting my function below, could anyone tell me whats wrong with my code? Thanks.

---------------------------------------------------------------------------------------------------------------------------------

My function to switch from block (0,1) to block(2,3):

extern void switch_entry(void);

void boot_switch_to_block_2(void){
    // Set block 2,3 size to 0
    DecRegs.MFBALR18.bit.BLOCK_SIZE = 0;
    DecRegs.MFBALR19.bit.BLOCK_SIZE = 0;

    // Move block 0,1 to backup address
    DecRegs.MFBALR1.bit.ADDRESS = 0x10000 >> 10;
    DecRegs.MFBALR17.bit.ADDRESS = 0x18000 >> 10;

    // Move block 2,3 to boot address
    DecRegs.MFBALR18.bit.ADDRESS = 0;
    DecRegs.MFBALR19.bit.ADDRESS = 0x8000 >> 10;

    // Set block 2,3 size back to 32K
    DecRegs.MFBALR18.bit.BLOCK_SIZE = 6;
    DecRegs.MFBALR19.bit.BLOCK_SIZE = 6;

    // Software reset
    switch_entry();
}

where switch_entry is a global label in load_UCD3138128.asm

Case handler in SWI:

        case 16:
            if(arg1 == TRUE){
                // Copy function to RAM
                memcpy((void*)program_area,(void*)boot_switch_to_block_0_start,sizeof(program_area));
                // call function
                boot_switch_to_block_0();
            }
            else{
                // Copy function to RAM
                memcpy((void*)program_area,(void*)boot_switch_to_block_2_start,sizeof(program_area));
                // call function
                boot_switch_to_block_2();
            }
            break;

Modified load_UCD3138128.asm:

        .global _switch_entry


rom_main .equ 0xffffa4dc
        .sect ".vectors"
        .state32
        B    c_int00
        B    _undefined_instruction_exception
        B    _software_interrupt
        B    _abort_prefetch_exception
        B    _abort_data_fetch_exception
        B    _abort_prefetch_exception
        B    _standard_interrupt
        B    _fast_interrupt
_switch_entry
        B    switch_image_stack_fix
        .align    4
        .sect ".text"
        .state32


switch_image_stack_fix
        LDR        r13, c_sup_stack_top
        MRS        r1,spsr
        BIC        r1,r1,#0x20
        MRS        r0,cpsr
        BIC        r0,r0,#0x1F
        ORR        r0,r0,#0x1F
        MSR        cpsr_cf,r0
        ldr        r13,c_user_stack_top
        MSR        cpsr_cf,r1
        B _c_int00

  • void boot_switch_to_block_2(void){

       // Set block 2,3 size to 0

       DecRegs.MFBALR18.bit.BLOCK_SIZE = 0;

       DecRegs.MFBALR19.bit.BLOCK_SIZE = 0;

       // Move block 0,1 to backup address

       DecRegs.MFBAHR1.bit.ADDRESS = 1;

       DecRegs.MFBAHR17.bit.ADDRESS = 1;

       // Move block 2,3 to boot address

       DecRegs.MFBAHR18.bit.ADDRESS = 0;

       DecRegs.MFBAHR19.bit.ADDRESS = 0;

       // Set block 2,3 size back to 32K

       DecRegs.MFBALR18.bit.BLOCK_SIZE = 6;

       DecRegs.MFBALR19.bit.BLOCK_SIZE = 6;

       // Software reset

       switch_entry();

    }

    I think i didnt set the address for the blocks correctly before. I have modified my code to the lines in red.

    I still getting the illegal access exception, and i found that the exception is generated when i try to write ADDRESS of MFBAHR1 & MFBAHR17.

    Is there anything i need to do before i write MFBAHR1/MFBAHR17 while i'm running in block(0,1)?

  • You can't do the block switch while running in one of the blocks. We recommend you go copy the block switch function from program flash to RAM, and call it in RAM.
  • Hi Ian,

    Thanks for your reply. My problem is resolved by accessing MFBALRX register in word but not bit field.

    Just like one of your post on the forum: