From 573234d9d51554538c5b83f70bdbcbbbc0917360 Mon Sep 17 00:00:00 2001 From: kraus Date: Sat, 17 Aug 2019 13:52:06 +0200 Subject: [PATCH] various LPC804 fixes --- sys/arm/lpc804/blink/Makefile | 145 ++++++++++++++++ sys/arm/lpc804/blink/blink.a | Bin 0 -> 19860 bytes sys/arm/lpc804/blink/delay.c | 129 +++++++++++++++ sys/arm/lpc804/blink/delay.h | 55 +++++++ sys/arm/lpc804/blink/lpc804.ld | 177 ++++++++++++++++++++ sys/arm/lpc804/blink/main.c | 62 +++++++ sys/arm/lpc804/blink/startup.c | 201 +++++++++++++++++++++++ sys/arm/lpc804/lpc_chip_804/inc/i2c.h | 2 +- sys/arm/lpc804/lpc_chip_804/inc/spi.h | 1 + sys/arm/lpc804/lpc_chip_804/inc/syscon.h | 12 +- sys/arm/lpc804/lpc_chip_804/info.txt | 19 +++ sys/arm/lpc804/lpc_chip_804/src/i2c.c | 2 +- sys/arm/lpc804/lpc_chip_804/src/plu.c | 1 - sys/arm/lpc804/lpc_chip_804/src/spi.c | 2 +- sys/arm/lpc804/lpc_chip_804/src/syscon.c | 2 +- 15 files changed, 800 insertions(+), 10 deletions(-) create mode 100644 sys/arm/lpc804/blink/Makefile create mode 100644 sys/arm/lpc804/blink/blink.a create mode 100644 sys/arm/lpc804/blink/delay.c create mode 100644 sys/arm/lpc804/blink/delay.h create mode 100644 sys/arm/lpc804/blink/lpc804.ld create mode 100644 sys/arm/lpc804/blink/main.c create mode 100644 sys/arm/lpc804/blink/startup.c diff --git a/sys/arm/lpc804/blink/Makefile b/sys/arm/lpc804/blink/Makefile new file mode 100644 index 00000000..b97f40b7 --- /dev/null +++ b/sys/arm/lpc804/blink/Makefile @@ -0,0 +1,145 @@ +# +# Generic and Simple GNU ARM Makefile +# +# Desinged for the gnu-arm-none-eabi tool chain +# +# Features +# - create hex file +# - create assembler listing (.dis) +# +# Limitations +# - only C-files supported +# - no automatic dependency checking (call 'make clean' if any .h files are changed) +# +# Targets: +# make +# create hex file, no upload +# make upload +# create and upload hex file +# make clean +# delete all generated files +# +# Note: +# Display list make database: make -p -f/dev/null | less +# +#================================================ +# External tools + +# The base directory of gcc-arm-none-eabi +# Can be empty on Ubuntu and installed gcc-arm-none-eabi +# If set, GCCBINPATH must contain a "/" at the end. +GCCBINPATH:=/usr/bin/ + +#================================================ +# Project Information + +# The name for the project +TARGETNAME:=blink + +# The source files of the project +SRC:=$(wildcard *.c) + +# The CPU architecture (will be used for -mcpu) +# for the LPC804, can we use "cortex-m0plus" instead of "cortex-m0"? +MCPU:=cortex-m0plus + +# Include directory for the system include files +SYSINC:=../lpc_chip_804/inc +SYSSRC:=$(wildcard ../lpc_chip_804/src/*.c) + +# Include directory for the u8g2 include files +#U8G2INC:=../../../../csrc/ +#U8G2SRC:=$(wildcard ../../../../csrc/*.c) + +# directory for FatFS +#FFINC:=../fatfs +#FFSRC:=$(wildcard ../fatfs/*.c) + +# Directory for the linker script +LDSCRIPTDIR:=. +# Name of the linker script (must be the "keep" script, because the other script is not always working) +LDSCRIPT:=lpc804.ld + +#================================================ +# Main part of the Makefile starts here. Usually no changes are needed. + +# Internal Variable Names +LIBNAME:=$(TARGETNAME).a +ELFNAME:=$(TARGETNAME).elf +HEXNAME:=$(TARGETNAME).hex +DISNAME:=$(TARGETNAME).dis +MAPNAME:=$(TARGETNAME).map +OBJ:=$(SRC:.c=.o) $(SYSSRC:.c=.o) $(U8G2SRC:.c=.o) $(FFSRC:.c=.o) + +# Replace standard build tools by arm tools +CC:=$(GCCBINPATH)arm-none-eabi-gcc +AR:=$(GCCBINPATH)arm-none-eabi-ar +OBJCOPY:=$(GCCBINPATH)arm-none-eabi-objcopy +OBJDUMP:=$(GCCBINPATH)arm-none-eabi-objdump +SIZE:=$(GCCBINPATH)arm-none-eabi-size + +# Common flags +COMMON_FLAGS = -mthumb -mcpu=$(MCPU) +COMMON_FLAGS += -Wall -I. -I$(SYSINC) -I$(U8G2INC) +# define stack size (defaults to 0x0100) +# COMMON_FLAGS += -D__STACK_SIZE=0x0100 + +# COMMON_FLAGS += -Os -flto +COMMON_FLAGS += -Os +# COMMON_FLAGS += -fstack-protector +# COMMON_FLAGS += -finstrument-functions +# Do not use stand libs startup code. Uncomment this for gcclib procedures +# memcpy still works, but might be required for __aeabi_uidiv +# COMMON_FLAGS += -nostdlib +# remove unused data and function +COMMON_FLAGS += -ffunction-sections -fdata-sections +# COMMON_FLAGS += -ffunction-sections -fdata-sections -fshort-wchar +# C flags +CFLAGS:=$(COMMON_FLAGS) -std=gnu99 +# LD flags +# remove unreferenced procedures and variables, but keep "arm_stack_area" and __isr_vector +GC:=-Wl,--gc-sections -Wl,--undefined=arm_stack_area -Wl,--undefined=__isr_vector +MAP:=-Wl,-Map=$(MAPNAME) +LFLAGS:=$(COMMON_FLAGS) $(GC) $(MAP) +#LDLIBS:=--specs=nano.specs -L$(LDSCRIPTDIR) -T $(LDSCRIPT) +LDLIBS:=--specs=nosys.specs -L$(LDSCRIPTDIR) -T $(LDSCRIPT) + +# Additional Suffixes +.SUFFIXES: .elf .hex .bin .dis + +# Targets +.PHONY: all +all: $(DISNAME) $(HEXNAME) + $(SIZE) $(ELFNAME) + +.PHONY: upload +upload: $(DISNAME) $(HEXNAME) $(ELFNAME) + $(SIZE) $(ELFNAME) + +.PHONY: clean +clean: + $(RM) $(OBJ) $(HEXNAME) $(ELFNAME) $(LIBNAME) $(DISNAME) $(MAPNAME) libssp.a libssp_nonshared.a + +# implicit rules +.elf.hex: + $(OBJCOPY) -O ihex $< $@ + + + +# explicit rules + +$(ELFNAME): $(LIBNAME)($(OBJ)) libssp.a libssp_nonshared.a + $(LINK.o) $(LFLAGS) $(LIBNAME) $(LDLIBS) -o $@ + +$(DISNAME): $(ELFNAME) + $(OBJDUMP) -D -S $< > $@ + + +# create empty ssp libs for -fstack-protector-all -fstack-protector +libssp.a: + $(AR) rcs $@ + +libssp_nonshared.a: + $(AR) rcs $@ + + diff --git a/sys/arm/lpc804/blink/blink.a b/sys/arm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qDe2-bZkgS!iGVbJieAA-Wl10<6^(9)QNN|7UZl4ya4fG{C zApl80-y+vHZD{JgdJ|Xsu~PB4iN7Vwi=}-_ddiz>TEJZFTJgF6{pSDt|2Q?^&F?F@ z?_f+B&A7pg51TP%6!R~c@uqa8C3f$^>f$i@^`i8qYmPG z)-!NF(wrk2w9eu?;w+1r1wj + +/* Generic ARM delay procedure, based on the system timer (SysTick) */ + +/* + Delay by the provided number of system ticks. + The delay must be smaller than the RELOAD value. + This delay has an imprecision of about +/- 20 system ticks. +*/ +static void _delay_system_ticks_sub(uint32_t sys_ticks) +{ + uint32_t start_val, end_val, curr_val; + uint32_t load; + + start_val = SysTick->VAL; + start_val &= 0x0ffffffUL; + end_val = start_val; + + if ( end_val < sys_ticks ) + { + /* check, if the operation after this if clause would lead to a negative result */ + /* if this would be the case, then add the reload value first */ + load = SysTick->LOAD; + load &= 0x0ffffffUL; + end_val += load; + } + /* counter goes towards zero, so end_val is below start value */ + end_val -= sys_ticks; + + + /* wait until interval is left */ + if ( start_val >= end_val ) + { + for(;;) + { + curr_val = SysTick->VAL; + curr_val &= 0x0ffffffUL; + if ( curr_val <= end_val ) + break; + if ( curr_val > start_val ) + break; + } + } + else + { + for(;;) + { + curr_val = SysTick->VAL; + curr_val &= 0x0ffffffUL; + if ( curr_val <= end_val && curr_val > start_val ) + break; + } + } +} + +/* + Delay by the provided number of system ticks. + Any values between 0 and 0x0ffffffff are allowed. +*/ +void delay_system_ticks(uint32_t sys_ticks) +{ + uint32_t load4; + load4 = SysTick->LOAD; + load4 &= 0x0ffffffUL; + load4 >>= 2; + + while ( sys_ticks > load4 ) + { + sys_ticks -= load4; + _delay_system_ticks_sub(load4); + } + _delay_system_ticks_sub(sys_ticks); +} + +/* + Delay by the provided number of micro seconds. + Limitation: "us" * System-Freq in MHz must now overflow in 32 bit. + Values between 0 and 1.000.000 (1 second) are ok. + + Important: Call SystemCoreClockUpdate() before calling this function. +*/ +void delay_micro_seconds(uint32_t us) +{ + uint32_t sys_ticks; + + sys_ticks = main_clk; + sys_ticks /=1000000UL; + sys_ticks *= us; + delay_system_ticks(sys_ticks); +} diff --git a/sys/arm/lpc804/blink/delay.h b/sys/arm/lpc804/blink/delay.h new file mode 100644 index 00000000..563724d4 --- /dev/null +++ b/sys/arm/lpc804/blink/delay.h @@ -0,0 +1,55 @@ +/* + delay.h + + LPC11U3x GPS Logger (https://github.com/olikraus/lpc11u3x-gps-logger) + + Copyright (c) 2016, olikraus@gmail.com + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list + of conditions and the following disclaimer. + + * 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. + + 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 HOLDER 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. + +*/ + +#ifndef _DELAY_H +#define _DELAY_H + +#include + +/* + Delay by the provided number of system ticks. + Any values between 0 and 0x0ffffffff are allowed. +*/ +void delay_system_ticks(uint32_t sys_ticks); + +/* + Delay by the provided number of micro seconds. + Limitation: "us" * System-Freq in MHz must now overflow in 32 bit. + Values between 0 and 1.000.000 (1 second) are ok. + + Important: Call SystemCoreClockUpdate() before calling this function. +*/ +void delay_micro_seconds(uint32_t us); + +#endif /* _DELAY_H */ diff --git a/sys/arm/lpc804/blink/lpc804.ld b/sys/arm/lpc804/blink/lpc804.ld new file mode 100644 index 00000000..dbd3ccdf --- /dev/null +++ b/sys/arm/lpc804/blink/lpc804.ld @@ -0,0 +1,177 @@ +/* source: gcc-arm-none-eabi-4_7-2013q1/share/gcc-arm-none-eabi/samples/ldscripts/mem.ld */ + +/* Linker script to configure memory regions. + * Need modifying for a specific board. + * FLASH.ORIGIN: starting address of flash + * FLASH.LENGTH: length of flash + * RAM.ORIGIN: starting address of RAM bank 0 + * RAM.LENGTH: length of RAM bank 0 + */ +MEMORY +{ + /* LPC804 */ + FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x8000 /* 32K for LPC804 */ + RAM (rwx) : ORIGIN = 0x10000000, LENGTH = 0x1000 /* 4K for LPC804 */ +} + +/* source: gcc-arm-none-eabi-4_7-2013q1/share/gcc-arm-none-eabi/samples/ldscripts/sections.ld */ + +/* Linker script to place sections and symbol values. Should be used together + * with other linker script that defines memory regions FLASH and RAM. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __exidx_start + * __exidx_end + * __etext + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __data_end__ + * __bss_start__ + * __bss_end__ + * __end__ + * end + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + */ + +/* entry point */ +ENTRY(Reset_Handler) + +/* extern declaration so that the value appears correctly for the LPC checksum calculation */ +EXTERN(NMI_Handler) +EXTERN(HardFault_Handler) + +SECTIONS +{ + .text : + { + KEEP(*(.isr_vector)) + *(.text*) + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + + KEEP(*(.eh_frame*)) + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + __etext = .; + + .data : AT (__etext) + { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + KEEP(*(.jcr*)) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + + } > RAM + + .bss : + { + . = ALIGN(4); + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + end = __end__; + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") + + /* + http://www.lpcware.com/content/forum/lpc1788-flash-signature-generation + Section 3.5.2/page 12 of the LPC82x User Manual + + Linker works with even addresses, however to indicate thumb address mode, + the lowest bit of the address is set to one. For the checksum calculation we + only have the even addresses, however later in the isr table the compiler will + store the odd addresses for the three handler subprocedures if compiled in + thumb mode. Because of this, 3 is added to consider the three odd handler calls. + */ + LPC_checksum = 0- (__StackTop + Reset_Handler + NMI_Handler + HardFault_Handler + 3 /* three entries */); +} + diff --git a/sys/arm/lpc804/blink/main.c b/sys/arm/lpc804/blink/main.c new file mode 100644 index 00000000..7c29f491 --- /dev/null +++ b/sys/arm/lpc804/blink/main.c @@ -0,0 +1,62 @@ + +#include +#include +#include +#include + + +/*=======================================================================*/ +/* Configuration */ +#define SYS_TICK_PERIOD_IN_MS 100 + + +/*=======================================================================*/ +/* system procedures and sys tick master task */ + + + +volatile uint32_t sys_tick_irq_cnt=0; + + +void __attribute__ ((interrupt)) SysTick_Handler(void) +{ + sys_tick_irq_cnt++; +} + +/*=======================================================================*/ +/* + setup the hardware and start interrupts. + called by "Reset_Handler" +*/ +int __attribute__ ((noinline)) main(void) +{ + + /* call to the lpc lib setup procedure. This will set the IRC as clk src and main clk to 24 MHz */ + SystemInit(); + + /* if the clock or PLL has been changed, also update the global variable SystemCoreClock */ + SystemCoreClockUpdate(); + + /* set systick and start systick interrupt */ + SysTick_Config(main_clk/1000UL*(unsigned long)SYS_TICK_PERIOD_IN_MS); + + /* */ + GPIOInit(); + + /* enable clock for several subsystems */ + + Enable_Periph_Clock(CLK_IOCON); + Enable_Periph_Clock(CLK_SWM); + + + //Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, IOCON_FUNC1); /* RxD */ + Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 15); + + for(;;) + { + Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 15); + delay_micro_seconds(1000000); + Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 15); + delay_micro_seconds(1000000); + } +} diff --git a/sys/arm/lpc804/blink/startup.c b/sys/arm/lpc804/blink/startup.c new file mode 100644 index 00000000..9c5acd04 --- /dev/null +++ b/sys/arm/lpc804/blink/startup.c @@ -0,0 +1,201 @@ + +/* + + startup.c + + LPC804 + + Copyright (c) 2016, olikraus@gmail.com + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list + of conditions and the following disclaimer. + + * 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. + + 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 HOLDER 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. + + + Requires code from the LPC804 example zip files + +*/ +#include + + +/*=======================================================================*/ +/* external functions */ +void __attribute__ ((interrupt)) SysTick_Handler(void); +//void __attribute__ ((interrupt, used)) UART_IRQ(void); +int __attribute__ ((noinline)) main(void); + + + +/*=======================================================================*/ +/* + Reserve some space for the stack. This is used to check if global variables + stack exceed RAM size. + If -Wl,--gc-sections is used, then also define -Wl,--undefined=arm_stack_area to keep the variable in RAM. + The name of the variable (here: arm_stack_area) does not matter. + + Heap (=dynamic memory allocation) is not supported +*/ +#ifndef __STACK_SIZE +#define __STACK_SIZE 0x100 +#endif +unsigned char arm_stack_area[__STACK_SIZE] __attribute__ ((section(".stack"))) __attribute__ ((aligned(8))); + + +/*=======================================================================*/ +/* isr system procedures */ + +/* make the top of the stack known to the c compiler, value will be calculated by the linker script */ +void __StackTop(void); + +void __attribute__ ((interrupt)) __attribute__ ((noreturn)) Reset_Handler(void) +{ + register unsigned long *ptr; + register unsigned long *start; + register unsigned long *end; + + /* + The following two operations are not required in normal mode reset mode, + however it is usefull if the reset handler is started via ISP "Go" command + */ + __set_MSP((uint32_t)__StackTop); + //Chip_SYSCTL_Map(2); + LPC_SYSCON->SYSMEMREMAP = (uint32_t) 2; // user flash mode: use user isr vector table + + /* + Loop to copy data from read only memory to RAM. The ranges + of copy from/to are specified by following symbols evaluated in + linker script. + __etext: End of code section, i.e., begin of data sections to copy from. + __data_start__/__data_end__: RAM address range that data should be + copied to. Both must be aligned to 4 bytes boundary. + */ + extern unsigned long __data_start__[]; + extern unsigned long __data_end__[]; + extern unsigned long __etext[]; + ptr = __etext; + start = __data_start__; + end = __data_end__; + while( start < end ) + { + *start = *ptr; + start++; + ptr++; + } + + /* + Loop to zero out BSS section, which uses following symbols + in linker script: + __bss_start__: start of BSS section. Must align to 4 + __bss_end__: end of BSS section. Must align to 4 + */ + extern unsigned long __bss_start__[]; + extern unsigned long __bss_end__[]; + ptr = __bss_start__; + end = __bss_end__; + while( ptr < end ) + { + *ptr = 0; + ptr++; + } + + /* Call main procedure */ + main(); + + /* finished, do nothing. */ + for(;;) + ; +} + +/* "NMI_Handler" is used in the ld script to calculate the checksum */ +void __attribute__ ((interrupt)) NMI_Handler(void) +{ +} + +/* "HardFault_Handler" is used in the ld script to calculate the checksum */ +void __attribute__ ((interrupt)) HardFault_Handler(void) +{ +} + +/* make the checksum known to the c compiler, value will be calculated by the linker script */ +void LPC_checksum(void); + +/*=======================================================================*/ +/* isr vector */ +/* based on LPC8xx.h */ +/* see table 38 of the LPC804 user manual (page 39) */ + +typedef void (*isr_handler_t)(void); +isr_handler_t __isr_vector[48] __attribute__ ((section(".isr_vector"))) __attribute__ ((aligned(4)))= +{ + __StackTop, /* 0x00: Top of Stack, calculated by the linker script */ + Reset_Handler, /* -15, 0x04: Reset Handler, DO NOT CHANGE THE ISR NAME (used for LPC_checksum calculation) */ + NMI_Handler, /* .14, 0x08: NMI Handler, DO NOT CHANGE THE ISR NAME (used for LPC_checksum calculation) */ + HardFault_Handler, /* -13, 0x0c: Hard Fault Handler, DO NOT CHANGE THE ISR NAME (used for LPC_checksum calculation) */ + 0, /* 0x10: Reserved, must be 0 */ + 0, /* 0x14: Reserved, must be 0 */ + 0, /* 0x18: Reserved, must be 0 */ + LPC_checksum, /* 0x1c: Checksum, calculated by the linker script or the flash utility */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* -5, SVCall Handler */ + 0, /* -4, Reserved */ + 0, /* -3, Reserved */ + 0, /* -2, PendSV Handler */ + SysTick_Handler, /* -1, SysTick Handler */ + + + 0, /* 0 SPI0_IRQn, SPI0 controller */ + 0, /* 1 Not used/Reserved */ + 0, /* 2 DAC0_IRQn, DAC0 Interrupt */ + 0, /* 3 UART0_IRQn, USART0 */ + 0, /* 4 UART1_IRQn, USART1 */ + 0, /* 5 Not used */ + 0, /* 6 Not used */ + 0, /* 7 I2C1 controller */ + 0, /* 8 I2C0 controller */ + 0, /* 9 Not used/Reserved */ + 0, /* 10 MRT_IRQnMulti-Rate Timer */ + 0, /* 11 CMP_IRQn, Analog Comparator /CapTouch*/ + 0, /* 12 WDT_IRQn WDT */ + 0, /* 13 BOD_IRQn BOD Brown Out Detect */ + 0, /* 14 FLASH_IRQn (/Reserved according to the user manual) */ + 0, /* 15 WKT_IRQn Self wake-up timer */ + 0, /* 16 ADC_SEQA_IRQn */ + 0, /* 17 ADC_SEQB_IRQn */ + 0, /* 18 ADC_THCMP_IRQn ADC threshold compare */ + 0, /* 19 ADC_OVR_IRQn ADC overrun */ + 0, /* 20 Not used/Reserved */ + 0, /* 21 Not used/Reserved */ + 0, /* 22 Not used/Reserved */ + 0, /* 23 CTIMER0_IRQn, CT32B0_IRQ */ + 0, /* 24 PIO INT0 */ + 0, /* 25 PIO INT1 */ + 0, /* 26 PIO INT2 */ + 0, /* 27 PIO INT3 */ + 0, /* 28 PIO INT4 */ + 0, /* 29 PIO INT5 */ + 0, /* 30 PIO INT6 */ + 0 /* 31 PIO INT7 */ +}; + diff --git a/sys/arm/lpc804/lpc_chip_804/inc/i2c.h b/sys/arm/lpc804/lpc_chip_804/inc/i2c.h index 159fa638..ce9e58bc 100644 --- a/sys/arm/lpc804/lpc_chip_804/inc/i2c.h +++ b/sys/arm/lpc804/lpc_chip_804/inc/i2c.h @@ -21,7 +21,7 @@ #ifndef lpc8xx_I2C_H_ #define lpc8xx_I2C_H_ -#include "lpc8xx.h" +#include "LPC8xx.h" #define RD_BIT 0x01 diff --git a/sys/arm/lpc804/lpc_chip_804/inc/spi.h b/sys/arm/lpc804/lpc_chip_804/inc/spi.h index f3d5c8e4..c2b6fd3a 100644 --- a/sys/arm/lpc804/lpc_chip_804/inc/spi.h +++ b/sys/arm/lpc804/lpc_chip_804/inc/spi.h @@ -23,6 +23,7 @@ #define lpc8xx_SPI_H_ #include "LPC8xx.h" +#include "swm.h" #define SPI_FLASH_CS1() (LPC_GPIO_PORT->SET[0] = 1<CLR[0] = 1< + #ifndef LPC8XX_SYSCON_H_ #define LPC8XX_SYSCON_H_ @@ -205,11 +207,11 @@ typedef enum { -void Enable_Periph_Clock(unsigned int slot); -void Disable_Periph_Clock(unsigned int slot); -void Do_Periph_Reset(unsigned int slot); -void Config_Syspll(unsigned int which_clock, unsigned int pll_ctrl_value); -void Config_Fclksel_Mux(unsigned int to_which_periph, unsigned int which_clock); +void Enable_Periph_Clock(uint32_t slot); +void Disable_Periph_Clock(uint32_t slot); +void Do_Periph_Reset(uint32_t slot); +//void Config_Syspll(unsigned int which_clock, unsigned int pll_ctrl_value); +void Config_Fclksel_Mux(uint32_t to_which_periph, uint32_t which_clock); diff --git a/sys/arm/lpc804/lpc_chip_804/info.txt b/sys/arm/lpc804/lpc_chip_804/info.txt index 69cbc840..6bd12ccb 100644 --- a/sys/arm/lpc804/lpc_chip_804/info.txt +++ b/sys/arm/lpc804/lpc_chip_804/info.txt @@ -3,4 +3,23 @@ Source: LPC804-EX-CODE-MCUXPRESSO.zip from nxp.com the file inc/chip_setup.h might depend on then project, but should be a good starting point. +Toplevel include should be "LPC8xx.h". +The name "LPC8xx.h" might be misleading: This file is specific to the LPC804, but +i decided to to change the name, but keep the orginal file name from the above zip +folder. In fact plan is not to modify any of the files in lpc_chip_804 so that they can +be overwritten at any time with the original files (maybe chip_setup.h is an exception). + +For some reason the variable "SystemCoreClock" is renamed to "main_clk". + +While working in the code, I saw, that there are some issues in "lpc_chip_804": + - Removed includes of "utilities.h" because the funcionality is not called + - added inclusion of "swm.h" from "spi.h", because "spi.h" makes use of + some definitions from "swm.h" + - Removed "Config_Syspll" declaration from "syscon.h" because it is removed in the src. + - Alligned "unsigned int" with "uint32_t" declarations in syscon.h and .c + - Change the inclusion of "lpc8xx.h" to "LPC8xx.h" in i2c.h + + As a conclusion, I had to change the following files: + i2c.h syscon.h syscon.c i2c.c spi.c spi.h plu.c + \ No newline at end of file diff --git a/sys/arm/lpc804/lpc_chip_804/src/i2c.c b/sys/arm/lpc804/lpc_chip_804/src/i2c.c index 64857630..db6e5fc4 100644 --- a/sys/arm/lpc804/lpc_chip_804/src/i2c.c +++ b/sys/arm/lpc804/lpc_chip_804/src/i2c.c @@ -6,7 +6,7 @@ */ #include "LPC8xx.h" -#include "utilities.h" +//#include "utilities.h" #include "i2c.h" /***************************************************************************** diff --git a/sys/arm/lpc804/lpc_chip_804/src/plu.c b/sys/arm/lpc804/lpc_chip_804/src/plu.c index cb4e727d..614cef76 100644 --- a/sys/arm/lpc804/lpc_chip_804/src/plu.c +++ b/sys/arm/lpc804/lpc_chip_804/src/plu.c @@ -30,7 +30,6 @@ #include "LPC8xx.h" #include "core_cm0plus.h" #include "syscon.h" -#include "utilities.h" #include "plu.h" #include diff --git a/sys/arm/lpc804/lpc_chip_804/src/spi.c b/sys/arm/lpc804/lpc_chip_804/src/spi.c index d3807ac0..377a3db9 100644 --- a/sys/arm/lpc804/lpc_chip_804/src/spi.c +++ b/sys/arm/lpc804/lpc_chip_804/src/spi.c @@ -6,7 +6,7 @@ */ #include "LPC8xx.h" -#include "utilities.h" +//#include "utilities.h" #include "spi.h" uint32_t SPI_RXCount, SPI_TXCount; diff --git a/sys/arm/lpc804/lpc_chip_804/src/syscon.c b/sys/arm/lpc804/lpc_chip_804/src/syscon.c index 17e7c9d0..e8ebbe8c 100644 --- a/sys/arm/lpc804/lpc_chip_804/src/syscon.c +++ b/sys/arm/lpc804/lpc_chip_804/src/syscon.c @@ -41,7 +41,7 @@ void Disable_Periph_Clock(uint32_t slot) { // Function: Do_Periph_Reset // Use like this: Do_Periph_Reset(RESET_SPI0); // -void Do_Periph_Reset(unsigned int slot) { +void Do_Periph_Reset(uint32_t slot) { if (slot < 32) { LPC_SYSCON->PRESETCTRL[0] &= ~(1<PRESETCTRL[0] |= (1<