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.

Blink - Turn off

Hi, I have a minor issue, I just start to use the Tm4c129 board and I try to run a blink code:

//*****************************************************************************
int
main(void)
{
	int ui32Loop;
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_1);

	SysTickPeriodSet(SysCtlClockGet() / SYSTICKS_PER_SECOND);
	SysTickIntEnable();
	SysTickEnable();

    while(1)
    {
        //
        // Turn on the LED.
        //
    	GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);

        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 10000; ui32Loop++)
        {
        }

        //
        // Turn off the LED.
        //
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,  GPIO_PIN_1);

        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 10000; ui32Loop++)
        {
        }
    }
}

I don't see the led blink, and when I try to pause the debug pop up the error:

"Can't find a source file at "C:/Jenkins/workspace/TivaWare-Git-Release/DriverLib/build/DriverLib.test/driverlib/gpio.c" "

  • Hello Mathieu

    On the TM4c129 the following function is invalid

    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    It must be replaced by SysCtlClockFreqSet.

    Also for the issue you mentioned that is expected as the driverlib.lib is compiled on a TI machine. While the precompiled library is working, the debug information may not be useful. To be able to debug, please build the driverlib.lib locally and then use the same in your project.

    Regards
    Amit
  • Hi, I thought that it was a TI machine because I don't have a Jenkins user in my system. Thanks for the help
  • Hello Mathieu,

    That is OK. You can rebuild the driverlib on a Windows PC as well. Import the driverlib as a project, build and use the output from the workspace into your project.

    Regards
    Amit
  • Hi why the led isn't still blinking.... This is the complete code:

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/tm4c129xnczad.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/systick.h"
    
    
    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Blinky (blinky)</h1>
    //!
    //! A very simple example that blinks the on-board LED.
    //
    //*****************************************************************************
    #define SYSTICKS_PER_SECOND 100
    volatile unsigned long g_ulSysTickCount = 0;
    void
    SysTickIntHandler(void)
    {
        //
        // Update our system tick counter.
        //
        g_ulSysTickCount++;
    }
    //*****************************************************************************
    //
    // Blink the on-board LED.
    //
    //*****************************************************************************
    int
    main(void)
    {
    	int ui32Loop;
    	SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320 , 40000000 );
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    
    
    	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_1);
    	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_2);
    
    	SysTickPeriodSet(SysCtlClockGet() / SYSTICKS_PER_SECOND);
    	SysTickIntEnable();
    	SysTickEnable();
    
        while(1)
        {
            //
            // Turn on the LED.
            //
        	GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 100000; ui32Loop++)
            {
            }
    
            //
            // Turn off the LED.
            //
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,  GPIO_PIN_1);
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 100000; ui32Loop++)
            {
            }
        }
    }

  • Hello Mathieu,

    Because SysCtlClockGet() is not a TM4C129 function. It is a TM4C123 function. This is causing SysTick to fire so frequently that the main loop does not get executed. To be able to set the correct value for the SysTick you need to use the return value of the SysCtlClockFreqSet function.

    Regards
    Amit
  • Hi so the modification could be:

    int clock;
    clock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480) , 120000000 );
    
    ....
    
    
    SysTickPeriodSet(clock / SYSTICKS_PER_SECOND);
    

  • Hi Mathieu,

    You are trying the basics of the MCU - blinking an LED - so why do you also have there the systick?
    If you don't have enough experience to analyze possible faults (and even if you did) you should try to simplify your code! You just need to blink the LED, you don't need the systick, it's just another possible error to arise!

    First remove that systick parts and try again.

    Also try use in the for instead of "ui32Loop < 100000;" do "ui32Loop < 100000000;". I would say the led is blinking but too fast for the human eye to see.
    Later after you try that I will tell you a better way to create crude delays instead of using a "for"
  • Hi,

    I remove the systick from my vector table and my code so I got this:

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/tm4c129xnczad.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/systick.h"
    
    //*****************************************************************************
    //
    // Blink the on-board LED.
    //
    //*****************************************************************************
    int
    main(void)
    {
    	int ui32Loop;
    
        SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
    
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    
    
    	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0);
    
    
    
        while(1)
        {
            //
            // Turn on the LED.
            //
        	GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 100000000; ui32Loop++)
            {
            }
    
            //
            // Turn off the LED.
            //
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0,  GPIO_PIN_0);
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 100000000; ui32Loop++)
            {
            }
        }
    }
    

    The led isn t blinking. I think there must a be a build/linker error.

  • I actually got a TM4C1294 launchpad handy.

    I tested your code and it worked fine. The value I told you to use for the for was actually too big now. Took about 15seconds.
    I tested with the value you had initially and it blink too fast (I could kinda notice it blinking but if I didn't knew I would mistake it as always on).


    Play a bit with the value, c'mon. If it went into debug there is surely no build/linker error (at least not a common one).
  • Hello Luis

    Extreme precision analysis with the SysTick timer usage in the blinky code and even more on the loop count... Bravo

    Regards
    Amit
  • Thank you Amit :D


    , do remember to come back report your results even if you are successful.
    There's also the matter of showing you the really simple and more predictable function for crude delays. I don't want to go into that just yet hence why I'm not saying it. First let's solve the current problems without introducing new things.
  • Bravo to Luis (of course) and also to Amit for recognizing Luis' dogged persistence, recommendation of "KISS" (although not directly stated) and boundless tech desire & understanding... (note to Amit - another couple of "rainy seasons" - Luis will have both of our jobs...)
  • Hi, I keep getting an error when I pause the debug

    Can't find a source file at "C:/Jenkins/workspace/TivaWare-Git-Release/DriverLib/build/DriverLib.test/driverlib/gpio.c"

    so I am pretty sure I got an error into my driverlib import. Because the Led isn`t blinking with the 15 seconds value.

    I reduce the clock frequency by 100 mHz and still I don t even see the led close to blinking. I add an orther one and I just 2 led lighting up

    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/tm4c129xnczad.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/systick.h"
    
    //*****************************************************************************
    //
    // Blink the on-board LED.
    //
    //*****************************************************************************
    int
    main(void)
    {
    	int ui32Loop;
    
        SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 20000000);
    
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    	SysCtlDelay(3);
    
    
    	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0);
    
    	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_1);
    
    
        while(1)
        {
            //
            // Turn on the LED.
            //
        	GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
        	 GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 1000000; ui32Loop++)
            {
            }
    
            //
            // Turn off the LED.
            //
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0,  0);
            GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1);
            //
            // Delay for a bit.
            //
            for(ui32Loop = 0; ui32Loop < 1000000; ui32Loop++)
            {
            }
        }

  • Hi , i went for the function systdelay instead of the for loop and now the led is correctly blinking
  • Hello Mathieu,

    The error message for the path "C:/Jenkins/workspace/TivaWare-Git-Release/DriverLib/build/DriverLib.test/driverlib/gpio.c" means that you are using the precompiled version of the driverlib that is in the installer. If you re compile the same on your machine it would keep the debug symbols as well and then you will be able to debug the pre compiled files.

    Regards
    Amit
  • Your error is like Amit says. I get exactly the same error! You actually can tell where is the file when that error appear - I always do that but I should do what Amit suggests which is recompile the library.

    The SysCtlDelay() function - not systdelay, note that the first words on the functions are relevant. SysCtl -> System Control. Note that all the GPIO functions start with GPIO - is what I was going to suggest for you to use due to being more easy to tell the time it will block the code. I am pretty sure your previous code with the "for" and without the added complication of the system tick timer is working, you just didn't get the timing right (you see how the use of the "for" to create delays causes confusion so try to avoid it with SysCtlDelay()).

    Now after playing around with the GPIO - outputs and inputs and probably simple interrupts - you could try to implement a systick counter and a function to create more accurate delays. The SysCtlDelay is not that accurate, it's simply 3 NOP instructions. In simple codes it can be accurate enough I guess, but interrupts do affect the accuracy of it.
  • cb1_mobile said:
    (note to Amit - another couple of "rainy seasons" - Luis will have both of our jobs...)



    Then I would be able to eat giant cookies everyday and that would be probably not as awesome as I think it would