This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F2806: trouble switching clock source after boot

Part Number: TMS320F2806
Other Parts Discussed in Thread: CONTROLSUITE

Hello,

For my application I want to switch after boot to an external oscillator. This oscillator is connected to X1/X2 pins. In the bootloader I use the internal oscillator, after the App starts i switch to the external oscillator.

the problem is that the CPU seems to keep resetting. I suspect the VCOCLK getting an overflow since it doesn't get cleared by OSCCLK. However im not sure.

What is interesting is by running the app in debug mode (i.e no bootloader), the app works OK, and no reset happens. this means that the oscillator settings in the App are not faulty. The Oscillator settings in the bootloader are not faulty either, since if i undo the oscillator changes in the App everything still works, carrying on with the oscillator settings in the bootloader. 

Somehow the transition between internal/external oscillator doesnt go smoothly.

below are the bootloader Oscillator steps:

  // enable internal oscillator 1
  CLK_enableOsc1(obj->clkHandle);

  // disable the external clock in
  CLK_disableClkIn(obj->clkHandle);

  // disable the crystal oscillator
  CLK_disableCrystalOsc(obj->clkHandle);

  // disable oscillator 2
  CLK_disableOsc2(obj->clkHandle);

  // set the oscillator source
  CLK_setOscSrc(obj->clkHandle,CLK_OscSrc_Internal);

  // set the low speed clock prescaler
  CLK_setLowSpdPreScaler(obj->clkHandle,CLK_LowSpdPreScaler_SysClkOut_by_4);

  // set the clock out prescaler
  CLK_setClkOutPreScaler(obj->clkHandle,CLK_ClkOutPreScaler_SysClkOut_by_1);

the steps for switching (that happen in the App):

  // disable the external clock in. check ref. doc page 12. X1
  CLK_disableClkIn(obj->clkHandle);


  CLK_setOsc2Src(obj->clkHandle,CLK_Osc2Src_Internal);

  // set the oscillator source
  CLK_setOscSrc(obj->clkHandle,CLK_OscSrc_External);

  // moved to last
  CLK_disableOsc1(obj->clkHandle); // todo check


  // set the low speed clock prescaler
  CLK_setLowSpdPreScaler(obj->clkHandle,CLK_LowSpdPreScaler_SysClkOut_by_4);

  // set the clock out prescaler
  CLK_setClkOutPreScaler(obj->clkHandle,CLK_ClkOutPreScaler_SysClkOut_by_1);

it seems that somehow the transition between the 2 clocks is problematic. Did anyone have a similar experience?

Thanks,

  • Hello Hani,

    Have you tried commenting the "disable the external clock in" function code out?

    // disable the external clock in
    CLK_disableClkIn(obj->clkHandle);

    Does it work if you remove the above code?

    Best Regards,
    Adam Dunhoft
  • Hello Adam,

    It doesn't work since my external oscillator is on the X1/X2 pins. I need this function to set CLKCTL[XCLKINOFF] = 1, to disconnect GPIO19/38 from the XCLKIN gate. (page 37 of system control document)
  • Hello Hani,

    Have you tried copying the bootloader code into the App and just running the App? Does it pass?

    Are you configuring the PLL in the bootloader?

    Best Regards,
    Adam Dunhoft
  • Hello Adam,

    Copying the bootloader code in the App works. As well as Copying the App Code into the bootloader, as long as I dont switch clocks in the App. (i.e switching to ext. osc. in Bootloader only).

    so the problem happens when switching clocks between bootloader and App, and when I use external osc. in bootloader and app.

    Problem doesn't happen when I switch to ext. osc. in bootloader (and do nothing in App).

    In system Control Document page 42, it mentions a system initialization file (DSP2803x_SysCtrl.c) I am yet to find where this file is downloadable. It is also not on my system??

    Perhaps it is outdated or no longer in the install, but Its very helpful to have it as an example source.


    Regards.

  • Hello Hani,

    You can find the SysCtrl.c files in controlSUITE.

    F2806x: ..\controlSUITE\device_support\f2806x\v151\F2806x_common\source
    F2803x: ..\controlSUITE\device_support\f2803x\v130\DSP2803x_common\source

    What is the process for your switch from bootloader to application code?

    Best Regards,
    Adam Dunhoft
  • Hello Adam,

    The problem was solved by commenting the following line in the bootloader code:

    CLK_disableCrystalOsc(obj->clkHandle);

    This is on by default, and disabling it cuts the oscillator signal coming in X1/X2 to uC.

    Thanks,