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.

How to increase stack size on Keil uVision for stellaris LM4F120 launchpad

Other Parts Discussed in Thread: LM4120

Hello all,

I want to increase my stack size. I am using Keil uVision IDE. The default value mentioned is Stack EQU 0x00000100;

How to modify this value to make it 1K stack ?

 

; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;
;******************************************************************************
Stack   EQU     0x00000100

;******************************************************************************
;
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
;
;******************************************************************************
Heap    EQU     0x00000000

;******************************************************************************
;
; Allocate space for the stack.
;
;******************************************************************************
        AREA    STACK, NOINIT, READWRITE, ALIGN=3
StackMem
        SPACE   Stack
__initial_sp

;******************************************************************************
;
; Allocate space for the heap.
;
;******************************************************************************
        AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
HeapMem
        SPACE   Heap
__heap_limit

I have already tried to write 0x00001000 to make it 1K, I also tried 0x00000000 but it doesnt work.

  • Hello Sahil,

    Please see the post below

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/329697/1148648.aspx#1148648

    Also I changed the stack size in one of the TIVAware sample projects in the same manner as you specified and the map file shows the new stack size correctly.

    BTW, 0x1000 is 4096 bytes and not 1024 bytes as you wanted. For that it should be 0x400


    Regards

    Amit

  • Dear Amit,

    Thank you for your valuable comments.

    Actually my code is working well in CCS but it doesnt work in Keil. I am using UARTprintf function and therefore I doubted if that could be due to stack. So I increased the stack but still it doesnt work.

    The moment when it receives the interrupt it jumps to the following interupt.

    ; This is the code that gets called when the processor receives an unexpected
    ; interrupt. This simply enters an infinite loop, preserving the system state
    ; for examination by a debugger.
    ;
    ;******************************************************************************
    IntDefaultHandler
    B IntDefaultHandler

    The same code works fine in CCS even with a stack size of 250 bytes only.

    A very important point is,  if I donot call any function from "utils/uartstdio.h" it works fine and i get communication on UART with the ISR.

    Alternatively, if I use utils/uartstdio.h and disable the ISR the code starts running.

    As a summary;

    1. In keil the code works fine if I do not use utils/uartstdio.h.
    2. If I use utils/uartstdio.h (even without calling uartprintif function) just to enable the UART with ISR Enabled, the code stops and jumps to the highlighted region mentioned above.
    3. If I use utils/uartstdio.h and Disable the the ISR, the code starts working.
    4. In a simple way, The system enters the above mentioned loop if I use  utils/uartstdio.h with ISR Enabled

    For me, all that are symptoms of Stack limitations, as I said I increased the stack size and the heap size to 1k (0x400H) but still not working.

    Although the same code is working in CCS with a stack size of only 250 bytes.

    Any idea ??

    void inituart0(void)
    {
    	volatile int temp;
     // Enable the peripherals used by this example.
           
      SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
      SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    	
      GPIOPinConfigure(GPIO_PA0_U0RX);
      GPIOPinConfigure(GPIO_PA1_U0TX);
      GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Configure the UART for 115,200, 8-N-1 operation.
        // This function uses SysCtlClockGet() to get the system clock
        // frequency.  This could be also be a variable or hard coded value
        // instead of a function call.
        //
      UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
      temp = SYSCTL_RCGC0_R;
      //UARTStdioConfig(0, 115200, SysCtlClockGet());
      temp = SYSCTL_RCGC0_R;
      UARTStdioInit(0);
      //UARTStdioInitExpClk(0, 115200);
    		
    
    
    }
    

    and the main file is;

    #define TARGET_IS_BLIZZARD_RA1
    #include "inc/hw_types.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/lm4f120h5qr.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/timer.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/uart.h"
    #include "driverlib/rom.h"
    #include "customlibraries/myuart.h"
    #include "driverlib/rom_map.h"
    #include <string.h>
    #include "utils/uartstdio.h"
    #include "customlibraries/myadc.h"
    
    #define LED_RED    0x02		//PF1(Red)
    #define LED_BLUE   0x04		//PF2(Blue)
    #define LED_GREEN  0x08		//PF3(Green)
    
    extern void IntGPIOF(void);
    
    int main(void)
    {
    	volatile unsigned int ulLoop;
    	volatile unsigned long adcvalue;
    	
    	SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    	
    
    	// Enable the GPIO port F.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
    	//SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
    	//SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOE;
    	ulLoop = SYSCTL_RCGC2_R; //Some delay to stabilize the clock on the GPIO E and F modules
    
    	GPIO_PORTF_DIR_R |= 0x0EU;	
    	GPIO_PORTF_DEN_R |= 0x0EU;	
    	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |GPIO_PIN_3);
    
    	//Initialize UART0
    	inituart0();
    
    
    	UARTprintf("\r\nWELLCOME...\r\n");
    
    
    	initadc();
    	
    	//adcvalue = readadc(AIN8); //PE5
    
            //Enable interrupt on PF4
    	GPIOPortIntRegister(GPIO_PORTF_BASE,IntGPIOF);
    	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
    	GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
    	GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE);
    	GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_4);
    	IntMasterEnable();
    
    	while(1)
    	{
    		//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0xE);
    		GPIO_PORTF_DATA_R = 0x00;
    		for(ulLoop = 0; ulLoop < 1800000; ulLoop++){ }
    
    		GPIO_PORTF_DATA_R |= LED_RED;
    		for(ulLoop = 0; ulLoop < 1800000; ulLoop++){ } // Delay for a bit.
    		GPIO_PORTF_DATA_R = 0x00;
    
    		for(ulLoop = 0; ulLoop < 1800000; ulLoop++){ }
    		GPIO_PORTF_DATA_R |= LED_GREEN;
    		for(ulLoop = 0; ulLoop < 1800000; ulLoop++){ }
    		GPIO_PORTF_DATA_R = 0x00;
    
    		for(ulLoop = 0; ulLoop < 1800000; ulLoop++){ }
    		GPIO_PORTF_DATA_R |= LED_BLUE;
    		for(ulLoop = 0; ulLoop < 1800000; ulLoop++){ }
    
    
    	}
    
    
    }
    
    void IntGPIOF(void)
    {
    	volatile unsigned long adcvalue;
    	volatile int ulLoop;
    	
    	GPIO_PORTF_DATA_R = 0x00;
    	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0xE);
            for(ulLoop = 0; ulLoop < 900000; ulLoop++){ }
    
    	//Take the ADC reading on PE5
    	adcvalue = (33*readadc(AIN8))*1000/40950; //ADC pin on PE5
    	//adcvalue = 256;
    
            //Print it
    	UARTprintf("\r\nVoltage read: %dmVolt", adcvalue);
    	
            //Clearing the flag at the end of the routine because of NOT having Debounce implementation
    	GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_4);
    }
    

  • Dear all,

    I am attaching the complete project as I am unable to understand the problem. Kindly have a look at the map file or the html file as it says 

    Maximum Stack Usage = 48 bytes + Unknown(Functions without stacksize, Cycles, Untraceable Function Pointers)

    Find the attachment please.4572.Interrupt+UART+ADC.zip

  • Hi Sahil,

         I have set the stack size to 1KB of my uart_echo example program for Tiva Connected Launchpad. I compiled uart_echo without errors.

         I have seen your attached project files. It seems this line below is commented out at startup file. You, are setting up interrupts for PF4. But, no interrupt handlers at your main code. Also, the interrupt handler is not setup at your startup file.

        ;        DCD     IntDefaultHandler           ; GPIO Port F

    - kel

  • Hello Kel,

    The code calls the GPIOPintIntRegister which will copy the Interruot Vector Table to SRAM and then map the new interrupt handler for GPIO Port-F. But however it is a good point that the startup file has a commented GPIO Port-F handler which should not be done.

    Hello Sahil,

    In the code I do not see the UART Interrupt Handler being Registered the way you have done for GPIO Port-F. That would be the problem that on an interrupt it goes to the default interrupt handler.

    Regards

    Amit

  • Dear Amit,

    I tried to uncomment  the "DCD     IntDefaultHandler           ; GPIO Port F" and then I tried to comment just to see any difference. In either case it dosent work.

    As I said if i do not call any function from utils/uartstdio.h. It starts working and the interrupt works fine.

  • Hello Sahil,

    Thanks for confirming that the startup file did not have an issue. I checked the zip file that you had attached, however it had paths for some of the files that I do not have. Can you zip the C files after the modification which cause the issue. I can have a look at them.

    Also do sent the copy of the uartstdio.c in the zip package.

    As far as I know if the define UART_BUFFERED is used then the UART Interrupt Handler is enabled which would cause the code to jump to the default interrupt handler.

    Regards

    Amit

  • Hello Robregado,

    I have tried uncommenting and commenting out to see the difference, but doesnt work.

    One point I dont understand since the startup file is in assembly, when i replace

    DCD     IntDefaultHandler           ; GPIO Port F

    with

    DCD     IntGPIOF                      ; GPIO Port F

     

    The compiler doesnt recognise "IntGPIOF", since the startup file is in assembly so where/how should I declare the "IntGPIOF" . I am already declaring it in main().

    But as I said, I do not modify any single line of the startup file if I dont call any function of utils/uartstdio.h , the whole code starts working and i can see UART communicating with my PC.

  • Hello Amit,

    As you said "if the define UART_BUFFERED is used then the UART Interrupt Handler is enabled which would cause the code to jump to the default interrupt handler."

    It arises a question why the same code works fine in CCS !!

    You can also verify the code and the interrupt handler starts working by commenting all functions of utils/uartstdio.h.

    Please find the attachment for the missing files.

    0876.temp.zip

  • Hi Sahil,

         I have a uart_echo example program that uses uartstdio, and it compiles without error. The uart_echo is for Tiva Connected Launchpad.

         What I suggest you should do is use a known working example program for your launchpad such as uart_echo and just append your code. This way you don't have to worry about any project settings. I checked your Keil project settings and it is missing the "rvmdk" preprocessor define. At a working uart_echo example program for LM4120 Launcpad, these are the preprocessor defines below.

         rvmdk PART_LM4F120H5QR TARGET_IS_BLIZZARD_RA1

         I suggest you use the latest Tivaware for your Tiva Launchpad. Also, when adding uartstdio.c at your project, add it under "libraries".

    - kel

  • Hello Kel

    Both are already added.

  • Hello Sahil

    The code looks fine. One of the things you need to check is the manner in which the defines are placed in CCS and Keil, It is possible for the project settings to have it one toolchain and not the other.

    What I would suggest it to comment the UARTIntEnable function in the uartstdio.c and then run the test. Basically the idea is to check that the UARTIM bits "must" not be set. If it still gets set, then besides debugging we can add SysCtlPeripheralReset to the main code to reset UART-0 before initializing it

    Regards

    Amit

  • Hi Amit,

    I reset the peripheral as suggested, still no outcome.

    Actually this is the same code with same sequences I copied from Keil uvision to CCS and it worked. I re-verified the the manner/sequences and they are the same.  

    I have also made some changes i.e. in the startup file I added " IMPORT IntGPIOF" and replaced the default name of the interrupt for PortF with IntGPIOF but not helping.

    I commented UARTIntEnable which is called, the code still goes to the same loop and stucks there.

    I am completely out of questions now !

    There is one important point that you raised ; "if the define UART_BUFFERED is used then the UART Interrupt Handler is enabled which would cause the code to jump to the default interrupt handler" but follwoing the above modifications it should have some how impact on that.

    Alternatively, If this issue doesnt get fixed, I am thinking to switch to CCS to work, the only thing about CCS, I dont like is you can not make a copy of existing project and reload it as a new project. Any suggestion ?

  • Hello Sahil,

    This is indeed very strange. May be some IDE subtlety that I am missing. I don't like why Keil would be doing. Since the first zip project had broken paths, if you can correct the same, I would want to debug and close this issue. All the steps including the UARTIntEnable seem to be correctly done

    As for migrating to CCS, you can make a copy of the project, rename it in the CCS IDE environment and use it. I have been doing for months now.

    Regards

    Amit

  • Sahil

    See, the difference in options. The left one is your Keil project. The one at the right is a working uart_echo example program.

  • Amit,

    I am sending you all the project with all the required files in single zip. I suggest to also have a look at the html file that has some important question marks, might be useful in diagnosing the issue.

    4452.temp.zip

  • Hello Robregado,

    I tried the same as you have done,

    The missing preprocessor I have defined in the main() instead. So it is the same then.

    The only missing Tick (i.e. ELF section.....), I just clicked (enabled) but no output.

  • Hello Sahil,

    The project zip file have custom paths to different source files and driverlib from StellarisWare. Took me some time to correct all of them (except main.c and startup.s). First thing obviously was there a customer driverlib, that needed to be replaced with stellarisware version of the driverlib.

    Are you sure the files especially the pre compiled lib file are from StellarisWare rvmdk-lm4f?

    Regards

    Amit

  • Problem fixed :)

    Changed the driver lib of Keil to the one which is for CCS I usually use, It fixed the problem though apparently the drivers look the same.

    Amit I thank you for your efforts, you raised quite important points.

    Robregado I thank you too for your comments and valuable information.

  • Hello Sahil,

    Now that does baffle me. Could it be some DB copy issue?

    Regards

    Amit

  • Hi Amit,

    Well for me it looks some difference in one of the lib files, It could also be some DB issue but since you have seen I dont use the usual approach of changing the Default vector name instead I tie the ISR with the API function i.e. GPIOPortIntRegister(GPIO_PORTF_BASE,IntGPIOF); which is an alternative to bypass the required modification hence it doesnt make sense to have any problem with DB !!

     

    However, I am not sure !