aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-08-21 20:27:15 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-08-22 09:58:58 -0400
commit1022729a2adbeeb985848e82bb07f7af4d079c06 (patch)
tree84665cfd82f576ef79c6ca6aace816dbbe4da570
parent6409eda0580810599422c2a8a2ddce171d9e47ad (diff)
downloadkutter-1022729a2adbeeb985848e82bb07f7af4d079c06.tar.gz
kutter-1022729a2adbeeb985848e82bb07f7af4d079c06.tar.xz
kutter-1022729a2adbeeb985848e82bb07f7af4d079c06.zip
lpc176x: Update code to use armcm_boot mechanism
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/lpc176x/Kconfig16
-rw-r--r--src/lpc176x/Makefile34
-rw-r--r--src/lpc176x/adc.c7
-rw-r--r--src/lpc176x/gpio.c1
-rw-r--r--src/lpc176x/i2c.c1
-rw-r--r--src/lpc176x/main.c4
-rw-r--r--src/lpc176x/serial.c7
-rw-r--r--src/lpc176x/spi.c1
-rw-r--r--src/lpc176x/usbserial.c7
9 files changed, 37 insertions, 41 deletions
diff --git a/src/lpc176x/Kconfig b/src/lpc176x/Kconfig
index 9bd5c6d2..9c09d46e 100644
--- a/src/lpc176x/Kconfig
+++ b/src/lpc176x/Kconfig
@@ -28,6 +28,22 @@ config CLOCK_FREQ
default 100000000 if MACH_LPC1768
default 120000000 if MACH_LPC1769
+config FLASH_SIZE
+ hex
+ default 0x80000
+
+config RAM_START
+ hex
+ default 0x10000000
+
+config RAM_SIZE
+ hex
+ default 0x7fe0 # (0x8000 - 32) - top 32 bytes used by IAP functions
+
+config STACK_SIZE
+ int
+ default 512
+
config SMOOTHIEWARE_BOOTLOADER
bool "Target board uses Smoothieware bootloader"
default y
diff --git a/src/lpc176x/Makefile b/src/lpc176x/Makefile
index 2e932b84..f4966ff7 100644
--- a/src/lpc176x/Makefile
+++ b/src/lpc176x/Makefile
@@ -3,40 +3,25 @@
# Setup the toolchain
CROSS_PREFIX=arm-none-eabi-
-dirs-y += src/lpc176x src/generic
-dirs-y += lib/lpc176x/device/TOOLCHAIN_GCC_ARM
+dirs-y += src/lpc176x src/generic lib/lpc176x/device
-CFLAGS += -mthumb -mcpu=cortex-m3
-CFLAGS += -Ilib/lpc176x/device -Ilib/cmsis-core
+CFLAGS += -mthumb -mcpu=cortex-m3 -Ilib/lpc176x/device -Ilib/cmsis-core
+
+CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs
+CFLAGS_klipper.elf += -T $(OUT)src/generic/armcm_boot.ld
+$(OUT)klipper.elf: $(OUT)src/generic/armcm_boot.ld
# Add source files
src-y += lpc176x/main.c lpc176x/gpio.c
+src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_timer.c
+src-y += generic/crc16_ccitt.c
+src-y += ../lib/lpc176x/device/system_LPC17xx.c
src-$(CONFIG_HAVE_GPIO_ADC) += lpc176x/adc.c
src-$(CONFIG_HAVE_GPIO_I2C) += lpc176x/i2c.c
src-$(CONFIG_HAVE_GPIO_SPI) += lpc176x/spi.c
-src-y += generic/crc16_ccitt.c generic/alloc.c
-src-y += generic/armcm_irq.c generic/armcm_timer.c
-src-y += ../lib/lpc176x/device/system_LPC17xx.c
src-$(CONFIG_USBSERIAL) += lpc176x/usbserial.c generic/usb_cdc.c
src-$(CONFIG_SERIAL) += lpc176x/serial.c generic/serial_irq.c
-# Add assembler build rules
-$(OUT)%.o: %.S
- @echo " Assembling $@"
- $(Q)$(AS) $< -o $@
-
-asmsrc-y := ../lib/lpc176x/device/TOOLCHAIN_GCC_ARM/startup_LPC17xx.S
-OBJS_klipper.elf += $(patsubst %.S, $(OUT)src/%.o,$(asmsrc-y))
-
-# Build the linker script
-$(OUT)LPC1768.ld: lib/lpc176x/device/TOOLCHAIN_GCC_ARM/LPC1768.ld $(OUT)board-link
- @echo " Preprocessing $@"
- $(Q)$(CPP) -P -MD -MT $@ -DMBED_APP_START=$(CONFIG_FLASH_START) -DMBED_APP_SIZE="(512K - $(CONFIG_FLASH_START))" $< -o $@
-
-CFLAGS_klipper.elf += -T $(OUT)LPC1768.ld
-CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs
-$(OUT)klipper.elf : $(OUT)LPC1768.ld
-
# Build the additional bin output file
target-y += $(OUT)klipper.bin
@@ -44,6 +29,7 @@ $(OUT)klipper.bin: $(OUT)klipper.elf
@echo " Creating bin file $@"
$(Q)$(OBJCOPY) -O binary $< $@
+# Flash rules
flash: $(OUT)klipper.bin
@echo " Flashing $< to $(FLASH_DEVICE)"
$(Q)$(PYTHON) ./scripts/flash_usb.py -t lpc176x -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin
diff --git a/src/lpc176x/adc.c b/src/lpc176x/adc.c
index e89d73a4..97e24c16 100644
--- a/src/lpc176x/adc.c
+++ b/src/lpc176x/adc.c
@@ -4,8 +4,8 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
-#include "LPC17xx.h" // LPC_PINCON
#include "autoconf.h" // CONFIG_CLOCK_FREQ
+#include "board/armcm_boot.h" // armcm_enable_irq
#include "board/irq.h" // irq_save
#include "board/misc.h" // timer_from_us
#include "command.h" // shutdown
@@ -37,7 +37,7 @@ static struct {
enum { ADC_DONE=0x0100 };
// ADC hardware irq handler
-void __visible
+void
ADC_IRQHandler(void)
{
uint32_t pos = adc_status.pos, chan = adc_status.chan & 0xff;
@@ -71,8 +71,7 @@ gpio_adc_setup(uint8_t pin)
LPC_ADC->ADCR = adc_status.adcr = (1<<21) | ((prescal & 0xff) << 8);
LPC_ADC->ADINTEN = 0xff;
adc_status.chan = ADC_DONE;
- NVIC_SetPriority(ADC_IRQn, 0);
- NVIC_EnableIRQ(ADC_IRQn);
+ armcm_enable_irq(ADC_IRQHandler, ADC_IRQn, 0);
}
gpio_peripheral(pin, adc_pin_funcs[chan], 0);
diff --git a/src/lpc176x/gpio.c b/src/lpc176x/gpio.c
index b7afda74..35a5a226 100644
--- a/src/lpc176x/gpio.c
+++ b/src/lpc176x/gpio.c
@@ -5,7 +5,6 @@
// This file may be distributed under the terms of the GNU GPLv3 license.
#include <string.h> // ffs
-#include "LPC17xx.h" // LPC_PINCON
#include "board/irq.h" // irq_save
#include "command.h" // shutdown
#include "gpio.h" // gpio_out_setup
diff --git a/src/lpc176x/i2c.c b/src/lpc176x/i2c.c
index 7b87083f..ec5d4b50 100644
--- a/src/lpc176x/i2c.c
+++ b/src/lpc176x/i2c.c
@@ -4,7 +4,6 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
-#include "LPC17xx.h" // LPC_I2C1
#include "board/misc.h" // timer_is_before
#include "command.h" // DECL_COMMAND
#include "gpio.h" // i2c_setup
diff --git a/src/lpc176x/main.c b/src/lpc176x/main.c
index d522a014..62c5c207 100644
--- a/src/lpc176x/main.c
+++ b/src/lpc176x/main.c
@@ -4,10 +4,10 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
-#include "LPC17xx.h" // NVIC_SystemReset
+#include "board/misc.h" // timer_read_time
#include "command.h" // DECL_CONSTANT
+#include "internal.h" // NVIC_SystemReset
#include "sched.h" // sched_main
-#include "board/misc.h" // timer_read_time
DECL_CONSTANT_STR("MCU", "lpc176x");
diff --git a/src/lpc176x/serial.c b/src/lpc176x/serial.c
index f36a485c..3d0432ba 100644
--- a/src/lpc176x/serial.c
+++ b/src/lpc176x/serial.c
@@ -4,7 +4,7 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
-#include "LPC17xx.h" // LPC_UART0
+#include "board/armcm_boot.h" // armcm_enable_irq
#include "autoconf.h" // CONFIG_SERIAL_BAUD
#include "board/irq.h" // irq_save
#include "board/serial_irq.h" // serial_rx_data
@@ -33,7 +33,7 @@ kick_tx(void)
}
}
-void __visible
+void
UART0_IRQHandler(void)
{
uint32_t iir = LPC_UART0->IIR, status = iir & 0x0f;
@@ -76,8 +76,7 @@ serial_init(void)
gpio_peripheral(GPIO(0, 2), 1, 0);
// Enable receive irq
- NVIC_SetPriority(UART0_IRQn, 0);
- NVIC_EnableIRQ(UART0_IRQn);
+ armcm_enable_irq(UART0_IRQHandler, UART0_IRQn, 0);
LPC_UART0->IER = 0x01;
}
DECL_INIT(serial_init);
diff --git a/src/lpc176x/spi.c b/src/lpc176x/spi.c
index bfdb8fe8..c297fb01 100644
--- a/src/lpc176x/spi.c
+++ b/src/lpc176x/spi.c
@@ -4,7 +4,6 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
-#include "LPC17xx.h" // LPC_SSP0
#include "command.h" // shutdown
#include "gpio.h" // spi_setup
#include "internal.h" // gpio_peripheral
diff --git a/src/lpc176x/usbserial.c b/src/lpc176x/usbserial.c
index 90e72cc4..95ce6e74 100644
--- a/src/lpc176x/usbserial.c
+++ b/src/lpc176x/usbserial.c
@@ -5,8 +5,8 @@
// This file may be distributed under the terms of the GNU GPLv3 license.
#include <string.h> // memcpy
-#include "LPC17xx.h" // LPC_SC
#include "autoconf.h" // CONFIG_SMOOTHIEWARE_BOOTLOADER
+#include "board/armcm_boot.h" // armcm_enable_irq
#include "board/armcm_timer.h" // udelay
#include "board/irq.h" // irq_disable
#include "board/misc.h" // timer_read_time
@@ -265,7 +265,7 @@ usb_request_bootloader(void)
* Setup and interrupts
****************************************************************/
-void __visible
+void
USB_IRQHandler(void)
{
uint32_t udis = LPC_USB->USBDevIntSt;
@@ -319,8 +319,7 @@ usbserial_init(void)
sie_cmd_write(SIE_CMD_SET_DEVICE_STATUS, 1);
// enable irqs
LPC_USB->USBDevIntEn = DEV_STAT | EP_SLOW;
- NVIC_SetPriority(USB_IRQn, 1);
- usb_irq_enable();
+ armcm_enable_irq(USB_IRQHandler, USB_IRQn, 1);
}
DECL_INIT(usbserial_init);