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.

Can't Change TM4C129X System Clock

Other Parts Discussed in Thread: SYSBIOS

I'm trying to change the system clock on the TM4C129X and am having some issues. I have been developing on the dev kit which has a 25MHz crystal. I just received our first run of prototypes and am successfully able to load code and run my program...however we are using a 16MHz crystal. I'd still like to run at 120MHz like the dev kit. I have tried the following code with no luck.

I am using IAR version 7.20.2 and TI-RTOS version 2.00.02.36

/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Types.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>

/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>

/* Example/Board Header files */
#include "Board.h"

/* USB Reference Module Header file */
#include "USBCDCD.h"
#include "diagUART.h"      // for UART init
#include "debugPrint.h"
#include "irdaDriver.h"
#include "gpioDriver.h"
#include <driverlib/sysctl.h>	

/*
 *  ======== main ========
 */
int main( void )
{
   uint32_t clockspeed;
   uint32_t baudclock;
   Types_FreqHz freq;
   Bits32 loFreq;
   
   // Set clock
   SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | 
                   SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN );
   clockspeed = SysCtlClockGet();
   BIOS_getCpuFreq( &freq );     
      
   /* Call board init functions */
   Board_initGeneral();
   Board_initGPIO();
   Board_initUART();
   Board_initI2C();
   InitDebugPrint();
   InitDiagUart();
   Board_initLCD();
   Board_initUSB( Board_USBDEVICE );
   GPIO_Init();

   /* Call CDC init */
   USBCDCD_init();

   /* Start BIOS */
   BIOS_start();

   return (0);
}

Changing the parameters in SysCtlClockSet() have no affect on the clock speed when I call SysCtlClockGet(). I always return 96MHz. I thought I remember reading somewhere that SysCtlClockGet() is not supported with this micro, but I can't seem to find that now. It is in the Tivaware Peripheral library and is used in a lot of the function calls.  I traced the code back to sysctl.h and found the PLL defines and tried altering those to see if anything changed. This did not change the clock speed either. Does the sysctl.h file not get compiled at runtime?

//*****************************************************************************
//
// The following are defines for the bit fields in the SYSCTL_PLLFREQ0
// register.
//
//*****************************************************************************
#define SYSCTL_PLLFREQ0_MFRAC_M 0x000FFC00  // PLL M Fractional Value
#define SYSCTL_PLLFREQ0_MINT_M  0x000003FF  // PLL M Integer Value
#define SYSCTL_PLLFREQ0_MFRAC_S 10
#define SYSCTL_PLLFREQ0_MINT_S  0

//*****************************************************************************
//
// The following are defines for the bit fields in the SYSCTL_PLLFREQ1
// register.
//
//*****************************************************************************
#define SYSCTL_PLLFREQ1_Q_M     0x00001F00  // PLL Q Value
#define SYSCTL_PLLFREQ1_N_M     0x0000001F  // PLL N Value
#define SYSCTL_PLLFREQ1_Q_S     8
#define SYSCTL_PLLFREQ1_N_S     0

Any help would be appreciated. Thanks!

  • Brayden,

    TI-RTOS allows you to modify the clock frequency through its Boot module. So, the following code is not recommended. Instead in Code Composer Studio, double click on .cfg file to open it in a graphical view. In the graphical view, click and navigate through TI-RTOS Kernel > Boot to open Boot module page.

    // Set clock
    SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | 
                   SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN );
    clockspeed = SysCtlClockGet();
    

    It should look something similar to this:

    You can set up the frequency from this page and then re-build your code.

    Hope this helps.

    Vikram

  • Is there a way to do this in IAR? Is there an option in the TI-RTOS plugins? I am not using Code Composer Studio.

  • Definitely. In IAR, the graphical view is not currently supported but you can add the following lines to the .cfg file to enable the same functionality.

    var Boot = xdc.useModule('ti.catalog.arm.cortexm4.tiva.ce.Boot');
    Boot.xtal = Boot.XTAL_16MHZ;
    Boot.cpuFrequency = 12000000;
    BIOS.cpuFreq.lo = 12000000;

    Further reference of the Boot module, please refer to this documentation.

  • Hi Brayden,

    Brayden Sundstrand1 said:
    SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN ); clockspeed = SysCtlClockGet();

    SysCtlClockSet C API is for TM4C123 microcontroller. For TM4C129, use SysCtlClockFreqSet. See, details at Tivaware Peripheral Library User's Guide. You can also check how System Clock is set at Tivaware example programs for TM4C129.

    Also there is some issue with the return value of SysCtlClockGet(). So, I recommend to just assign the actual value of system clock to clockspeed variable..

    I also recommend to use the latest Tivaware version for TM4C129.

    - Markel

  • Thank you for the information, this worked. The only thing I had to add was var BIOS = xdc.useModule('ti.sysbios.BIOS') as I did not already have that declared. I will also try the SysCtlClockFreqSet function to make sure I can change dynamically.

    -Brayden

  • Where is the documentation for SysCtlClockFreqSet? I have the latest TivaWare Peripheral Driver Library doc (http://www.ti.com/lit/ug/spmu298/spmu298.pdf) and this function is not in there.

    I was able to get it to work, but an updated document with the proper API calls would help.

    Thank you,
    Brayden

  • Hi Brayden,

        It can be found at Tivaware 2.1 and later versions at the doc folder.

    - kel