diff options
author | Lasse Dalegaard <dalegaard@gmail.com> | 2021-07-03 12:49:33 +0200 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-07-04 11:30:19 -0400 |
commit | 0597210cb9f550cd2f410214ec8b48503ce94c81 (patch) | |
tree | 09527a26239c99d89f992cb04b5942f5be8e5fd8 /src | |
parent | bb2f27f928085861b4bc9ad0c4886a5635fd3326 (diff) | |
download | kutter-0597210cb9f550cd2f410214ec8b48503ce94c81.tar.gz kutter-0597210cb9f550cd2f410214ec8b48503ce94c81.tar.xz kutter-0597210cb9f550cd2f410214ec8b48503ce94c81.zip |
rp2040: support usb_request_bootloader
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/rp2040/Makefile | 2 | ||||
-rw-r--r-- | src/rp2040/bootrom.c | 25 | ||||
-rw-r--r-- | src/rp2040/internal.h | 2 | ||||
-rw-r--r-- | src/rp2040/usbserial.c | 3 |
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); } |