2011-08-12 21:57:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/kinetis/kinetis_start.c
|
|
|
|
* arch/arm/src/chip/kinetis_start.c
|
|
|
|
*
|
2012-02-11 04:50:52 +01:00
|
|
|
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-08-12 21:57:12 +02:00
|
|
|
*
|
|
|
|
* 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. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/init.h>
|
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
#include "up_arch.h"
|
|
|
|
#include "up_internal.h"
|
|
|
|
|
|
|
|
#include "kinetis_internal.h"
|
2011-08-16 17:06:39 +02:00
|
|
|
#include "kinetis_smc.h"
|
2013-03-24 18:28:38 +01:00
|
|
|
#include "kinetis_userspace.h"
|
2011-08-12 21:57:12 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 16:04:12 +02:00
|
|
|
* Pre-processor Definitions
|
2011-08-12 21:57:12 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: _start
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the reset entry point.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void __start(void)
|
|
|
|
{
|
|
|
|
const uint32_t *src;
|
|
|
|
uint32_t *dest;
|
|
|
|
|
2011-08-13 00:10:48 +02:00
|
|
|
/* Disable the watchdog timer */
|
|
|
|
|
|
|
|
kinetis_wddisable();
|
|
|
|
|
2011-08-12 21:57:12 +02:00
|
|
|
/* Clear .bss. We'll do this inline (vs. calling memset) just to be
|
|
|
|
* certain that there are no issues with the state of global variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (dest = &_sbss; dest < &_ebss; )
|
|
|
|
{
|
|
|
|
*dest++ = 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:37:55 +01:00
|
|
|
/* Move the initialized data section from his temporary holding spot in
|
2011-08-12 21:57:12 +02:00
|
|
|
* FLASH into the correct place in SRAM. The correct place in SRAM is
|
|
|
|
* give by _sdata and _edata. The temporary location is in FLASH at the
|
|
|
|
* end of all of the other read-only data (.text, .rodata) at _eronly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (src = &_eronly, dest = &_sdata; dest < &_edata; )
|
|
|
|
{
|
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
|
2011-08-13 00:10:48 +02:00
|
|
|
/* Copy any necessary code sections from FLASH to RAM. The correct
|
2015-06-11 16:38:56 +02:00
|
|
|
* destination in SRAM is given by _sramfuncs and _eramfuncs. The
|
|
|
|
* temporary location is in flash after the data initialization code
|
2011-08-13 00:10:48 +02:00
|
|
|
* at _framfuncs
|
|
|
|
*/
|
|
|
|
|
2013-01-14 23:06:19 +01:00
|
|
|
#ifdef CONFIG_ARCH_RAMFUNCS
|
2011-08-13 00:10:48 +02:00
|
|
|
for (src = &_framfuncs, dest = &_sramfuncs; dest < &_eramfuncs; )
|
|
|
|
{
|
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-16 17:06:39 +02:00
|
|
|
/* Perform clock and Kinetis module initialization (This depends on
|
|
|
|
* RAM functions having been copied to RAM).
|
|
|
|
*/
|
2011-08-13 18:11:26 +02:00
|
|
|
|
|
|
|
kinetis_clockconfig();
|
|
|
|
|
|
|
|
/* Configure the uart and perform early serial initialization so that we
|
2011-08-16 17:06:39 +02:00
|
|
|
* can get debug output as soon as possible (This depends on clock
|
|
|
|
* configuration).
|
2011-08-13 18:11:26 +02:00
|
|
|
*/
|
2011-08-12 21:57:12 +02:00
|
|
|
|
2011-08-13 18:11:26 +02:00
|
|
|
kinetis_lowsetup();
|
2012-02-11 04:50:52 +01:00
|
|
|
#ifdef USE_EARLYSERIALINIT
|
2011-08-12 21:57:12 +02:00
|
|
|
up_earlyserialinit();
|
|
|
|
#endif
|
|
|
|
|
2013-03-24 18:28:38 +01:00
|
|
|
/* For the case of the separate user-/kernel-space build, perform whatever
|
|
|
|
* platform specific initialization of the user memory is required.
|
|
|
|
* Normally this just means initializing the user space .data and .bss
|
|
|
|
* segments.
|
|
|
|
*/
|
|
|
|
|
2014-08-29 22:47:22 +02:00
|
|
|
#ifdef CONFIG_BUILD_PROTECTED
|
2013-03-24 18:28:38 +01:00
|
|
|
kinetis_userspace();
|
|
|
|
#endif
|
|
|
|
|
2011-08-13 18:11:26 +02:00
|
|
|
/* Initialize other on-board resources */
|
2011-08-12 21:57:12 +02:00
|
|
|
|
|
|
|
kinetis_boardinitialize();
|
2011-08-13 00:10:48 +02:00
|
|
|
|
|
|
|
/* Show reset status */
|
|
|
|
|
2011-08-13 18:11:26 +02:00
|
|
|
dbg("Reset status: %02x:%02x\n",
|
|
|
|
getreg8(KINETIS_SMC_SRSH), getreg8(KINETIS_SMC_SRSL));
|
2011-08-12 21:57:12 +02:00
|
|
|
|
|
|
|
/* Then start NuttX */
|
|
|
|
|
|
|
|
os_start();
|
|
|
|
|
|
|
|
/* Shouldn't get here */
|
|
|
|
|
2015-10-07 19:39:06 +02:00
|
|
|
for (; ; );
|
2011-08-12 21:57:12 +02:00
|
|
|
}
|