lpcware

Hardfault, after adding USB stack

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by jeshwanth on Thu Jan 22 22:47:13 MST 2015
Hello List,

I am working on LPC1768 board. I have integrated USB stack to our software stack, after integrating it started failing (hardfault) initial stages like initialization itself.

There are many cases where I am getting hardfaults, I would like to explain one case here.

There is a Global variable called XYZ (It's a struct). As this variable comes in .data section, while copying the .data from flash it's copying wrong value. one of the value must be zero-0 but it's copying some junk value 9502977. So my program getting failed.

Ok, now lets consider I am moving the XYZ to flash by making it const. Then the program fails in next variable which is getting used after some 30 instruction from the previous fail point.

This behaviour  I found after adding my USB stack into it, before that it works normally.

This is my size command output.
   text   data    bss    dec    hexfilename
  71936   1800  26204  99940  18664Output/App/project.axf

And I am using FreeRTOS as the RTOS and this is failing before creating FreeRTOS tasks I mean initialization itself.

As many people told, there might be problem with Linker script. So I am posting the Ld script here.
/*
* GENERATED FILE - DO NOT EDIT
* (C) Code Red Technologies Ltd, 2008-2014
* Generated linker script file for LPC1768
* Created from generic_c.ld (vLPCXpresso v5.2 (4 [Build 2122] [2013-04-29] ))
* By LPCXpresso v5.2.4 [Build 2122] [2013-04-29]  on Thu Jun 19 10:46:14 IST 2014
*/


GROUP(
libcr_nohost.a
libcr_c.a
libcr_eabihelpers.a
)

MEMORY
{
  /* Define each memory region */
  MFlash512 (rx) : ORIGIN = 0x0000, LENGTH = 0x80000
  RamLoc32 (rwx) : ORIGIN = 0x10000000, LENGTH = 0x8000 /* 32k */
  RamAHB32 (rwx) : ORIGIN = 0x2007c000, LENGTH = 0x8000 /* 32k */

}
  /* Define a symbol for the top of each memory region */
  __top_RamLoc32 = 0x10000000 + 0x8000;
  __top_RamAHB32 = 0x2007c000 + 0x8000;


ENTRY(ResetISR)

SECTIONS
{

    .text_Flash2 : ALIGN(4)
    {
       FILL(0xff)
    *(.text_Flash2*)
    *(.text_MFlash512_246*)
    } > MFlash512_246
   
    /* MAIN TEXT SECTION */   
    .text : ALIGN(4)
    {
        FILL(0xff)
        __vectors_start__ = ABSOLUTE(.) ;
        KEEP(*(.isr_vector))
       
        /* Global Section Table */
        . = ALIGN(4) ;
        __section_table_start = .;
        __data_section_table = .;
        LONG(LOADADDR(.data));
        LONG(    ADDR(.data)) ;
        LONG(  SIZEOF(.data));
        LONG(LOADADDR(.data_RAM2));
        LONG(    ADDR(.data_RAM2)) ;
        LONG(  SIZEOF(.data_RAM2));
        __data_section_table_end = .;
        __bss_section_table = .;
        LONG(    ADDR(.bss));
        LONG(  SIZEOF(.bss));
        LONG(    ADDR(.bss_RAM2));
        LONG(  SIZEOF(.bss_RAM2));
        __bss_section_table_end = .;
        __section_table_end = . ;
        /* End of Global Section Table */
       

        *(.after_vectors*)
       
    } >MFlash512
   
    .text : ALIGN(4)   
    {
         *(.text*)
        *(.rodata .rodata.*)
        . = ALIGN(4);
       
    } > MFlash512

    /*
     * for exception handling/unwind - some Newlib functions (in common
     * with C++ and STDC++) use this.
     */
    .ARM.extab : ALIGN(4)
    {
    *(.ARM.extab* .gnu.linkonce.armextab.*)
    } > MFlash512
    __exidx_start = .;
   
    .ARM.exidx : ALIGN(4)
    {
    *(.ARM.exidx* .gnu.linkonce.armexidx.*)
    } > MFlash512
    __exidx_end = .;
   
    _etext = .;
       
   
    /* DATA section for RamAHB32 */
    .data_RAM2 : ALIGN(4)
    {
       FILL(0xff)
    *(.data.$RAM2*)
    *(.data.$RamAHB32*)
       . = ALIGN(4) ;
    } > RamAHB32 AT>MFlash512
   
    /* MAIN DATA SECTION */
   

    .uninit_RESERVED : ALIGN(4)
    {
        KEEP(*(.bss.$RESERVED*))
        . = ALIGN(4) ;
        _end_uninit_RESERVED = .;
    } > RamLoc32


/* Main DATA section (RamLoc32) */
.data : ALIGN(4)
{
   FILL(0xff)
   _data = . ;
   *(vtable)
   *(.data*)
   . = ALIGN(4) ;
   _edata = . ;
} > RamLoc32 AT>MFlash512

    /* BSS section for RamAHB32 */
    .bss_RAM2 : ALIGN(4)
    {
    *(.bss.$RAM2*)
    *(.bss.$RamAHB32*)
       . = ALIGN(4) ;
    } > RamAHB32

    /* MAIN BSS SECTION */
    .bss : ALIGN(4)
    {
        _bss = .;
        *(.bss*)
        *(COMMON)
        . = ALIGN(4) ;
        _ebss = .;
        PROVIDE(end = .);
    } > RamLoc32
       
    /* NOINIT section for RamAHB32 */
    .noinit_RAM2 (NOLOAD) : ALIGN(4)
    {
    *(.noinit.$RAM2*)
    *(.noinit.$RamAHB32*)
       . = ALIGN(4) ;
    } > RamAHB32
   
    /* DEFAULT NOINIT SECTION */
    .noinit (NOLOAD): ALIGN(4)
    {
        _noinit = .;
        *(.noinit*)
         . = ALIGN(4) ;
        _end_noinit = .;
    } > RamLoc32
   
    PROVIDE(_pvHeapStart = .);
    PROVIDE(_vStackTop = __top_RamLoc32 - 0);
}


But I found everything fine in ld script.

Can anybody help me in fixing this ?

Thanks in Advance :)

Outcomes