From b1f8aa175e1770c25e0583fe14cc625c4f86bde8 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 14 May 2019 17:37:11 +0700 Subject: [PATCH] add linker and startup for lpcxpresso11u68 board able to build and blink LED --- hw/bsp/lpcxpresso11u68/board.mk | 39 ++ .../lpcxpresso11u68/board_lpcxpresso11u68.c | 26 +- hw/bsp/lpcxpresso11u68/cr_startup_lpc11u6x.c | 352 ++++++++++++++++++ hw/bsp/lpcxpresso11u68/lpc11u68.ld | 242 ++++++++++++ 4 files changed, 640 insertions(+), 19 deletions(-) create mode 100644 hw/bsp/lpcxpresso11u68/board.mk create mode 100644 hw/bsp/lpcxpresso11u68/cr_startup_lpc11u6x.c create mode 100644 hw/bsp/lpcxpresso11u68/lpc11u68.ld diff --git a/hw/bsp/lpcxpresso11u68/board.mk b/hw/bsp/lpcxpresso11u68/board.mk new file mode 100644 index 000000000..a443cec4c --- /dev/null +++ b/hw/bsp/lpcxpresso11u68/board.mk @@ -0,0 +1,39 @@ +CFLAGS += \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m0plus \ + -nostdlib \ + -DCORE_M0PLUS \ + -D__VTOR_PRESENT=0 \ + -DCFG_TUSB_MCU=OPT_MCU_LPC11UXX \ + -D__USE_LPCOPEN \ + '-DCFG_TUSB_MEM_SECTION= __attribute__((section(".data.$RAM3")))' \ + '-DCFG_TUSB_MEM_ALIGN=__attribute__ ((aligned(64)))' + +# All source paths should be relative to the top level. +LD_FILE = hw/bsp/lpcxpresso11u68/lpc11u68.ld + +SRC_C += \ + hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/chip_11u6x.c \ + hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/clock_11u6x.c \ + hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/gpio_11u6x.c \ + hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/iocon_11u6x.c \ + hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/syscon_11u6x.c \ + hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/sysinit_11u6x.c + +INC += \ + $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_11u6x/inc + +# For TinyUSB port source +VENDOR = nxp +CHIP_FAMILY = lpc11_13_15 + +# For freeRTOS port source +FREERTOS_PORT = ARM_CM0 + +# For flash-jlink target +JLINK_DEVICE = LPC11U68 +JLINK_IF = swd + +# flash using jlink +flash: flash-jlink diff --git a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c index e72044740..98f259459 100644 --- a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c +++ b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c @@ -31,14 +31,8 @@ #define LED_PIN 17 #define LED_STATE_ON 0 -static const struct { - uint8_t port; - uint8_t pin; -} buttons[] = { { 0, 1 } }; - -enum { - BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) -}; +#define BUTTON_PORT 0 +#define BUTTON_PIN 1 /* System oscillator rate and RTC oscillator rate */ const uint32_t OscRateIn = 12000000; @@ -78,14 +72,11 @@ void board_init(void) Chip_GPIO_Init(LPC_GPIO); - //------------- LED -------------// + // LED Chip_GPIO_SetPinDIROutput(LPC_GPIO, LED_PORT, LED_PIN); - //------------- BUTTON -------------// - //for(uint8_t i=0; i MFlash256 + + .text : ALIGN(4) + { + *(.text*) + *(.rodata .rodata.* .constdata .constdata.*) + . = ALIGN(4); + } > MFlash256 + /* + * for exception handling/unwind - some Newlib functions (in common + * with C++ and STDC++) use this. + */ + .ARM.extab : ALIGN(4) + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > MFlash256 + + __exidx_start = .; + + .ARM.exidx : ALIGN(4) + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > MFlash256 + __exidx_end = .; + + _etext = .; + + /* possible MTB section for Ram1_2 */ + .mtb_buffer_RAM2 (NOLOAD) : + { + KEEP(*(.mtb.$RAM2*)) + KEEP(*(.mtb.$Ram1_2*)) + } > Ram1_2 + + /* DATA section for Ram1_2 */ + + .data_RAM2 : ALIGN(4) + { + FILL(0xff) + PROVIDE(__start_data_RAM2 = .) ; + *(.ramfunc.$RAM2) + *(.ramfunc.$Ram1_2) + *(.data.$RAM2*) + *(.data.$Ram1_2*) + . = ALIGN(4) ; + PROVIDE(__end_data_RAM2 = .) ; + } > Ram1_2 AT>MFlash256 + /* possible MTB section for Ram2USB_2 */ + .mtb_buffer_RAM3 (NOLOAD) : + { + KEEP(*(.mtb.$RAM3*)) + KEEP(*(.mtb.$Ram2USB_2*)) + } > Ram2USB_2 + + /* DATA section for Ram2USB_2 */ + + .data_RAM3 : ALIGN(4) + { + FILL(0xff) + PROVIDE(__start_data_RAM3 = .) ; + *(.ramfunc.$RAM3) + *(.ramfunc.$Ram2USB_2) + *(.data.$RAM3*) + *(.data.$Ram2USB_2*) + . = ALIGN(4) ; + PROVIDE(__end_data_RAM3 = .) ; + } > Ram2USB_2 AT>MFlash256 + /* MAIN DATA SECTION */ + /* Default MTB section */ + .mtb_buffer_default (NOLOAD) : + { + KEEP(*(.mtb*)) + } > Ram0_32 + .uninit_RESERVED : ALIGN(4) + { + KEEP(*(.bss.$RESERVED*)) + . = ALIGN(4) ; + _end_uninit_RESERVED = .; + } > Ram0_32 + + /* Main DATA section (Ram0_32) */ + .data : ALIGN(4) + { + FILL(0xff) + _data = . ; + *(vtable) + *(.ramfunc*) + *(.data*) + . = ALIGN(4) ; + _edata = . ; + } > Ram0_32 AT>MFlash256 + + /* BSS section for Ram1_2 */ + .bss_RAM2 : ALIGN(4) + { + PROVIDE(__start_bss_RAM2 = .) ; + *(.bss.$RAM2*) + *(.bss.$Ram1_2*) + . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */ + PROVIDE(__end_bss_RAM2 = .) ; + } > Ram1_2 + + /* BSS section for Ram2USB_2 */ + .bss_RAM3 : ALIGN(4) + { + PROVIDE(__start_bss_RAM3 = .) ; + *(.bss.$RAM3*) + *(.bss.$Ram2USB_2*) + . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */ + PROVIDE(__end_bss_RAM3 = .) ; + } > Ram2USB_2 + + /* MAIN BSS SECTION */ + .bss : ALIGN(4) + { + _bss = .; + *(.bss*) + *(COMMON) + . = ALIGN(4) ; + _ebss = .; + PROVIDE(end = .); + } > Ram0_32 + + /* NOINIT section for Ram1_2 */ + .noinit_RAM2 (NOLOAD) : ALIGN(4) + { + *(.noinit.$RAM2*) + *(.noinit.$Ram1_2*) + . = ALIGN(4) ; + } > Ram1_2 + + /* NOINIT section for Ram2USB_2 */ + .noinit_RAM3 (NOLOAD) : ALIGN(4) + { + *(.noinit.$RAM3*) + *(.noinit.$Ram2USB_2*) + . = ALIGN(4) ; + } > Ram2USB_2 + + /* DEFAULT NOINIT SECTION */ + .noinit (NOLOAD): ALIGN(4) + { + _noinit = .; + *(.noinit*) + . = ALIGN(4) ; + _end_noinit = .; + } > Ram0_32 + PROVIDE(_pvHeapStart = DEFINED(__user_heap_base) ? __user_heap_base : .); + PROVIDE(_vStackTop = DEFINED(__user_stack_top) ? __user_stack_top : __top_Ram0_32 - 0); + + /* ## Create checksum value (used in startup) ## */ + PROVIDE(__valid_user_code_checksum = 0 - + (_vStackTop + + (ResetISR + 1) + + (( DEFINED(NMI_Handler) ? NMI_Handler : M0_NMI_Handler ) + 1) + + (( DEFINED(HardFault_Handler) ? HardFault_Handler : M0_HardFault_Handler ) + 1) + ) + ); + + /* Provide basic symbols giving location and size of main text + * block, including initial values of RW data sections. Note that + * these will need extending to give a complete picture with + * complex images (e.g multiple Flash banks). + */ + _image_start = LOADADDR(.text); + _image_end = LOADADDR(.data) + SIZEOF(.data); + _image_size = _image_end - _image_start; +} \ No newline at end of file