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 !
Hello,
First of all your memory layout is a bit confusing.
There should be boot cluster 0 (for the one boot program) and boot program 1 (for the other boot program), if you want to use the boot swap mechanism. On top of them there should be the application(s).
The boot program must exist only inside the memory size of a boot cluster.
Regarding the boot swap, after calling FSL_InvertBootFlag you should issue a software reset so the boot swap takes place. The new bootloader is active after reset.
Hi, thanks for your answer
Concerning my memory organization, I aggre it wasn't very clear. In fact, there is 2 applications : The one handling the bootloading process to update the flash and the other one, the main application. Each of these application have their own boot (interrupt vector, ...)
Ok so calling the FSL_SwapBootCluster is not necessary since I already inverted boot flag. I just need to perform the reset then. I'll try this thanks !
I tried multiple things :
- Only keep FSL_SwapBootCluster function. So the jump to the second application was ok but the interruption table wasn't
- Only keep the FSL_InvertBootFlag function and perform a reset
I still have the same behavior : Stable in debug but can't jump to application in release
Also, I saw an issue every time the process failed in debug : I can't reprogram the MCU just after. I need to disconnect/reconnect the tool. I don't know if it can help us identify the issue
Have you a valid boot program on boot cluster 1?
When boot swap is used: Set the option bytes to 000C0H to 000C3H and 020C0H to 020C3H, and theon-chip debug security IDs to 000C4H to 000CDH and 020C4H to 020CDH.
On release mode (without a debugger) disable the on-chip debug setting:
I don't have this settings on Renesas Flash Programmer (V3.11)
Concerning the content of bootcluster, 0x0000 and 0x2000 are correctly written.
This setting is on e2studio or CS+ where you build the project.
Ha yes sorry, I completely forgot to precise that I'm working on IAR 7
Well, the Appilet for IAR then.
Alright I understand it was for the option byte sorry.Behavior is the same and now (before I change the option byte) the debug was completely unstable and application to bootloader is not working anymore (but bootloader to application always working)
Edit : Really sorry, I know it's a weird issue and I struggle to give more information to be clearer
Hi again, I'm bringing some news.
For now, I was able to stabilize the process in DEBUG mode, based on the chart you sent me. So I'm just inverting boot flag and then I force a soft reset using an infinite loop and the watchdog reset.
When I go in release mode, I can communicate with the bootloader to update the flash but when jumping from bootloader to application, the communication ends and everything is broken. It's like the MCU reset and remains in reset, without initializing the board. I'm still investigating