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.

TM4C123GH6PM: What is the system clock frequency on reset?

Part Number: TM4C123GH6PM

Just got my hands on this TIVA dev board and tried to blink a LED. The datasheet suggests on reset, PIOSC (16 MHz) is selected as system clock. But when I tried to pass 16000000 to SysTick LOAD register to blink the LED at 1 Hz, the LED seemed to blinking a bit faster than 1 Hz. I hooked it up to the scope and found the frequency was 1.5 Hz (320ms high and low time).

Here's my code if it helps :

#include "TM4C123.h"                    // Device header


void blinkLED(int count);

int main()
{
	SYSCTL->RCGCGPIO |= 1<<5;		//clock port F
	
	GPIOF->DIR |= (1<<3);		//PF3 configured as output
	GPIOF->DEN |= (1<<3);	  //enable digital function on PF3
	
	blinkLED(16000000);
	
	while(1);
	
}

void SysTick_Handler(void)
{
	GPIOF->DATA ^= (1<<3);			//toggle
}

void blinkLED(int count)
{
	SysTick->LOAD = count - 1;			//starting from 0
	SysTick->VAL = 0;
	SysTick->CTRL = 7;			
}



I have even noticed the issue while programming UART driver to communicate with PC. Sometimes it shows garbage characters (baud rate calculated taking 16 MHz system clock).

  • Hi,

      First of all, please refer item #4 in this TM4C FAQ https://e2e.ti.com/support/microcontrollers/other/f/908/t/695568. Basically, we do not support DRM style of programming. We recommend users use the TivaWare to develop their application. If you must use DRM then you can first reference the source code of the TivaWare API on how the registers are configured for the peripherals. 

      Below is the code that I use TivaWare to create a 1Hz blinking LED on PF2. Compare your Systick register configuration with yours.

    Also note that there is max of 3% tolerance on the PIOSC.

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/gpio.h"
    #include "driverlib/rom.h"
    
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    //*****************************************************************************
    //
    //! \addtogroup systick_examples_list
    //! <h1>Systick Interrupt (systick_int)</h1>
    //!
    //! This example shows how to configure the SysTick and the SysTick interrupt.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - NONE
    //!
    //! The following UART signals are configured only for displaying console
    //! messages for this example.  These are not required for operation of
    //! Systick.
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - SysTickIntHandler
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // Counter to count the number of interrupts that have been called.
    //
    //*****************************************************************************
    volatile uint32_t g_ui32Counter = 0;
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    void
    InitConsole(void)
    {
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }
    
    //*****************************************************************************
    //
    // The interrupt handler for the for Systick interrupt.
    //
    //*****************************************************************************
    void
    SysTickIntHandler(void)
    {
        //
        // Update the Systick interrupt counter.
        //
        g_ui32Counter++;
    
        if ((g_ui32Counter % 2) == 0) {
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
    
        } else {
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
    
        }
    
    }
    
    //*****************************************************************************
    //
    // Configure the SysTick and SysTick interrupt with a period of 1 second.
    //
    //*****************************************************************************
    int
    main(void)
    {
    
        uint32_t ui32PrevCount = 0;
    
        //
        // Set the clocking to run directly from the external crystal/oscillator.
        // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
        // crystal on your board.
        //
    
    //    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
    //                   SYSCTL_XTAL_16MHZ);
        SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_USE_OSC);
    
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        //
        // Enable the GPIO pins for the LED (PF2 & PF3).
        //
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
    
        //
        // Set up the serial console to use for displaying messages.  This is
        // just for this example program and is not needed for Systick operation.
        //
        InitConsole();
    
        //
        // Display the setup on the console.
        //
        UARTprintf("SysTick Firing Interrupt ->");
        UARTprintf("\n   Rate = 1sec\n\n");
    
        //
        // Initialize the interrupt counter.
        //
        g_ui32Counter = 0;
    
        //
        // Set up the period for the SysTick timer.  The SysTick timer period will
        // be equal to the system clock, resulting in a period of 1 second.
        //
    
        SysTickPeriodSet(SysCtlClockGet() / 2);
    
        //
        // Enable interrupts to the processor.
        //
        IntMasterEnable();
    
        //
        // Enable the SysTick Interrupt.
        //
        SysTickIntEnable();
    
        //
        // Enable SysTick.
        //
        SysTickEnable();
    
        //
        // Loop forever while the SysTick runs.
        //
        while(1)
        {
            //
            // Check to see if systick interrupt count changed, and if so then
            // print a message with the count.
            //
            if(ui32PrevCount != g_ui32Counter)
            {
                //
                // Print the interrupt counter.
                //
                UARTprintf("Number of interrupts: %d\r", g_ui32Counter);
                ui32PrevCount = g_ui32Counter;
            }
        }
    }