Giter Site home page Giter Site logo

arm-none-eabi-startup's Introduction

arm-none-eabi-startup

Startup code, vector tables and default exception/interrupt handlers for various uCs

Supported families

STM32

  • STM32F10x
  • STM32F2xx
  • STM32F3xx
  • STM32F4xx
  • STM32F7xx
  • STM32L0xx
  • STM32L1xx
  • STM32L4xx
  • STM32F0xx
  • STM32F0xx
  • STM32H7xx

NXP

  • LPC17xx
  • LPC40xx

EFM32

  • EFM32G
  • EFM32GG
  • EFM32HG
  • EFM32JG
  • EFM32LG
  • EFM32PG
  • EFM32TG
  • EFM32WG
  • EFM32ZG
  • EZR32LG
  • EZR32WG

Requirements

Library requires the following symbols to be defined in the user's linker script:

__top_of_stack : end of RAM area where stack located
__idata_start  : start of initializers section
__data_start   : start of initialized data section
__data_end     : end of initialized data section
__bss_start    : start of zero-filled data section
__bss_end      : end of zero-filled data section

Startup

Startup code is unified and very simple. It consists of Reset_Handler and two weak initialization functions.

Reset handler

//------------------------------------------------------------------------------
void Reset_Handler()
{
    if( __low_level_init() )
    {
        memcpy(__data_start, __idata_start, __data_end - __data_start); // copy initialized variables
        memset(__bss_start, 0, __bss_end - __bss_start);                // zero-fill uninitialized variables
        __libc_init_array();                                            // low-level init & ctor loop
    }
    main();
}
//------------------------------------------------------------------------------

Initialization functions

//------------------------------------------------------------------------------
__attribute__ ((weak))
void _init()
{
}
//------------------------------------------------------------------------------
int __low_level_init()
{
    return 1;
}
//------------------------------------------------------------------------------

At first, __low_level_init() function called. The function by default returns 1 that means to perform initialization of RAM data objects. The user can override this function - in particular, to set up clock speed, check type of start ('cold', 'warm', etc.) and return 0 if required that causes skip of initialization.

The second initialization function _init() called from __libc_init_array()1 just before calling of global class-object constructors.

This flexible approach allows for the user to run custom initialization code to satisfy user's project demands.

Debug and Release options

Default handler stubs

Vector table uses weak handler stubs that can be overrided in the user's project code. There are two sets of the stubs - for debug and release configurations. Debug configuration includes sepatate 'empty' function for each handler:

__attribute__ ((noreturn))
static void default_handler() { for(;;) { } }

and special function for HardFault_Handler:

static void hf_handler()
{
    volatile int i = 0;         //  debug variable: set non-zero value to 
    while(!i) { }               //  return from handler - this figures out 
                                //  an address where HW fault raised
}

Such code allows the user to change value of internal variable i to cause return from the handler and, therefore, jump to program address where Hard Fault occured.

In release configuration all vector table addresses point to the same default handler. This reduces code memory consumption.

Control

By default, debug configuration is turned on. The user can switch release configuration by definition of NDEBUG macro with -D command line option.


[1] Library function from GCC toolchain.

arm-none-eabi-startup's People

Contributors

antongus avatar harryzhurov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

arm-none-eabi-startup's Issues

неиспользуемый код в vectable.c

Здравствуйте.

Занесите, пожалуйста, hf_handler() под ifndef NDEBUG.

Сейчас релизная версия собирается с предупреждением:
../Drivers/System/vectable.c:118:13: warning: 'hf_handler' defined but not used [-Wunused-function]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.