Rx671 Code Flash erase not working when changing system clock

Hi,

I'm changing the System clock to 96MHz and 12 MHz for operations. when i change the system clock, Code Flash erase, write functions are not working. Also, the flash functions return FLASH_SUCCESS even though the erase function is failed. I'm not sure if any other setting has to be done for changing system clock.

My main clock is 12MHz with external oscillator.

PLL Circuit Frequency division is x1.

PLL Circuit Frequency Multiplication is x16

I'm maintaining all clocks (FlashIF, ICLK, peripheral and external bus clock) to 12 MHz.

And based on operations, i want to change to high frequency (ICLK to 96MHz)so i'm using below code.

/* Protect off. */
	    SYSTEM.PRCR.WORD = 0xA50B;

	    /* Select the clock based upon user's choice. */
//	    clock_source_select2();

	    delay_us(10);
	if(HIGH_FREQUENCY == ucClockSpeed){
		SYSTEM.SCKCR.BIT.ICK = 1; // 192/2 =96MHz - Ext clk x N
		SYSTEM.ROMWT.BYTE = 0x01;
	}
	else
	{
		SYSTEM.SCKCR.BIT.ICK = 4; // 192/16 =12MHz - Ext clk x N
		SYSTEM.ROMWT.BYTE = 0x00;
	}

	delay_us(50);
//	/* Protect on. */
	SYSTEM.PRCR.WORD = 0xA500;