aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rp2040/Makefile2
-rw-r--r--src/rp2040/bootrom.c25
-rw-r--r--src/rp2040/internal.h2
-rw-r--r--src/rp2040/usbserial.c3
4 files changed, 30 insertions, 2 deletions
diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile
index 07c02a13..b65e1757 100644
--- a/src/rp2040/Makefile
+++ b/src/rp2040/Makefile
@@ -15,7 +15,7 @@ $(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
-src-y += generic/timer_irq.c rp2040/timer.c
+src-y += generic/timer_irq.c rp2040/timer.c rp2040/bootrom.c
src-$(CONFIG_USBSERIAL) += rp2040/usbserial.c generic/usb_cdc.c
src-$(CONFIG_SERIAL) += rp2040/serial.c generic/serial_irq.c
diff --git a/src/rp2040/bootrom.c b/src/rp2040/bootrom.c
new file mode 100644
index 00000000..da2da18e
--- /dev/null
+++ b/src/rp2040/bootrom.c
@@ -0,0 +1,25 @@
+// Hardware interface to bootrom on rp2040
+//
+// Copyright (C) 2021 Lasse Dalegaard <dalegaard@gmail.com>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include <stdint.h> // uint16_t, uint32_t, uintptr_t
+
+static void *
+rom_func_lookup(uint32_t code)
+{
+ // Table and lookup function are provided by the BOOTROM
+ void *(*fn)(uint16_t *, uint32_t) =
+ (void *)(uintptr_t)(*(uint16_t *)0x18);
+ uint16_t *table = (uint16_t *)(uintptr_t)(*(uint16_t *)0x14);
+ return fn(table, code);
+}
+
+void
+reset_to_usb_boot(uint32_t gpio_activity_pin_mask
+ , uint32_t disable_interface_mask)
+{
+ void (*reset_to_usb_boot)(uint32_t, uint32_t) = rom_func_lookup(0x4255);
+ reset_to_usb_boot(gpio_activity_pin_mask, disable_interface_mask);
+}
diff --git a/src/rp2040/internal.h b/src/rp2040/internal.h
index 8c48640a..2950801a 100644
--- a/src/rp2040/internal.h
+++ b/src/rp2040/internal.h
@@ -8,5 +8,7 @@ void enable_pclock(uint32_t reset_bit);
int is_enabled_pclock(uint32_t reset_bit);
uint32_t get_pclock_frequency(uint32_t reset_bit);
void gpio_peripheral(uint32_t gpio, int func, int pull_up);
+void reset_to_usb_boot(uint32_t gpio_activity_pin_mask
+ , uint32_t disable_interface_mask);
#endif // internal.h
diff --git a/src/rp2040/usbserial.c b/src/rp2040/usbserial.c
index 9d3e2f87..3cd2e9d8 100644
--- a/src/rp2040/usbserial.c
+++ b/src/rp2040/usbserial.c
@@ -153,7 +153,8 @@ usb_set_configure(void)
void
usb_request_bootloader(void)
{
- // XXX
+ // Use the bootrom-provided code to reset into BOOTSEL mode
+ reset_to_usb_boot(0, 0);
}