Hi, I am using USB CDC Virtual COM Demo(FreeRTOS) and my development environment is K64F12+KDS3.0+KSDK1.2.0 without PE. I want try to change the FlexBus clock (CLKOUT) according to PC serial port input. However, when I change the value of ''.vdiv0'' and re-initial the clock again, the virtual serial port cannot find any more and nothing can be wrriten to the port
the code is shown following:
in board.c:
const clock_manager_user_config_t ClockConfigRun30M =
{
.mcgConfig =
{
.mcg_mode = kMcgModePEE, // Work in PEE mode.
.irclkEnable = true, // MCGIRCLK enable.
.irclkEnableInStop = false, // MCGIRCLK disable in STOP mode.
.ircs = kMcgIrcSlow, // Select IRC32k.
.fcrdiv = 0U, // FCRDIV is 0.
.frdiv = 7U,
.drs = kMcgDcoRangeSelLow, // Low frequency range
.dmx32 = kMcgDmx32Default, // DCO has a default range of 25%
.oscsel = kMcgOscselOsc, // Select OSC
.pll0EnableInFllMode = false, // PLL0 disable
.pll0EnableInStop = false, // PLL0 disalbe in STOP mode
.prdiv0 = 0x13U,
.vdiv0 = 0x00U,//0x10U, //0x18U
},
.simConfig =
{
.pllFllSel = kClockPllFllSelPll, // PLLFLLSEL select PLL.
.er32kSrc = kClockEr32kSrcRtc, // ERCLK32K selection, use RTC.
.outdiv1 = 0U,
.outdiv2 = 1U,
.outdiv3 = 1U,
.outdiv4 = 4U,
},
.oscerConfig =
{
.enable = true, // OSCERCLK enable.
.enableInStop = false, // OSCERCLK disable in STOP mode.
}
};
void BOARD_ClockInit30M(void)
{
/* Set allowed power mode, allow all. */
SMC_HAL_SetProtection(SMC, kAllowPowerModeAll);
/* Setup board clock source. */
// Setup OSC0 if used.
// Configure OSC0 pin mux.
PORT_HAL_SetMuxMode(EXTAL0_PORT, EXTAL0_PIN, EXTAL0_PINMUX);
BOARD_InitOsc0();
// Setup RTC external clock if used.
BOARD_InitRtcOsc();
/* Set system clock configuration. */
#if (CLOCK_INIT_CONFIG == CLOCK_VLPR)
CLOCK_SYS_SetConfiguration(&g_defaultClockConfigVlpr);
#else
CLOCK_SYS_SetConfiguration(&ClockConfigRun30M);
#endif
}
and in virtual_com.c:
void Virtual_Com_App(void)
{
/* User Code */
if ((0 != g_recv_size) && (0xFFFFFFFF != g_recv_size))
{
int32_t i;
/* Copy Buffer to Send Buff */
for (i = 0; i < g_recv_size; i++)
{
USB_PRINTF("Copied: %c\n", g_curr_recv_buf[i]);
g_curr_send_buf[g_send_size++] = g_curr_recv_buf[i];
}
g_recv_size = 0;
}
if (g_send_size)
{
uint8_t error;
uint32_t size = g_send_size;
g_send_size = 0;
error = USB_Class_CDC_Send_Data(g_app_handle, DIC_BULK_IN_ENDPOINT,g_curr_send_buf, size);
//added by myself to change the FlexBus according to serial port input
switch(g_curr_send_buf[0]){
case 0x31:
BOARD_ClockInit30M();
GPIO_DRV_ClearPinOutput(kGpioLED1);
g_curr_send_buf[0]=0x00;
OSA_Init();
break;
case 0x32:
GPIO_DRV_SetPinOutput(kGpioLED1);
//BOARD_ClockInit40M();
g_curr_send_buf[0]=0x00;
break;
case 0x33:
GPIO_DRV_ClearPinOutput(kGpioLED2);
//BOARD_ClockInit35M();
g_curr_send_buf[0]=0x00;
break;
default:
break;
}
if (error != USB_OK)
{
/* Failure to send Data Handling code here */
}
}
if BOARD_ClockInit30M() is not included in the case statement, the LED can be toggled correctly and serial port is normal. However, when the BOARD_ClockInit30M() is included in the case statement, the serial port can only be inputed once and then when I input again, error message will appear and the serial port cannot be opened anymore.


Could anybody can help me about this? I suppose it may because I re-initial the clock but I don't know how to fix it.
Many thanks!
Best Regars,
Gloria