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.

CCS/EK-TM4C1294XL: HardFault_Handler problem in Tiva C series

Other Parts Discussed in Thread: EK-TM4C1294XL

art Number: EK-TM4C1294XL

Tool/software: Code Composer Studio

    I am using TM4C123GXL and Keil IDE to generate a formula.I had initialized array which has 5000 elements.  And I used qsort function from the c library.  But when I tried to run this code without qsort , the code is working. (it is working so slow).  After I open the qsort function the program is going to an endless loop called hard fault handler and waits at the instruction B and also I can`t able to stop this instruction.

HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler         [WEAK]
                B       .
                ENDP 

I am attaching my rar file with this. Actually my project is little bit in complete because I had trying to vary the duty cycle for only one signal even though I want 8 PWM's.What I am done here is to just check the first condition and failed to execute want solution.

  • I don't have the Keil IDE so I cannot reproduce your problem. I suspect that you might need to increase your heap or stack size. Here is some information on debugging a fault condition:

    http://www.ti.com/lit/an/spma043/spma043.pdf

  • Dear Bob,

    Thanks for your reply.  Yes, the problem most probably is related heap or stack size.  But I don`t understand why the problem is related heap or stack. 

    I had just initialized array has 5000 elements.  And I tried the same code on another development board (metro m4) and it worked successfully.

    In addition, I increased the stack size from compiler settings but the problem repeated.

    if you have the CCS IDE I can share the code which is written for CSS 

    Thanks for your helping.

    Best Regards

    Ufuk Demirel

     

     

  • Hi Ufuk,

      Bob is out of office for a week. I will try to help you.

       Every time a function declares a new local variable, it is "pushed" onto the stack. 5000 elements will take up quite some memory space. What is the size of each element (i.e. 8-bit, 16-bit or 32-bit)? How much stack did you declare? Is your qsort function recursive? If each element is 32-bit then just the 5000 elements will take up 20kB of memory let alone other variables you might declared in the same function. Please bear in mind that there is only 32kB of system memory in the device. How much memory does the metro m4 have? Perhaps it has more system memory than TM4C123.  

  • Hi Charles,

    Thank you for your understanding.  

    The size of each element is 32 bit (integer).  My qsort function recursived to qsort the array has 500 element (almost 5000 times)  The metro me4 has 192 kb ram. 

    You can find the compiler settings in the attachment or above.  I tried to compile and test on Keil and ccs. But the problem repeated.

    Best Regards 

    Ufuk

      

  • Hi,

      What is the stack size you declare? It doesn't show on your screenshot.

      I don't know exactly how many elements are pushed onto the stack. 500 elements recursively called 5000 times will can easily overflow the stack. As I noted before there is only 32kB of SRAM on this device. 

      At what number of elements does it run successfully? Can you try 50 elements first and gradually increase the number of elements until it starts to overflow at which time the hard fault will occur. 

      Do you have the TM4C129 launchPad? The TM4C129 has 256kB of on chip SRAM. Please try it if you have the launchPad. Again, if your application requires more than 32kB of memory then the TM4C123 is not the right choice for you.

      

      

  • Hi,

      I have not heard back from you. I hope my prior post answered your question concerning the physical limitation of the MCU as far as how much stack can be allocated. If your application requires more than the available SRAM on the MCU, your choice of actions will be to either look for a MCU with bigger memory or somehow take different approach on your search algorithm to reduce the stack usage.  I will close this thread for now. If your issue is not resolved, you can just reply back to this post to reopen the thread. 

  • Hi,

    Sorry for my late answer. I was out of the office. How can I learn stack size from code compressor?   

     I tried the code on the TMC1294 launchpad. (http://www.ti.com/tool/EK-TM4C1294XL) But the problem repeated.

    You can find the code below which creates a problem. 

      for (j = 0; j < 5000; j++)
      {
        for (i = 0; i <= SAMPLECOUNT; i++)
          sampleArray[i] = koridorArray[j + i];
          qsort(sampleArray, SAMPLECOUNT + 1, sizeof(int), cmpfunc);
    
        tempValue = sampleArray[50];
        if (tempValue > maxValueofKoridor)
        {
          maxValueofKoridor = tempValue;
          numberofKoridor = j;
        }
      }

  • Hi,

      

      At what number of elements does it run successfully? Can you try 50 elements first and gradually increase the number of elements until it starts to overflow at which time the hard fault will occur?

     I'm not familiar with Keil. You should be able to find the similar setting (from CCS) as shown below to play with the code size vs speed. Tune to the setting for smallest code size. 

      

  • Hi Charles,

    I changed the stack size from startup_TM4C129.s file. Firs value was 0x0000200 and I updated as 0x1000. I increased five times. 

    ; <h> Stack Configuration
    ;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
    ; </h>
    
    Stack_Size      EQU     0x00001000    ; it was 0x200 
    
                    AREA    STACK, NOINIT, READWRITE, ALIGN=3
    Stack_Mem       SPACE   Stack_Size
    __initial_sp

    And the problem is solved. The device is working in spite of slow. I guess I need to change the main clock frequency to works faster. How can I change the main clock frequency to work faster?

    Thanks for helping

  • Hi,

      What is your current frequency? You can configure the device to run at the maximum of 80MHz for TM4C123 as follows. 

    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
    SYSCTL_OSC_MAIN);

       If you are using the EK-TM4C1294XL board then you can achieve the maximum frequency of 120MHz as follows.

    g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                  SYSCTL_OSC_MAIN |
                                  SYSCTL_USE_PLL |
                                  SYSCTL_CFG_VCO_480), 120000000);

     

      

  • ***LIKE***

    Vendor's Charles has both correctly diagnosed & resolved (another) poster issue.

    Poster claimed to have used ''123 MCU" w/in his initial post - yet his Subject Line noted '129!'   

    Later he (appeared) to have switched to '129 board - Charles has provided the 'key' to 'Full System Clock Speed' for (both) MCUs - that's well done!