title: Can't debug after using SysTick_Config
body: <p>I - an embedded beginner - am fighting my way through the black magic world of embedded programming. So far I won already a bunch of fights, but this new bug seems to be a hard one.</p>
  
  <p>First, my embedded setup:</p>
  
  <ul>
  <li>Olimex STM32-P207 (STM32F207)</li>
  <li>Olimex ARM-USB-OCD-H JTAG</li>
  <li>OpenOCD</li>
  <li>Eclipse (with CDT and GDB hardware debugging)</li>
  <li>Codesourcery Toolchain</li>
  <li>Startup file and linker script (adapted memory map for the STM32F207) for RIDE (what uses GCC)</li>
  <li>STM32F2xx_StdPeriph_Lib_V1.1.0</li>
  </ul>
  
  <p>Using the many tutorials and Q&amp;As out there I was able to set-up makefile, linker and startup code and got some simple examples running using STM's standard library (classic blinky, using buttons and interrupts etc.). However, once I started playing around with the SysTick interrupts, things got messy.</p>
  
  <p>If add the SysTick_Config() call to my code (even with an empty SysTick_Handler), ...</p>
  
  <pre><code>int main(void)
  {
    /*!&lt; At this stage the microcontroller clock setting is already configured, 
         [...]
    */
    if (SysTick_Config(SystemCoreClock / 120000))
    {
      // Catch config error
      while(1);
    }
  [...]
  </code></pre>
  
  <p>... then my debugger starts at the (inline) function NVIC_SetPriority() and once I hit "run" I end up in the HardFault_Handler().
  This only happens, when using the debugger. Otherwise the code runs normal (telling from the blinking LEDs).</p>
  
  <p>I already read a lot and tried a lot (modifying compiler options, linker, startup, trying other code with SysTick_Config() calls), but nothing solved this problem.</p>
  
  <p>One thing could be a hint:
  The compiler starts in both cases (with and without the SysTick_Config call) at 0x00000184. In the case without the SysTick_Config call this points at the beginnig of main(). Using SysTick_Config this pionts at NVIC_SetPriority().</p>
  
  <p>Does anybody have a clue what's going on? Any hint about where I could continue my search for a solution?</p>
  
  <p>I don't know what further information would be helpful to solve this riddle. Please let me know and I will be happy to provide the missing pieces.</p>
  
  <p>Thanks a lot!</p>
  
  <p>/edit1: Added results of arm-none-eabi-readelf, -objdump and -size.</p>
  
  <p>/edit2: I removed the code info to make space for the actual code. With this new simplified version debugging starts at</p>
  
  <pre><code>08000184:   stmdaeq r0, {r4, r6, r8, r9, r10, r11, sp}
  </code></pre>
  
  <p>readelf:</p>
  
  <pre><code>[ 2] .text             PROGBITS        08000184 008184 002dcc 00  AX  0   0  4
  ...
   2: 08000184     0 SECTION LOCAL  DEFAULT    2
  ...
  46: 08000184     0 NOTYPE  LOCAL  DEFAULT    2 $d
  </code></pre>
  
  <p>main.c</p>
  
  <pre><code>/* Includes ------------------------------------------------------------------*/
  #include "stm32f2xx.h"
  
  /* Private typedef -----------------------------------------------------------*/
  /* Private define ------------------------------------------------------------*/
  /* Private macro -------------------------------------------------------------*/
  /* Private variables ---------------------------------------------------------*/
  uint16_t counter = 0;
  
  /* Private function prototypes -----------------------------------------------*/
  /* Private functions ---------------------------------------------------------*/
  void assert_failed(uint8_t* file, uint32_t line);
  void Delay(__IO uint32_t nCount);
  void SysTick_Handler(void);
  /**
    * @brief  Main program
    * @param  None
    * @retval None
    */
  int main(void)
  {
    if (SysTick_Config(SystemCoreClock / 12000))
    {
      // Catch config error
      while(1);
    }
    /*
     * Configure the LEDs
     */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); // LEDs
  
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOF, &amp;GPIO_InitStructure);
  
    GPIOF-&gt;BSRRL = GPIO_Pin_6;
  
    while (1)
    {
      if (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_9) == SET)
      {
        GPIOF-&gt;BSRRH = GPIO_Pin_9;
      }
      else
      {
        GPIOF-&gt;BSRRL = GPIO_Pin_9;
      }
      Delay(500000);
    }
    return 0;
  }
  
  #ifdef  USE_FULL_ASSERT
  
  /**
    * @brief  Reports the name of the source file and the source line number
    *         where the assert_param error has occurred.
    * @param  file: pointer to the source file name
    * @param  line: assert_param error line source number
    * @retval None
    */
  void assert_failed(uint8_t* file, uint32_t line)
  { 
    /* User can add his own implementation to report the file name and line number,
       ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  
    /* Infinite loop */
    while (1)
    {
    }
  }
  #endif
  
  /**
   * @brief  Delay Function.
   * @param  nCount:specifies the Delay time length.
   * @retval None
   */
  void Delay(__IO uint32_t nCount)
  {
    while (nCount &gt; 0)
    {
      nCount--;
    }
  }
  
  /**
    * @brief  This function handles Hard Fault exception.
    * @param  None
    * @retval None
    */
  void HardFault_Handler(void)
  {
    /* Go to infinite loop when Hard Fault exception occurs */
    while (1)
    {
    }
  }
  
  /**
    * @brief  This function handles SysTick Handler.
    * @param  None
    * @retval None
    */
  void SysTick_Handler(void)
  {
    if (counter &gt; 10000 )
    {
      if (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_8) == SET)
      {
        GPIOF-&gt;BSRRH = GPIO_Pin_8;
      }
      else
      {
        GPIOF-&gt;BSRRL = GPIO_Pin_8;
      }
      counter = 0;
    }
    else
    {
      counter++;
    }
  }
  </code></pre>
  
  <p>/edit3:</p>
  
  <p><strong>Soultion</strong>:
  Because the solution is burrowed in a comment, I put it up here:</p>
  
  <p>My linker file was missing <strong><code>ENTRY(your_function_of_choice);</code></strong> (e.g. Reset_Handler). Adding this made my debugger work again (it now starts at the right point).</p>
  
  <p>Thanks everybody!</p>