Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Klipper3d/klipper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2022-10-22 04:50:21 +0300
committerKevin O'Connor <kevin@koconnor.net>2022-11-08 17:53:04 +0300
commit6485ff800b56dbb4578afde88e7d22f6b0a25dc8 (patch)
treec68e762a9abd6af3af31292bf4ccedc30e95e9c9
parent42e9adcfc9963b54c71e8851e1a6a41a001531e5 (diff)
rp2040: Support CanBoot as bootloader
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/rp2040/Kconfig25
-rw-r--r--src/rp2040/Makefile28
-rw-r--r--src/rp2040/main.c2
3 files changed, 41 insertions, 14 deletions
diff --git a/src/rp2040/Kconfig b/src/rp2040/Kconfig
index 148222d7e..69b1cd58e 100644
--- a/src/rp2040/Kconfig
+++ b/src/rp2040/Kconfig
@@ -47,17 +47,32 @@ config STACK_SIZE
int
default 512
-config FLASH_START
- hex
- default 0x10000100
-
######################################################################
# Bootloader options
######################################################################
+config RP2040_HAVE_STAGE2
+ bool
+config RP2040_HAVE_BOOTLOADER
+ bool
+ default y if !RP2040_HAVE_STAGE2
+
+choice
+ prompt "Bootloader offset"
+ config RP2040_FLASH_START_0100
+ bool "No bootloader"
+ select RP2040_HAVE_STAGE2
+ config RP2040_FLASH_START_4000
+ bool "16KiB bootloader"
+endchoice
+config FLASH_START
+ hex
+ default 0x10004000 if RP2040_FLASH_START_4000
+ default 0x10000100
+
choice
- prompt "Flash chip" if LOW_LEVEL_OPTIONS
+ prompt "Flash chip" if LOW_LEVEL_OPTIONS && RP2040_HAVE_STAGE2
config RP2040_FLASH_W25Q080
bool "W25Q080 with CLKDIV 2"
config RP2040_FLASH_GENERIC_03
diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile
index 5bb572fb2..47954c9a3 100644
--- a/src/rp2040/Makefile
+++ b/src/rp2040/Makefile
@@ -8,10 +8,6 @@ dirs-y += src/rp2040 src/generic lib/rp2040/elf2uf2 lib/fast-hash lib/can2040
CFLAGS += -mcpu=cortex-m0plus -mthumb -Ilib/cmsis-core
CFLAGS += -Ilib/rp2040 -Ilib/rp2040/cmsis_include -Ilib/fast-hash -Ilib/can2040
-CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs
-CFLAGS_klipper.elf += -T $(OUT)src/rp2040/rp2040_link.ld
-$(OUT)klipper.elf: $(OUT)stage2.o $(OUT)src/rp2040/rp2040_link.ld
-
# Add source files
src-y += rp2040/main.c rp2040/gpio.c rp2040/adc.c generic/crc16_ccitt.c
src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c
@@ -38,11 +34,8 @@ $(OUT)stage2.o: lib/rp2040/boot_stage2/$(STAGE2_FILE) $(OUT)autoconf.h
$(Q)$(OBJCOPY) -O binary $(OUT)stage2raw.o $(OUT)stage2raw.bin
$(Q)lib/rp2040/boot_stage2/pad_checksum -s 0xffffffff $(OUT)stage2raw.bin $(OUT)stage2.S
$(Q)$(CC) $(CFLAGS) -c $(OUT)stage2.S -o $(OUT)stage2.o
-OBJS_klipper.elf += $(OUT)stage2.o
-
-# Binary output file rules
-target-y += $(OUT)klipper.uf2
+# Binary output file rules when using stage2
$(OUT)lib/rp2040/elf2uf2/elf2uf2: lib/rp2040/elf2uf2/main.cpp
@echo " Building $@"
$(Q)g++ -g -O -Ilib/rp2040 $< -o $@
@@ -51,11 +44,28 @@ $(OUT)klipper.uf2: $(OUT)klipper.elf $(OUT)lib/rp2040/elf2uf2/elf2uf2
@echo " Creating uf2 file $@"
$(Q)$(OUT)lib/rp2040/elf2uf2/elf2uf2 $< $@
+target-$(CONFIG_RP2040_HAVE_STAGE2) += $(OUT)klipper.uf2
+rplink-$(CONFIG_RP2040_HAVE_STAGE2) := $(OUT)src/rp2040/rp2040_link.ld
+stage2-$(CONFIG_RP2040_HAVE_STAGE2) := $(OUT)stage2.o
+
+# rp2040 building when using a bootloader
+$(OUT)klipper.bin: $(OUT)klipper.elf
+ @echo " Creating bin file $@"
+ $(Q)$(OBJCOPY) -O binary $< $@
+
+target-$(CONFIG_RP2040_HAVE_BOOTLOADER) += $(OUT)klipper.bin
+rplink-$(CONFIG_RP2040_HAVE_BOOTLOADER) := $(OUT)src/generic/armcm_link.ld
+
+# Set klipper.elf linker rules
+CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs -T $(rplink-y)
+OBJS_klipper.elf += $(stage2-y)
+$(OUT)klipper.elf: $(stage2-y) $(rplink-y)
+
+# Flash rules
lib/rp2040_flash/rp2040_flash:
@echo " Building rp2040_flash"
$(Q)make -C lib/rp2040_flash rp2040_flash
-# Flash rules
flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash
@echo " Flashing $< to $(FLASH_DEVICE)"
$(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.uf2
diff --git a/src/rp2040/main.c b/src/rp2040/main.c
index 462e69c69..eac3a0b93 100644
--- a/src/rp2040/main.c
+++ b/src/rp2040/main.c
@@ -6,6 +6,7 @@
#include <stdint.h> // uint32_t
#include "board/misc.h" // bootloader_request
+#include "generic/armcm_reset.h" // try_request_canboot
#include "hardware/structs/clocks.h" // clock_hw_t
#include "hardware/structs/pll.h" // pll_hw_t
#include "hardware/structs/resets.h" // sio_hw
@@ -45,6 +46,7 @@ DECL_INIT(watchdog_init);
void
bootloader_request(void)
{
+ try_request_canboot();
// Use the bootrom-provided code to reset into BOOTSEL mode
reset_to_usb_boot(0, 0);
}