cpu/kinetis_common: optimization of startup code
This commit is contained in:
parent
8db0a57a81
commit
253e7ce715
@ -4,11 +4,8 @@ export INCLUDES += -I$(RIOTCPU)/kinetis_common/include
|
||||
# Add search path for linker scripts
|
||||
export LINKFLAGS += -L$(RIOTCPU)/kinetis_common/ldscripts
|
||||
|
||||
# add the CPU specific startup code for the linker
|
||||
export UNDEF += $(BINDIR)kinetis_common/startup.o
|
||||
|
||||
# add the CPU specific fault handlers for the linker
|
||||
export UNDEF += $(BINDIR)kinetis_common/fault_handlers.o
|
||||
# add the CPU specific code for the linker
|
||||
export UNDEF += $(BINDIR)kinetis_common/fcfield.o
|
||||
|
||||
# Define a recipe to build the watchdog disable binary, used when flashing
|
||||
$(RIOTCPU)/kinetis_common/dist/wdog-disable.bin: $(RIOTCPU)/kinetis_common/dist/wdog-disable.s
|
||||
|
||||
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Freie Universität Berlin
|
||||
* Copyright (C) 2015 PHYTEC Messtechnik GmbH
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_kinetis_common_fhandlers
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Fault Handlers for Freescale Kinetis MCUs
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @author Johann Fischer <j.fischer@phytec.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "cpu.h"
|
||||
#include "panic.h"
|
||||
#include "fault_handlers.h"
|
||||
|
||||
void isr_nmi(void)
|
||||
{
|
||||
core_panic(PANIC_NMI_HANDLER, "NMI HANDLER");
|
||||
}
|
||||
|
||||
void isr_hard_fault(void)
|
||||
{
|
||||
core_panic(PANIC_HARD_FAULT, "HARD FAULT");
|
||||
}
|
||||
|
||||
void isr_mem_manage(void)
|
||||
{
|
||||
core_panic(PANIC_MEM_MANAGE, "MEM MANAGE HANDLER");
|
||||
}
|
||||
|
||||
void isr_bus_fault(void)
|
||||
{
|
||||
core_panic(PANIC_BUS_FAULT, "BUS FAULT");
|
||||
}
|
||||
|
||||
void isr_usage_fault(void)
|
||||
{
|
||||
core_panic(PANIC_USAGE_FAULT, "ISR USAGE FAULT");
|
||||
}
|
||||
|
||||
void isr_debug_mon(void)
|
||||
{
|
||||
core_panic(PANIC_DEBUG_MON, "DEBUG MON HANDLER");
|
||||
}
|
||||
|
||||
void isr_unhandled(void)
|
||||
{
|
||||
core_panic(PANIC_DUMMY_HANDLER, "UNHANDLED ISR");
|
||||
}
|
||||
44
cpu/kinetis_common/fcfield.c
Normal file
44
cpu/kinetis_common/fcfield.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2015 PHYTEC Messtechnik GmbH
|
||||
* Copyright (C) 2015 Eistec AB
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_kinetis_common
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Default FCF code for Freescale Kinetis MCUs
|
||||
*
|
||||
* @author Johann Fischer <j.fischer@phytec.de>
|
||||
* @author Joakim Gebart <joakim.gebart@eistec.se>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* fcfield table */
|
||||
__attribute__((weak, section(".fcfield")))
|
||||
const uint8_t flash_configuration_field[] = {
|
||||
0xff, /* backdoor comparison key 3., offset: 0x0 */
|
||||
0xff, /* backdoor comparison key 2., offset: 0x1 */
|
||||
0xff, /* backdoor comparison key 1., offset: 0x2 */
|
||||
0xff, /* backdoor comparison key 0., offset: 0x3 */
|
||||
0xff, /* backdoor comparison key 7., offset: 0x4 */
|
||||
0xff, /* backdoor comparison key 6., offset: 0x5 */
|
||||
0xff, /* backdoor comparison key 5., offset: 0x6 */
|
||||
0xff, /* backdoor comparison key 4., offset: 0x7 */
|
||||
0xff, /* non-volatile p-flash protection 1 - low register, offset: 0x8 */
|
||||
0xff, /* non-volatile p-flash protection 1 - high register, offset: 0x9 */
|
||||
0xff, /* non-volatile p-flash protection 0 - low register, offset: 0xa */
|
||||
0xff, /* non-volatile p-flash protection 0 - high register, offset: 0xb */
|
||||
0xfe, /* non-volatile flash security register, offset: 0xc */
|
||||
0xff, /* non-volatile flash option register, offset: 0xd */
|
||||
0xff, /* non-volatile eeram protection register, offset: 0xe */
|
||||
0xff, /* non-volatile d-flash protection register, offset: 0xf */
|
||||
};
|
||||
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Freie Universität Berlin
|
||||
* Copyright (C) 2015 PHYTEC Messtechnik GmbH
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup cpu_kinetis_common_fhandlers Kinetis Fault Handlers
|
||||
* @ingroup cpu_kinetis_common
|
||||
* @brief Fault Handlers for Freescale Kinetis MCUs.
|
||||
*
|
||||
* @{
|
||||
|
||||
* @file
|
||||
* @brief Interface definition for the Kinetis Fault Handlers.
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @author Johann Fischer <j.fischer@phytec.de>
|
||||
*/
|
||||
|
||||
#ifndef FAULT_HANDLERS_H
|
||||
#define FAULT_HANDLERS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Non Maskable Interrupt
|
||||
*/
|
||||
void isr_nmi(void);
|
||||
|
||||
/**
|
||||
* @brief HardFault
|
||||
*/
|
||||
void isr_hard_fault(void);
|
||||
|
||||
/**
|
||||
* @brief MemManage
|
||||
*/
|
||||
void isr_mem_manage(void);
|
||||
|
||||
/**
|
||||
* @brief BusFault
|
||||
*/
|
||||
void isr_bus_fault(void);
|
||||
|
||||
/**
|
||||
* @brief UsageFault
|
||||
*/
|
||||
void isr_usage_fault(void);
|
||||
|
||||
/**
|
||||
* @brief Debug Interrupt
|
||||
*/
|
||||
void isr_debug_mon(void);
|
||||
|
||||
/**
|
||||
* @brief Default handler, called in case no interrupt handler was defined.
|
||||
*/
|
||||
void isr_unhandled(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FAULT_HANDLERS_H */
|
||||
/** @} */
|
||||
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Freie Universität Berlin
|
||||
* Copyright (C) 2015 PHYTEC Messtechnik GmbH
|
||||
* Copyright (C) 2015 Eistec AB
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_kinetis_common
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Startup code for Freescale Kinetis MCUs
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @author Johann Fischer <j.fischer@phytec.de>
|
||||
* @author Joakim Gebart <joakim.gebart@eistec.se>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "cpu_conf.h"
|
||||
#include "wdog.h"
|
||||
|
||||
/**
|
||||
* @name Memory markers as defined in the linker script
|
||||
* @{
|
||||
*/
|
||||
extern uint32_t _sfixed[];
|
||||
extern uint32_t _efixed[];
|
||||
extern uint32_t _etext[];
|
||||
extern uint32_t _srelocate[];
|
||||
extern uint32_t _erelocate[];
|
||||
extern uint32_t _szero[];
|
||||
extern uint32_t _ezero[];
|
||||
extern uint32_t _sstack[];
|
||||
extern uint32_t _ramcode_start[];
|
||||
extern uint32_t _ramcode_end[];
|
||||
extern uint32_t _ramcode_load[];
|
||||
extern uint32_t _vector_ram_start[];
|
||||
extern uint32_t _vector_ram_end[];
|
||||
extern uint32_t _vector_rom[];
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief functions for initializing the board, std-lib and kernel
|
||||
*/
|
||||
extern void board_init(void);
|
||||
extern void kernel_init(void);
|
||||
extern void __libc_init_array(void);
|
||||
|
||||
/**
|
||||
* @brief This function is the entry point after a system reset
|
||||
*
|
||||
* After a system reset, the following steps are necessary and carried out:
|
||||
* 0. disable the Watchdog Timer
|
||||
* 1. load data section from flash to ram
|
||||
* 2. overwrite uninitialized data section (BSS) with zeros
|
||||
* 3. initialize the newlib
|
||||
* 4. initialize the board (sync clock, setup std-IO)
|
||||
* 5. initialize and start RIOTs kernel
|
||||
*/
|
||||
void reset_handler(void)
|
||||
{
|
||||
uint32_t *dst;
|
||||
uint32_t *src = _etext;
|
||||
|
||||
/* disable the WDOG */
|
||||
wdog_disable();
|
||||
|
||||
/* load .data section from flash to ram */
|
||||
for (dst = _srelocate; dst < _erelocate;) {
|
||||
*(dst++) = *(src++);
|
||||
}
|
||||
|
||||
/* default .bss section to zero */
|
||||
for (dst = _szero; dst < _ezero;) {
|
||||
*(dst++) = 0;
|
||||
}
|
||||
|
||||
/* copy .ramcode from flash to RAM */
|
||||
src = _ramcode_load;
|
||||
for (dst = _ramcode_start; dst < _ramcode_end;) {
|
||||
*(dst++) = *(src++);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy ISR vector from flash to RAM.
|
||||
*
|
||||
* To use this CPU feature, define RAMVECT_SIZE=0x400 when building and write
|
||||
* the new vector table address in RAM to SCB->VTOR.
|
||||
*/
|
||||
src = _vector_rom;
|
||||
for (dst = _vector_ram_start; dst < _vector_ram_end;) {
|
||||
*(dst++) = *(src++);
|
||||
}
|
||||
|
||||
/* initialize the board and startup the kernel */
|
||||
board_init();
|
||||
/* initialize std-c library (this should be done after board_init) */
|
||||
__libc_init_array();
|
||||
/* startup the kernel */
|
||||
kernel_init();
|
||||
}
|
||||
|
||||
/* fcfield table */
|
||||
__attribute__((weak, section(".fcfield")))
|
||||
const uint8_t flash_configuration_field[] = {
|
||||
0xff, /* backdoor comparison key 3., offset: 0x0 */
|
||||
0xff, /* backdoor comparison key 2., offset: 0x1 */
|
||||
0xff, /* backdoor comparison key 1., offset: 0x2 */
|
||||
0xff, /* backdoor comparison key 0., offset: 0x3 */
|
||||
0xff, /* backdoor comparison key 7., offset: 0x4 */
|
||||
0xff, /* backdoor comparison key 6., offset: 0x5 */
|
||||
0xff, /* backdoor comparison key 5., offset: 0x6 */
|
||||
0xff, /* backdoor comparison key 4., offset: 0x7 */
|
||||
0xff, /* non-volatile p-flash protection 1 - low register, offset: 0x8 */
|
||||
0xff, /* non-volatile p-flash protection 1 - high register, offset: 0x9 */
|
||||
0xff, /* non-volatile p-flash protection 0 - low register, offset: 0xa */
|
||||
0xff, /* non-volatile p-flash protection 0 - high register, offset: 0xb */
|
||||
0xfe, /* non-volatile flash security register, offset: 0xc */
|
||||
0xff, /* non-volatile flash option register, offset: 0xd */
|
||||
0xff, /* non-volatile eeram protection register, offset: 0xe */
|
||||
0xff, /* non-volatile d-flash protection register, offset: 0xf */
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user