]> git.sur5r.net Git - armstart-ibdap/blobdiff - src/cr_startup_lpc11uxx.c
initial commit
[armstart-ibdap] / src / cr_startup_lpc11uxx.c
diff --git a/src/cr_startup_lpc11uxx.c b/src/cr_startup_lpc11uxx.c
new file mode 100755 (executable)
index 0000000..ed97c98
--- /dev/null
@@ -0,0 +1,348 @@
+//*****************************************************************************\r
+// LPC11Uxx Microcontroller Startup code for use with LPCXpresso IDE\r
+//\r
+// Version : 141204\r
+//*****************************************************************************\r
+//\r
+// Copyright(C) NXP Semiconductors, 2013-2014\r
+// All rights reserved.\r
+//\r
+// Software that is described herein is for illustrative purposes only\r
+// which provides customers with programming information regarding the\r
+// LPC products.  This software is supplied "AS IS" without any warranties of\r
+// any kind, and NXP Semiconductors and its licensor disclaim any and\r
+// all warranties, express or implied, including all implied warranties of\r
+// merchantability, fitness for a particular purpose and non-infringement of\r
+// intellectual property rights.  NXP Semiconductors assumes no responsibility\r
+// or liability for the use of the software, conveys no license or rights under any\r
+// patent, copyright, mask work right, or any other intellectual property rights in\r
+// or to any products. NXP Semiconductors reserves the right to make changes\r
+// in the software without notification. NXP Semiconductors also makes no\r
+// representation or warranty that such application will be suitable for the\r
+// specified use without further testing or modification.\r
+//\r
+// Permission to use, copy, modify, and distribute this software and its\r
+// documentation is hereby granted, under NXP Semiconductors' and its\r
+// licensor's relevant copyrights in the software, without fee, provided that it\r
+// is used in conjunction with NXP Semiconductors microcontrollers.  This\r
+// copyright, permission, and disclaimer notice must appear in all copies of\r
+// this code.\r
+//*****************************************************************************\r
+\r
+#if defined (__cplusplus)\r
+#ifdef __REDLIB__\r
+#error Redlib does not support C++\r
+#else\r
+//*****************************************************************************\r
+//\r
+// The entry point for the C++ library startup\r
+//\r
+//*****************************************************************************\r
+extern "C" {\r
+    extern void __libc_init_array(void);\r
+}\r
+#endif\r
+#endif\r
+\r
+#define WEAK __attribute__ ((weak))\r
+#define ALIAS(f) __attribute__ ((weak, alias (#f)))\r
+\r
+//*****************************************************************************\r
+#if defined (__cplusplus)\r
+extern "C" {\r
+#endif\r
+\r
+//*****************************************************************************\r
+#if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)\r
+// Declaration of external SystemInit function\r
+extern void SystemInit(void);\r
+#endif\r
+\r
+// Patch the AEABI integer divide functions to use MCU's romdivide library\r
+#ifdef __USE_ROMDIVIDE\r
+// Location in memory that holds the address of the ROM Driver table\r
+#define PTR_ROM_DRIVER_TABLE ((unsigned int *)(0x1FFF1FF8))\r
+// Variables to store addresses of idiv and udiv functions within MCU ROM\r
+unsigned int *pDivRom_idiv;\r
+unsigned int *pDivRom_uidiv;\r
+#endif\r
+\r
+//*****************************************************************************\r
+//\r
+// Forward declaration of the default handlers. These are aliased.\r
+// When the application defines a handler (with the same name), this will \r
+// automatically take precedence over these weak definitions\r
+//\r
+//*****************************************************************************\r
+     void ResetISR(void);\r
+WEAK void NMI_Handler(void);\r
+WEAK void HardFault_Handler(void);\r
+WEAK void SVC_Handler(void);\r
+WEAK void PendSV_Handler(void);\r
+WEAK void SysTick_Handler(void);\r
+WEAK void IntDefaultHandler(void);\r
+//*****************************************************************************\r
+//\r
+// Forward declaration of the specific IRQ handlers. These are aliased\r
+// to the IntDefaultHandler, which is a 'forever' loop. When the application\r
+// defines a handler (with the same name), this will automatically take\r
+// precedence over these weak definitions\r
+//\r
+//*****************************************************************************\r
+void FLEX_INT0_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FLEX_INT1_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FLEX_INT2_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FLEX_INT3_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FLEX_INT4_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FLEX_INT5_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FLEX_INT6_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FLEX_INT7_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void GINT0_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void GINT1_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void SSP1_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void I2C_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void TIMER16_0_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void TIMER16_1_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void TIMER32_0_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void TIMER32_1_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void UART_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void USB_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void USB_FIQHandler (void) ALIAS(IntDefaultHandler);\r
+void ADC_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void WDT_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void BOD_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+void USBWakeup_IRQHandler (void) ALIAS(IntDefaultHandler);\r
+\r
+//*****************************************************************************\r
+// The entry point for the application.\r
+// __main() is the entry point for redlib based applications\r
+// main() is the entry point for newlib based applications\r
+//*****************************************************************************\r
+#if defined (__REDLIB__)\r
+extern void __main(void);\r
+#else\r
+extern int main(void);\r
+#endif\r
+//*****************************************************************************\r
+//\r
+// External declaration for the pointer to the stack top from the Linker Script\r
+//\r
+//*****************************************************************************\r
+extern void _vStackTop(void);\r
+\r
+//*****************************************************************************\r
+#if defined (__cplusplus)\r
+} // extern "C"\r
+#endif\r
+//*****************************************************************************\r
+//\r
+// The vector table.  Note that the proper constructs must be placed on this to\r
+// ensure that it ends up at physical address 0x0000.0000.\r
+//\r
+//*****************************************************************************\r
+extern void (* const g_pfnVectors[])(void);\r
+__attribute__ ((section(".isr_vector")))\r
+void (* const g_pfnVectors[])(void) = {\r
+    &_vStackTop,              // The initial stack pointer\r
+    ResetISR,                         // The reset handler\r
+    NMI_Handler,                      // The NMI handler\r
+    HardFault_Handler,                // The hard fault handler\r
+    0,                                // Reserved\r
+    0,                                // Reserved\r
+    0,                                // Reserved\r
+    0,                                // Reserved\r
+    0,                                // Reserved\r
+    0,                                // Reserved\r
+    0,                                // Reserved\r
+    SVC_Handler,                      // SVCall handler\r
+    0,                                // Reserved\r
+    0,                                // Reserved\r
+    PendSV_Handler,                   // The PendSV handler\r
+    SysTick_Handler,                  // The SysTick handler\r
+\r
+    // LPC11U specific handlers\r
+    FLEX_INT0_IRQHandler,             //  0 - GPIO pin interrupt 0\r
+    FLEX_INT1_IRQHandler,             //  1 - GPIO pin interrupt 1\r
+    FLEX_INT2_IRQHandler,             //  2 - GPIO pin interrupt 2\r
+    FLEX_INT3_IRQHandler,             //  3 - GPIO pin interrupt 3\r
+    FLEX_INT4_IRQHandler,             //  4 - GPIO pin interrupt 4\r
+    FLEX_INT5_IRQHandler,             //  5 - GPIO pin interrupt 5\r
+    FLEX_INT6_IRQHandler,             //  6 - GPIO pin interrupt 6\r
+    FLEX_INT7_IRQHandler,             //  7 - GPIO pin interrupt 7\r
+    GINT0_IRQHandler,                 //  8 - GPIO GROUP0 interrupt\r
+    GINT1_IRQHandler,                 //  9 - GPIO GROUP1 interrupt\r
+    0,                                // 10 - Reserved\r
+    0,                                // 11 - Reserved\r
+    0,                                // 12 - Reserved\r
+    0,                                // 13 - Reserved\r
+    SSP1_IRQHandler,                  // 14 - SPI/SSP1 Interrupt\r
+    I2C_IRQHandler,                   // 15 - I2C0\r
+    TIMER16_0_IRQHandler,             // 16 - CT16B0 (16-bit Timer 0)\r
+    TIMER16_1_IRQHandler,             // 17 - CT16B1 (16-bit Timer 1)\r
+    TIMER32_0_IRQHandler,             // 18 - CT32B0 (32-bit Timer 0)\r
+    TIMER32_1_IRQHandler,             // 19 - CT32B1 (32-bit Timer 1)\r
+    SSP0_IRQHandler,                  // 20 - SPI/SSP0 Interrupt\r
+    UART_IRQHandler,                  // 21 - UART0\r
+    USB_IRQHandler,                   // 22 - USB IRQ\r
+    USB_FIQHandler,                   // 23 - USB FIQ\r
+    ADC_IRQHandler,                   // 24 - ADC (A/D Converter)\r
+    WDT_IRQHandler,                   // 25 - WDT (Watchdog Timer)\r
+    BOD_IRQHandler,                   // 26 - BOD (Brownout Detect)\r
+    FMC_IRQHandler,                   // 27 - IP2111 Flash Memory Controller\r
+    0,                                // 28 - Reserved\r
+    0,                                // 29 - Reserved\r
+    USBWakeup_IRQHandler,             // 30 - USB wake-up interrupt\r
+    0,                                // 31 - Reserved\r
+};\r
+\r
+//*****************************************************************************\r
+// Functions to carry out the initialization of RW and BSS data sections. These\r
+// are written as separate functions rather than being inlined within the\r
+// ResetISR() function in order to cope with MCUs with multiple banks of\r
+// memory.\r
+//*****************************************************************************\r
+__attribute__ ((section(".after_vectors")))\r
+void data_init(unsigned int romstart, unsigned int start, unsigned int len) {\r
+    unsigned int *pulDest = (unsigned int*) start;\r
+    unsigned int *pulSrc = (unsigned int*) romstart;\r
+    unsigned int loop;\r
+    for (loop = 0; loop < len; loop = loop + 4)\r
+        *pulDest++ = *pulSrc++;\r
+}\r
+\r
+__attribute__ ((section(".after_vectors")))\r
+void bss_init(unsigned int start, unsigned int len) {\r
+    unsigned int *pulDest = (unsigned int*) start;\r
+    unsigned int loop;\r
+    for (loop = 0; loop < len; loop = loop + 4)\r
+        *pulDest++ = 0;\r
+}\r
+\r
+//*****************************************************************************\r
+// The following symbols are constructs generated by the linker, indicating\r
+// the location of various points in the "Global Section Table". This table is\r
+// created by the linker via the Code Red managed linker script mechanism. It\r
+// contains the load address, execution address and length of each RW data\r
+// section and the execution and length of each BSS (zero initialized) section.\r
+//*****************************************************************************\r
+extern unsigned int __data_section_table;\r
+extern unsigned int __data_section_table_end;\r
+extern unsigned int __bss_section_table;\r
+extern unsigned int __bss_section_table_end;\r
+\r
+//*****************************************************************************\r
+// Reset entry point for your code.\r
+// Sets up a simple runtime environment and initializes the C/C++\r
+// library.\r
+//*****************************************************************************\r
+__attribute__ ((section(".after_vectors")))\r
+void\r
+ResetISR(void) {\r
+\r
+\r
+\r
+    //\r
+    // Copy the data sections from flash to SRAM.\r
+    //\r
+    unsigned int LoadAddr, ExeAddr, SectionLen;\r
+    unsigned int *SectionTableAddr;\r
+\r
+    // Load base address of Global Section Table\r
+    SectionTableAddr = &__data_section_table;\r
+\r
+    // Copy the data sections from flash to SRAM.\r
+    while (SectionTableAddr < &__data_section_table_end) {\r
+        LoadAddr = *SectionTableAddr++;\r
+        ExeAddr = *SectionTableAddr++;\r
+        SectionLen = *SectionTableAddr++;\r
+        data_init(LoadAddr, ExeAddr, SectionLen);\r
+    }\r
+    // At this point, SectionTableAddr = &__bss_section_table;\r
+    // Zero fill the bss segment\r
+    while (SectionTableAddr < &__bss_section_table_end) {\r
+        ExeAddr = *SectionTableAddr++;\r
+        SectionLen = *SectionTableAddr++;\r
+        bss_init(ExeAddr, SectionLen);\r
+    }\r
+\r
+#if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)\r
+    SystemInit();\r
+#endif\r
+\r
+#if defined (__cplusplus)\r
+    //\r
+    // Call C++ library initialisation\r
+    //\r
+    __libc_init_array();\r
+#endif\r
+\r
+#if defined (__REDLIB__)\r
+    // Call the Redlib library, which in turn calls main()\r
+    __main() ;\r
+#else\r
+    main();\r
+#endif\r
+    //\r
+    // main() shouldn't return, but if it does, we'll just enter an infinite loop\r
+    //\r
+    while (1) {\r
+        ;\r
+    }\r
+}\r
+\r
+//*****************************************************************************\r
+// Default exception handlers. Override the ones here by defining your own\r
+// handler routines in your application code.\r
+//*****************************************************************************\r
+__attribute__ ((section(".after_vectors")))\r
+void NMI_Handler(void)\r
+{\r
+    while(1)\r
+    {\r
+    }\r
+}\r
+__attribute__ ((section(".after_vectors")))\r
+void HardFault_Handler(void)\r
+{\r
+    while(1)\r
+    {\r
+    }\r
+}\r
+__attribute__ ((section(".after_vectors")))\r
+void SVC_Handler(void)\r
+{\r
+    while(1)\r
+    {\r
+    }\r
+}\r
+__attribute__ ((section(".after_vectors")))\r
+void PendSV_Handler(void)\r
+{\r
+    while(1)\r
+    {\r
+    }\r
+}\r
+__attribute__ ((section(".after_vectors")))\r
+void SysTick_Handler(void)\r
+{\r
+    while(1)\r
+    {\r
+    }\r
+}\r
+\r
+//*****************************************************************************\r
+//\r
+// Processor ends up here if an unexpected interrupt occurs or a specific\r
+// handler is not present in the application code.\r
+//\r
+//*****************************************************************************\r
+__attribute__ ((section(".after_vectors")))\r
+void IntDefaultHandler(void)\r
+{\r
+    while(1)\r
+    {\r
+    }\r
+}\r
+\r