Hi!
I'm using R32C121 with IAR Embedded Workbench, and I have serious problems with debugging in CPU Rewrite mode. The whole thing goes off and freezes, if I go into EW1 mode by this code:
void FLASH_CPUReWriteMode(EWMODE selected_ewmode){
__disable_interrupt();
ewm_e2fm=0; //With this bit set to 1, FEW should not be set to 1
prr = 0xAA; //Protection feloldása FMCR regiszter írásához
fmcr = 0x00; //few = 0;
fmcr = 0x81; //few = 1;
prr = 0x00; //prr = 0;
if(selected_ewmode==EW0){
fpr0 = 0x01; //Protection feloldása FMR0 regiszter írásához, pr0 = 1;
ewm = 0;
fpr0 = 0x00; //pr0 = 0;
}
if(selected_ewmode==EW1){
ewm = 1;
Am I misunderstanding something or doing it wrong? I've look at the FLASH api from Renesas, which has almost the same code like mine, but there are no differences in entering Rewrite Mode. I've already tried this with writing just few=1; and pr0=1; also not getting a working code. I've tried to run through all of my FLASH functions, not interrupting them through debug, which also didn't do anything good. If I go through FLASH rewriting codes, the debug freezes and I have to restart the whole program. Could you please help me in this case? Thank You!
The answer: Do not try to access the Bus Timing register (febc) bit-wise, though the datasheet doesn't say it, write it only as a whole. Rewriting it bit-by-bit results in crashing ONLY when entering CPU rewrite mode, and not during initialization. Great bug, was even greater to debug.