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.

LM4F120 SysCtlClockSet hang

Hi! Sorry for writing in this forum, but Stellaris one became read-only...

I'm having a problem with the following code:

#include "inc/hw_memmap.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "driverlib/ssi.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "utils/ustdlib.h"
#include "driverlib/uart.h"

#include "LCD/ST7565.h"
#include "grlib/grlib.h"

#define MS SysCtlClockGet()/(1000*3)
#define US SysCtlClockGet()/(1000000*3)

int main(void)
{
	tContext sContext;
	tRectangle sRect;
	tDisplay sLCD;
	unsigned char LCDBuffer[LCD_WIDTH*LCD_HEIGHT/8];

// HANGS HERE SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinConfigure(GPIO_PB4_SSI2CLK); // SCK pin GPIOPinConfigure(GPIO_PB7_SSI2TX); // MOSI pin GPIOPinTypeSSI(GPIO_PORTB_BASE,GPIO_PIN_4|GPIO_PIN_7); GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_4); // A0 and LCD NCS pin configuration GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 0xFF); // Set NCS high GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5); // NRESET pin configuration GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0xFF); // Set NRESET high GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // Set LED output pin SSIConfigSetExpClk(SSI2_BASE,SysCtlClockGet(),SSI_FRF_MOTO_MODE_3,SSI_MODE_MASTER,1000000,8); SSIEnable(SSI2_BASE); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0xFF); /* ************************************************************************************************ * * GRAPHICS * * ************************************************************************************************ */
// When I comment out also this line works fine! // st7565r_InitDriver(&sLCD, LCDBuffer); // // return; // // // // // Initialize the graphics context. // // // GrContextInit(&sContext, &sLCD); // // // // // Fill the top 15 rows of the screen with blue to create the banner. // // // sRect.sXMin = 0; // sRect.sYMin = 0; // sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; // sRect.sYMax = 14; // GrContextForegroundSet(&sContext, ClrBlack); // GrRectFill(&sContext, &sRect); // // // // // Put the application name in the middle of the banner. // // // GrContextFontSet(&sContext, g_pFontFixed6x8); // GrStringDrawCentered(&sContext, "hello", -1, // GrContextDpyWidthGet(&sContext) / 2, 7, 0); // // // // // Say hello using the Computer Modern 20 point font. // // // GrContextFontSet(&sContext, g_pFontCm20); // GrStringDrawCentered(&sContext, "Hello World!", -1, // GrContextDpyWidthGet(&sContext) / 2, // ((GrContextDpyHeightGet(&sContext) - 16) / 2) + 16, // 0); // // // // // Flush any cached drawing operations. // // // GrFlush(&sContext); }

When lines in the bottom of main function are not commented debugging process hangs on SysCtlClockSet command. When I comment out st7565r_InitDriver(&sLCD, LCDBuffer); it works fine. What is strange - I am running it in step by step mode and the program is not even coming close to the commented lines. It always hangs on SysCtlClockSet.

  • Hi,

    Without the code I would say this is a lottery to guess the problem. Users more experienced with the stellaris probably can give a good educated guess but still, you should provide the most info possible to solve the problem.

    Instead of step by step debug only, try to go into the SysCtlClockSet function
  • user3555485 said:
    What is strange - I am running it in step by step mode and the program is not even coming close to the commented lines. It always hangs on SysCtlClockSet.

    Why do you believe that, "strange?"   Look more closely at, "SysCtlClockSet()" it's a huge function - is it not?   Unwise to "break therein."

    Does not (much) of your code spring from the (other) past LX4F device - the LX4F232?   That MCU's eval board included a small (oled) I believe - your LX4F120 (there never were any LM4F120s) is a very "stripped down device" and it's eval board was display free...

    Is your board's xtal intact - and marked as the same value your function notes?

  • I did a custom Booster Pack for that board. It contains ST7565R driver-based LCD.

    Well, I stepped into SysCtlClockSet and it turned out that I'm running into FaultISR... I did some investigation and what turns out that problem is in LCD buffer. I guess its too large (?!). Its 132*64/8 = 1056 Bytes (1056*unsiged char). I have reduced main function to sth like that:

    int main(void)
    {
    	unsigned char LCDBuffer[LCD_WIDTH*LCD_HEIGHT/8];
    
    	LCDBuffer[0] = 'a';
    
    	SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    }

    After stepping into SysCtlClockSet I'm getting FaultISR.

  • Your "SysCtlClockSet()" is exactly the same as ours. (and ours has run successfully upon over 2K LX4F boards)

    Would it not make sense to "avoid" break-point w/in SysCtlClockSet() - and instead "break" at some dummy function - just after SysCtlClockSet() completes?

    SysCtlClockSet() (again) is a huge function - each every function it calls must be included w/in your file set-ups & configurations - have you insured that's been achieved?

    Your post has the strong scent of, "I made my own project!"   (usual - poster, "Last Words!")   

    Long live the simpler, far faster/safer, "Copy an existing/official project" - and add your code therein!

  • Well, actually I started with projects described in the Stellaris Launchpad Workbook.

    I guess discussion about braking in/outside of SysCtlClockSet is not a problem anymore after my reply to your previous post.

    What's more, when I change size of the buffer to sth smaller, say 12*8=96 Bytes, everything works fine.

  • Ok. I guess I've figured out what was wrong. However, I'd like to know if I'm right.

    I was declaring quite an array in the function. I guess it caused heap overflow, and in consequence FaultISR. When declaration of an array was moved outside from the function (declared as global variable) FaultISR has disappeared.
  • user3555485 said:
    I was declaring quite an array in the function

    That's completely clear... ... ... to you.

    Which function?   What does this have to do w/your past issue w/I"SysCtlClockSet()?"

    Stack size is "usual suspect" when "quite an array" is introduced...

  • Well, I have posted function discussed in a reply to your post (published at Nov 17, 2015 4:10 PM). Thus, saying that I meant exactly function already introduced in a previous post. However, to make things clear, function mentioned:

    int main(void)
    {
        unsigned char LCDBuffer[LCD_WIDTH*LCD_HEIGHT/8];
    
        LCDBuffer[0] = 'a';
    
        SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    }

    The past issue turned out (thanks to the advice of the members of this community ;-) ) to be FaultISR after entering SysCtlClockSet function. However, in fact, the problem was entering any function, as entering any function led to FaultISR. It has just happened that clock setting was the first function called in the main procedure.

    That is why my concept of explanation was that declaring a large block of data as a local variable in a function caused heap overflow and further led to FaultISR while calling another function.

    I am not an experienced programmer, thus I'm asking for your opinion, as I really would like to understand what is going on and why.

  • I can pretty much guarantee that I'm not best one qualified here to fully answer.

    I can tell you that we often store such arrays w/in the flash memory - or when it's "font image storage" we place it w/in external, quad, SPI flash - which places minimal demand upon MCU's memory. (and speeds on-going compiling during program development)

    Google K & R, that's the "C" bible - look for code examples close to your desire - and experiment. Experimentation usually proves the best method for your (real) understanding as you have complete control over each aspect of your program & can immediately note the impact of change...