SAME 70 main() never reached

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I am using a SAME70Q19 together with Atmel Studu 7.0 and my problem is the following:

I created a User Board project and after flashing the device  I jump into the Reset_handler()

in startup_same70.c. I can  step through untill "__libc_init_array()"; From here I jump

into Dummy_Handler(void) because of HardFault Error. I never come to main().

What went wrong?

Atmel Studio 7.0.1417

ASF 3.34.1

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Google "Hard Fault" and "Hard Fault Handler" - there are many references to debugging Hard Faults from the information available in the Hard Fault Handler ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did it but I could not found out why it jumps into hard fault handler because my c library isn't initialized at this point.

right now I think it has something to do with my linker file.

Could someone please send me an old linker file for an ATSAME70Q19? I think there is a bug in the new release of Atmel Studio. 

The default linker file is:

 

/**
 * \file
 *
 * Copyright (c) 2015 Atmel Corporation. All rights reserved.
 *
 * \asf_license_start
 *
 * \page License
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. The name of Atmel may not be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * 4. This software may only be redistributed and used in connection with an
 *    Atmel microcontroller product.
 *
 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * \asf_license_stop
 *
 */

/*------------------------------------------------------------------------------
 *      Linker script for running in internal FLASH on the ATSAME70Q19
 *----------------------------------------------------------------------------*/

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)

/* Memory Spaces Definitions */
MEMORY
{
  rom (rx)  : ORIGIN = 0x00400000, LENGTH = 0x00080000
  ram (rwx) : ORIGIN = 0x20400000, LENGTH = 0x00040000
}

/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : 0x2000;
__ram_end__ = ORIGIN(ram) + LENGTH(ram) - 4;

/* The heapsize used by the application. NOTE: you need to adjust according to your application. */
HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : 0x200;

/* Section Definitions */
SECTIONS
{
    .text :
    {
        . = ALIGN(4);
        _sfixed = .;
        KEEP(*(.vectors .vectors.*))
        *(.text .text.* .gnu.linkonce.t.*)
        *(.glue_7t) *(.glue_7)
        *(.rodata .rodata* .gnu.linkonce.r.*)
        *(.ARM.extab* .gnu.linkonce.armextab.*)

        /* Support C constructors, and C destructors in both user code
           and the C library. This also provides support for C++ code. */
        . = ALIGN(4);
        KEEP(*(.init))
        . = ALIGN(4);
        __preinit_array_start = .;
        KEEP (*(.preinit_array))
        __preinit_array_end = .;

        . = ALIGN(4);
        __init_array_start = .;
        KEEP (*(SORT(.init_array.*)))
        KEEP (*(.init_array))
        __init_array_end = .;

        . = ALIGN(0x4);
        KEEP (*crtbegin.o(.ctors))
        KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
        KEEP (*(SORT(.ctors.*)))
        KEEP (*crtend.o(.ctors))

        . = ALIGN(4);
        KEEP(*(.fini))

        . = ALIGN(4);
        __fini_array_start = .;
        KEEP (*(.fini_array))
        KEEP (*(SORT(.fini_array.*)))
        __fini_array_end = .;

        KEEP (*crtbegin.o(.dtors))
        KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
        KEEP (*(SORT(.dtors.*)))
        KEEP (*crtend.o(.dtors))

        . = ALIGN(4);
        _efixed = .;            /* End of text section */
    } > rom

    /* .ARM.exidx is sorted, so has to go in its own output section.  */
    PROVIDE_HIDDEN (__exidx_start = .);
    .ARM.exidx :
    {
      *(.ARM.exidx* .gnu.linkonce.armexidx.*)
    } > rom
    PROVIDE_HIDDEN (__exidx_end = .);

    . = ALIGN(4);
    _etext = .;

    .relocate : AT (_etext)
    {
        . = ALIGN(4);
        _srelocate = .;
        *(.ramfunc .ramfunc.*);
        *(.data .data.*);
        . = ALIGN(4);
        _erelocate = .;
    } > ram

    /* .bss section which is used for uninitialized data */
    .bss (NOLOAD) :
    {
        . = ALIGN(4);
        _sbss = . ;
        _szero = .;
        *(.bss .bss.*)
        *(COMMON)
        . = ALIGN(4);
        _ebss = . ;
        _ezero = .;
    } > ram

    /* stack section */
    .stack (NOLOAD):
    {
        . = ALIGN(8);
        _sstack = .;
        . = . + STACK_SIZE;
        . = ALIGN(8);
        _estack = .;
    } > ram

    /* heap section */
    .heap (NOLOAD):
    {
        . = ALIGN(8);
         _sheap = .;
        . = . + HEAP_SIZE;
        . = ALIGN(8);
        _eheap = .;
    } > ram

    . = ALIGN(4);
    _end = . ;
    _ram_end_ = ORIGIN(ram) + LENGTH(ram) -1 ;
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I could solve the problem by putting TCM Configuration in the startup code. Now __libc_init_array() is called and I finally jump into main();

 

I put this before __libc_init_array();

 

	/* TCM Configuration */
		EFC->EEFC_FCR = (EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_CGPB | EEFC_FCR_FARG(8));
		EFC->EEFC_FCR = (EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_CGPB | EEFC_FCR_FARG(7));

		__DSB();
		__ISB();
		SCB->ITCMCR &= ~(uint32_t)(1UL);
		SCB->DTCMCR &= ~(uint32_t)SCB_DTCMCR_EN_Msk;
		__DSB();
		__ISB();

 

Last Edited: Thu. Apr 13, 2017 - 08:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Turned out that this did not solve the problem. After entering this code my system crashes after a few seconds and makes a software reset.

Something seems to be wrong with the memory map.

Can somebody help me?

Is somebody able to build a brand new ASF Example Project for ATSAME70 with ASF Modules System Clock Control and Generic board support

without getting stuck in the reset handler???

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Like the attached or something else? I tried a few bare board projects and some clock examples, seems ok, this is with a SAME70 Xplained.

/Lars

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, like the attached. What is the default value of your GPNVMBITS? I always start with 0x82.

If so I don't reach main. Only with 0x02.

You don't have a SAME70Q19? Right now I don't know if it is the toolchain or the controller.

I will post an example project from ASF. Of course I chanched my clock settings because I

have an eternal clock.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I read in the datasheet that it should start with 0x02 by default. I start with 0x82. Is there a way to save the GPNVMBITS so that

they are non-volatile?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I only have the SAME70 Xplained and with your project (after changing device) I also have a restart after a few seconds with your project, looks like the watchdog is active i.e. you should 

    /* Disable the watchdog */
    WDT->WDT_MR = WDT_MR_WDDIS;

as is done in board_init for the Xplained.

0x82 or 0x02 for GPNVMBITS ? I have seen both now, did not investigate but I would have guessed this is non-volatile. Can be programmed in Device programming and atprogram according to
https://community.atmel.com/forum...

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Angelus,

 

I have the same problem, did you solve it?

 

Code that worked fine on a SAME70N20 with a custom board will not run on our new board. The changes to the PCB are absolutely minimal (one I/O is no longer connected).

I am using the same compiler, programmer and ELF-file.

 

What is interesting is that the MCU that works has date code 1548, and the new one is marked 1709. Wonder if something is wrong with the MCU...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

add this in the startup file a the beginning, if you not using the tcm sections it should help you, let me know.

 

 

void Reset_Handler(void)

{

        uint32_t *pSrc, *pDest;

 

EFC->EEFC_FCR = (EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_GGPB);

 

uint32_t ulEEFC_bits = EFC->EEFC_FRR;

  

if ((ulEEFC_bits & 0x180) != 0x0)

{

EFC->EEFC_FCR = (EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_CGPB 

| EEFC_FCR_FARG(8));

EFC->EEFC_FCR = (EEFC_FCR_FKEY_PASSWD | EEFC_FCR_FCMD_CGPB 

| EEFC_FCR_FARG(7));

// Trigger Reset

RSTC->RSTC_CR = RSTC_CR_KEY_PASSWD | RSTC_CR_PROCRST;

}

 

        /* Initialize the relocate segment */

 

then leave the code that is after this comment

 

 

 

howien

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a million, Howien, that did the trick.

 

So what is this about? Like I said, code that works on an MCU from 2015 no longer works on one that is made in 2017 (I tried several ones, and they all fail).

 

Is there a hardware bug, or is something missing in Atmel studio?

 

BR,

Dimlite

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This Problem seems to be introduced by AS 7.0.1417 somehow. The code above did not work on my side because my data size in SRAM is > 128kByte and the stack in the linker script is above 128kB. SRAM above 128kB is unreachable at boot time due to weird setting of GPNVM bits. I had to use static variables which are located in first 128kB.  Maybe this link will provide you some additional infos:

https://community.atmel.com/forum/code-stuck-resethandler-after-atmel-studio-upgrade-701417?skey=Reset handler 

SAME newbie

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

its all about the gpnvm bits, bits 8:7 control the allocation of sram to the "sram space" and the tcm regions. you may notice that the gpnvm bits sometimes display as 0x82 ... that in it's own right is wrong! that is only showing 8 bits, to view the gpnvm bits that matter we need to see 9bits.

 

i suspect when the code download takes place it modifies those bits, at reset they should be zero to allocate all the sram to "sram" and the rom is visible, so i suspect that is modified in the download to boot from flash , bit 1 of gpnvm and it messes with the other two bits 8:7.

howien

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it must work. i have the same, my sram was greater than 200k. the code download then limits the sram to 128k by setting the gpnvm bits 8:7. 

 

you can test it by using the atmel ice and manually modifying sram memory, above the 128k boundary you cannot modify it. with the change above you can.

howien

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

howien12 wrote:

its all about the gpnvm bits, bits 8:7 control the allocation of sram to the "sram space" and the tcm regions. you may notice that the gpnvm bits sometimes display as 0x82 ... that in it's own right is wrong! that is only showing 8 bits, to view the gpnvm bits that matter we need to see 9bits.

 

i suspect when the code download takes place it modifies those bits, at reset they should be zero to allocate all the sram to "sram" and the rom is visible, so i suspect that is modified in the download to boot from flash , bit 1 of gpnvm and it messes with the other two bits 8:7.

 

Ok, thanks for taking the time to explain. I am still wondering about the root cause, though. People on the net seems to blame it on Atmel studio and the Atmel-ICE. But I have not updated my version of Atmel studio since I installed it in 2015, and I can move back and forth between the problem just by switching the board between the old ones with MCU from 2015 and the new ones with MCU from 2017, with the exact same project and programmer.

 

The project uses most of the SRAM (we have an image sensor attached, which consumes a lot of RAM, there is only a few ten kilobytes left).

Regarding ASF, we only use the generic board support and EEFC.

 

It is really odd, but I don't have time to look into it for now, must go on with the development. If someone else is interested, the details for Astudio is below.

 

Thanks again for the help!

 

 

Atmel Studio 7 (Version: 7.0.1006 - )
© 2015 Atmel Corp.
All rights reserved.

OS Version: Microsoft Windows NT 6.2.9200.0
Platform: Win32NT

Installed Packages: Shell VSIX manifest - 7.0
Shell VSIX manifest
Version: 7.0
Package GUID: e874ffe4-fbe3-4624-9a17-61014ede02d0
Company: Atmel Corporation

Installed Packages: Atmel Start - 1.0.91.0
Atmel Start
Version: 1.0.91.0
Package GUID: F8853255-9C7B-4DC2-8E0F-64D9324AEB0E
Company: Atmel

Installed Packages: Atmel Software Framework - 3.31.0.497
ASF
Version: 3.31.0
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.31.0
Release Description: ASF - 3.31.0 Release

ASF
Version: 3.30.1
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.30.1
Release Description: ASF - 3.30.1 Release

ASF
Version: 3.30.0
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.30.0
Release Description: ASF - 3.30.0 Release

ASF
Version: 3.29.0
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.29.0
Release Description: ASF - 3.29.0 Release

ASF
Version: 3.28.1
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.28.1
Release Description: ASF - 3.28.1 Release

ASF
Version: 3.27.3
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.27.3
Release Description: ASF - 3.27.3 Release

ASF
Version: 3.27.0
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.27.0
Release Description: ASF - 3.27.0 Release

ASF
Version: 3.26.0
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.26.0
Release Description: ASF - 3.26.0 Release

ASF
Version: 3.25.0
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.25.0
Release Description: ASF - 3.25.0 Release

ASF
Version: 3.24.2
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.24.2
Release Description: ASF - 3.24.2 Release

ASF
Version: 3.23.1
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.23.1
Release Description: ASF - 3.23.1 Release

ASF
Version: 3.22.0
Package GUID: 4CE20911-D794-4550-8B94-6C66A93228B8
Company: Atmel
HelpUrl: http://asf.atmel.com/3.22.0
Release Description: ASF - 3.22.0 Release

 

Installed Packages: LiveWatch - 2.0.54
LiveWatch
Version: 2.0.54
Package GUID: 7DF6DCFD-2BCA-41C7-9C0E-1B7F606B008E
Company: Atmel

Installed Packages: GdbConsole - 7.0.154
GdbConsole
Version: 7.0.154
Package GUID: 49258291-0FED-4501-881B-6BAA91BEBCA8
Company: Atmel

Installed Packages: Atmel Kits - 7.0.70
Atmel Kits
Version: 7.0.70
Package GUID: 6F4B8FE4-C464-4916-8B43-AC92431C1CDF
Company: Atmel

Installed Packages: AtmelToolchainProvider - 7.0.891
AtmelToolchainProvider
Version: 7.0.891
Package GUID: AtmelToolchainProvider.Atmel.10EF9C74-D8DA-4872-85F5-D8BB3101E245
Company: Atmel

Installed Packages: Data Visualizer Extension - 2.6.475
Data Visualizer Extension
Version: 2.6.475
Package GUID: 25dc067d-df31-4e22-be7f-cc6a77ccc7f3
Company: Atmel

Installed Packages: Atmel Gallery - 7.8
Atmel Gallery
Version: 7.8
Package GUID: AtmelStudio7ExtensionManager
Company: Atmel

Installed Packages: Percepio Trace for Atmel Studio - 1.3
Percepio Trace for Atmel Studio
Version: 1.3
Package GUID: fe274744-c496-42fc-9e52-f77b92d669b1
Company: Percepio AB

Installed Packages: Visual Assist for Atmel Studio - 10.9.2093.2
Visual Assist for Atmel Studio
Version: 10.9.2093.2
Package GUID: 7997A33C-B154-4b75-B2AC658CD58C9510
Company: Whole Tomato Software