Bootswapping operation is very unstable, even more in release

Hi everyone,

Context of the project

I'm working on a bootloader project based on RL78. I set my memory like this : 

This idea is to jump from application to bootloader when I want to update the application and to jump from bootloader to application when I'm finished with the upload.

Major Issue

I'm able to start bootloader, flash the program, jump to application, jump to bootloader and flash program again. But this is ok like 50% of the time in DEBUG. The first start and flash is always working, the first jump is almost always working and after that it depends.

In release mode, it is even worse. I can start bootloader, flash the program and most of the time I can't even jump to the application

How did I code that ?

I'm based on the renesas FSL library and working on the R5F10DPJ microcontroller. To perform the bootswapping, I'm using this function : 

void Flash_SwapBootCluster()
{
	fsl_u08 fsl_status;
	UINT32 wait;
	
	// Open FSL and prepare all functions
	FSL_Open();
	FSL_PrepareExtFunctions();

	// Invert bootflag to start correct bootloader and close FSL
	fsl_status = FSL_InvertBootFlag();
	while(fsl_status != FSL_OK)
	{
		fsl_status = FSL_InvertBootFlag();
	}

	// Close FSL
	FSL_Close();

	/* Delay */
	wait = (UINT32)0;
	while(wait < (UINT32)10000)
	{
		wait++;
	}

	// Perform swapping of bootcluster
	fsl_status = FSL_SwapBootCluster();
	while(fsl_status != FSL_OK)
	{
		fsl_status = FSL_SwapBootCluster();
	}
}

I start to be out of idea, am I doing something wrong with this boot swapping ?

Thanks in advance and have a good day !

Parents Reply
  • Hi, thanks again for you answer.

    I need to reserve SELFRAM for the FSL so I added this in the linker file : 

    -Z(CODE)SELFRAM=[FBF00-FC2FF]

    Do you want me to update the linker file or directly the cstartup.s87 file ? (which is reading my linker file). I start to struggle how to organize my linker file between FSL segment, SelfRam for FSL_Write and RAM Initialization

    I have this in my cstartup.s87 file :

            ; Init stack segment for as the generated code may sometimes
            ; access the 4th byte of a return address before it is initialized
            MOVW    HL, #sfb(CSTACK)
            MOVW    BC, #LWRD(sizeof(CSTACK))
            CMP0    C
            SKZ
            INC     B
            MOV     A, #0xCD        ; 0xCD to fool C-SPY's stack limit check
    loop_s:
            MOV     [HL], A
            INCW    HL
            DEC     C
            BNZ     loop_s
            DEC     B
            BNZ     loop_s
    
            MOV     CS, #0

    And, in my linker file : 

    //-------------------------------------------------------------------------
    //      Stack segment.
    //-------------------------------------------------------------------------
    -Z(DATA)CSTACK+_CSTACK_SIZE=FC300-FFE1F

    EDIT : This is only for the bootloader project, not the application

Children