From 9b342c65c8a038ff980645452ab84556376bedc7 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 14 Dec 2022 18:44:07 -0500 Subject: [PATCH 01/40] armcm_link: Rename CONFIG_FLASH_START to CONFIG_FLASH_APPLICATION_ADDRESS Rename the build symbol name for better clarity on what it represents. Signed-off-by: Kevin O'Connor --- src/atsam/Kconfig | 10 ++++---- src/atsamd/Kconfig | 44 ++++++++++++++++++++++++------------ src/atsamd/main.c | 2 +- src/generic/armcm_link.lds.S | 4 ++-- src/generic/armcm_reset.c | 4 ++-- src/lpc176x/Kconfig | 2 +- src/lpc176x/main.c | 2 +- src/rp2040/Kconfig | 2 +- src/stm32/Kconfig | 4 ++-- src/stm32/Makefile | 2 +- 10 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/atsam/Kconfig b/src/atsam/Kconfig index af3d067df8d0..4e2e839ec93f 100644 --- a/src/atsam/Kconfig +++ b/src/atsam/Kconfig @@ -65,11 +65,6 @@ config CLOCK_FREQ default 120000000 if MACH_SAM4 default 300000000 if MACH_SAME70 -config FLASH_START - hex - default 0x400000 if MACH_SAM4 || MACH_SAME70 - default 0x80000 - config FLASH_SIZE hex default 0x80000 @@ -93,6 +88,11 @@ config STACK_SIZE int default 512 +config FLASH_APPLICATION_ADDRESS + hex + default 0x400000 if MACH_SAM4 || MACH_SAME70 + default 0x80000 + choice prompt "Communication interface" config ATSAM_USB diff --git a/src/atsamd/Kconfig b/src/atsamd/Kconfig index 6162f9b84ff3..d6643ffd7bfe 100644 --- a/src/atsamd/Kconfig +++ b/src/atsamd/Kconfig @@ -110,6 +110,32 @@ config STACK_SIZE int default 512 + +###################################################################### +# Bootloader +###################################################################### + +choice + prompt "Bootloader offset" + config SAMD_FLASH_START_2000 + depends on MACH_SAMD21 + bool "8KiB bootloader (Arduino Zero)" + config SAMD_FLASH_START_4000 + bool "16KiB bootloader (Arduino M0)" + config SAMD_FLASH_START_0000 + bool "No bootloader" +endchoice +config FLASH_APPLICATION_ADDRESS + hex + default 0x4000 if SAMD_FLASH_START_4000 + default 0x2000 if SAMD_FLASH_START_2000 + default 0x0000 + + +###################################################################### +# Clock +###################################################################### + choice prompt "Clock Reference" config CLOCK_REF_X32K @@ -141,22 +167,10 @@ config CLOCK_FREQ default 200000000 if SAMD51_FREQ_200 default 120000000 if MACH_SAMX5 -choice - prompt "Bootloader offset" - config FLASH_START_2000 - depends on MACH_SAMD21 - bool "8KiB bootloader (Arduino Zero)" - config FLASH_START_4000 - bool "16KiB bootloader (Arduino M0)" - config FLASH_START_0000 - bool "No bootloader" -endchoice -config FLASH_START - hex - default 0x4000 if FLASH_START_4000 - default 0x2000 if FLASH_START_2000 - default 0x0000 +###################################################################### +# Communication inteface +###################################################################### choice prompt "Communication interface" diff --git a/src/atsamd/main.c b/src/atsamd/main.c index 37b6cc8b2fe0..96af22a0ade4 100644 --- a/src/atsamd/main.c +++ b/src/atsamd/main.c @@ -14,7 +14,7 @@ void bootloader_request(void) { - if (!CONFIG_FLASH_START) + if (!CONFIG_FLASH_APPLICATION_ADDRESS) return; // Bootloader hack irq_disable(); diff --git a/src/generic/armcm_link.lds.S b/src/generic/armcm_link.lds.S index eb3962ad6c87..2f789f1301e3 100644 --- a/src/generic/armcm_link.lds.S +++ b/src/generic/armcm_link.lds.S @@ -4,14 +4,14 @@ // // This file may be distributed under the terms of the GNU GPLv3 license. -#include "autoconf.h" // CONFIG_FLASH_START +#include "autoconf.h" // CONFIG_FLASH_APPLICATION_ADDRESS OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) MEMORY { - rom (rx) : ORIGIN = CONFIG_FLASH_START , LENGTH = CONFIG_FLASH_SIZE + rom (rx) : ORIGIN = CONFIG_FLASH_APPLICATION_ADDRESS , LENGTH = CONFIG_FLASH_SIZE ram (rwx) : ORIGIN = CONFIG_RAM_START , LENGTH = CONFIG_RAM_SIZE } diff --git a/src/generic/armcm_reset.c b/src/generic/armcm_reset.c index 6cd9ad8c856d..d747d9fc9623 100644 --- a/src/generic/armcm_reset.c +++ b/src/generic/armcm_reset.c @@ -5,7 +5,7 @@ // This file may be distributed under the terms of the GNU GPLv3 license. #include "armcm_reset.h" // try_request_canboot -#include "autoconf.h" // CONFIG_FLASH_START +#include "autoconf.h" // CONFIG_FLASH_APPLICATION_ADDRESS #include "board/internal.h" // NVIC_SystemReset #include "board/irq.h" // irq_disable #include "command.h" // DECL_COMMAND_FLAGS @@ -17,7 +17,7 @@ static void canboot_reset(uint64_t req_signature) { - if (CONFIG_FLASH_START == CONFIG_FLASH_BOOT_ADDRESS) + if (CONFIG_FLASH_APPLICATION_ADDRESS == CONFIG_FLASH_BOOT_ADDRESS) // No bootloader return; uint32_t *bl_vectors = (uint32_t *)CONFIG_FLASH_BOOT_ADDRESS; diff --git a/src/lpc176x/Kconfig b/src/lpc176x/Kconfig index 5c950ef593a2..02da06da36a6 100644 --- a/src/lpc176x/Kconfig +++ b/src/lpc176x/Kconfig @@ -70,7 +70,7 @@ choice config LPC_FLASH_START_0000 bool "No bootloader" endchoice -config FLASH_START +config FLASH_APPLICATION_ADDRESS hex default 0x4000 if LPC_FLASH_START_4000 default 0x0000 diff --git a/src/lpc176x/main.c b/src/lpc176x/main.c index 19a166dc0ec3..7fd05c5d2df6 100644 --- a/src/lpc176x/main.c +++ b/src/lpc176x/main.c @@ -44,7 +44,7 @@ DECL_INIT(watchdog_init); void bootloader_request(void) { - if (!CONFIG_FLASH_START) + if (!CONFIG_FLASH_APPLICATION_ADDRESS) return; try_request_canboot(); // Disable USB and pause for 5ms so host recognizes a disconnect diff --git a/src/rp2040/Kconfig b/src/rp2040/Kconfig index b42e6b219176..904699f84be4 100644 --- a/src/rp2040/Kconfig +++ b/src/rp2040/Kconfig @@ -66,7 +66,7 @@ choice config RP2040_FLASH_START_4000 bool "16KiB bootloader" endchoice -config FLASH_START +config FLASH_APPLICATION_ADDRESS hex default 0x10004000 if RP2040_FLASH_START_4000 default 0x10000100 diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index 364fd9fb75ef..83bf64492161 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -248,7 +248,7 @@ choice config STM32_FLASH_START_0000 bool "No bootloader" endchoice -config FLASH_START +config FLASH_APPLICATION_ADDRESS hex default 0x8000800 if STM32_FLASH_START_800 default 0x8001000 if STM32_FLASH_START_1000 @@ -266,7 +266,7 @@ config FLASH_START config ARMCM_RAM_VECTORTABLE bool - default y if MACH_STM32F0 && FLASH_START != 0x8000000 + default y if MACH_STM32F0 && FLASH_APPLICATION_ADDRESS != 0x8000000 default n diff --git a/src/stm32/Makefile b/src/stm32/Makefile index 9642eabd772b..d9efd0859e5a 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -94,7 +94,7 @@ lib/hidflash/hid-flash: flash: $(OUT)klipper.bin lib/hidflash/hid-flash @echo " Flashing $< to $(FLASH_DEVICE)" - $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" -s "$(CONFIG_FLASH_START)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin + $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" -s "$(CONFIG_FLASH_APPLICATION_ADDRESS)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin serialflash: $(OUT)klipper.bin @echo " Flashing $< to $(FLASH_DEVICE) via stm32flash" From fe0fc2961688588b0a4d6ad7783df961903bc736 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 14 Dec 2022 19:21:25 -0500 Subject: [PATCH 02/40] rp2040: Move watchdog code to new watchdog.c file Move the watchdog code to its own file so that it is easier to disable it for development builds. Signed-off-by: Kevin O'Connor --- src/rp2040/Makefile | 5 +++-- src/rp2040/main.c | 25 ------------------------- src/rp2040/watchdog.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 src/rp2040/watchdog.c diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile index 47954c9a322b..32d731f2f084 100644 --- a/src/rp2040/Makefile +++ b/src/rp2040/Makefile @@ -9,9 +9,10 @@ CFLAGS += -mcpu=cortex-m0plus -mthumb -Ilib/cmsis-core CFLAGS += -Ilib/rp2040 -Ilib/rp2040/cmsis_include -Ilib/fast-hash -Ilib/can2040 # Add source files -src-y += rp2040/main.c rp2040/gpio.c rp2040/adc.c generic/crc16_ccitt.c +src-y += rp2040/main.c rp2040/watchdog.c rp2040/gpio.c +src-y += rp2040/adc.c rp2040/timer.c rp2040/bootrom.c src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c -src-y += generic/timer_irq.c rp2040/timer.c rp2040/bootrom.c +src-y += generic/timer_irq.c generic/crc16_ccitt.c src-$(CONFIG_USBSERIAL) += rp2040/usbserial.c generic/usb_cdc.c src-$(CONFIG_USBSERIAL) += rp2040/chipid.c src-$(CONFIG_SERIAL) += rp2040/serial.c generic/serial_irq.c diff --git a/src/rp2040/main.c b/src/rp2040/main.c index c14e2759b3e1..0b144d0bba0c 100644 --- a/src/rp2040/main.c +++ b/src/rp2040/main.c @@ -9,7 +9,6 @@ #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/psm.h" // psm_hw #include "hardware/structs/resets.h" // sio_hw #include "hardware/structs/watchdog.h" // watchdog_hw #include "hardware/structs/xosc.h" // xosc_hw @@ -17,30 +16,6 @@ #include "sched.h" // sched_main -/**************************************************************** - * watchdog handler - ****************************************************************/ - -void -watchdog_reset(void) -{ - watchdog_hw->load = 0x800000; // ~350ms -} -DECL_TASK(watchdog_reset); - -void -watchdog_init(void) -{ - psm_hw->wdsel = PSM_WDSEL_BITS & ~(PSM_WDSEL_ROSC_BITS|PSM_WDSEL_XOSC_BITS); - watchdog_reset(); - watchdog_hw->ctrl = (WATCHDOG_CTRL_PAUSE_DBG0_BITS - | WATCHDOG_CTRL_PAUSE_DBG1_BITS - | WATCHDOG_CTRL_PAUSE_JTAG_BITS - | WATCHDOG_CTRL_ENABLE_BITS); -} -DECL_INIT(watchdog_init); - - /**************************************************************** * Bootloader ****************************************************************/ diff --git a/src/rp2040/watchdog.c b/src/rp2040/watchdog.c new file mode 100644 index 000000000000..dda7aa55654b --- /dev/null +++ b/src/rp2040/watchdog.c @@ -0,0 +1,29 @@ +// Watchdog code on rp2040 +// +// Copyright (C) 2021-2022 Kevin O'Connor +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include // uint32_t +#include "hardware/structs/psm.h" // psm_hw +#include "hardware/structs/watchdog.h" // watchdog_hw +#include "sched.h" // DECL_TASK + +void +watchdog_reset(void) +{ + watchdog_hw->load = 0x800000; // ~350ms +} +DECL_TASK(watchdog_reset); + +void +watchdog_init(void) +{ + psm_hw->wdsel = PSM_WDSEL_BITS & ~(PSM_WDSEL_ROSC_BITS|PSM_WDSEL_XOSC_BITS); + watchdog_reset(); + watchdog_hw->ctrl = (WATCHDOG_CTRL_PAUSE_DBG0_BITS + | WATCHDOG_CTRL_PAUSE_DBG1_BITS + | WATCHDOG_CTRL_PAUSE_JTAG_BITS + | WATCHDOG_CTRL_ENABLE_BITS); +} +DECL_INIT(watchdog_init); From f6199ef61360c06a29aba48bdb3b6e8f44a8b301 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 12 Dec 2022 21:45:58 -0500 Subject: [PATCH 03/40] config: Update generic-bigtreetech-octopus.cfg for f429 and h723 chips Signed-off-by: Kevin O'Connor --- config/generic-bigtreetech-octopus.cfg | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/config/generic-bigtreetech-octopus.cfg b/config/generic-bigtreetech-octopus.cfg index d8deb0da5f7e..73bd584ca884 100644 --- a/config/generic-bigtreetech-octopus.cfg +++ b/config/generic-bigtreetech-octopus.cfg @@ -1,6 +1,12 @@ -# This file contains common pin mappings for the BigTreeTech Octopus. -# To use this config, the firmware should be compiled for the -# STM32F446 with a "32KiB bootloader" and a "12MHz crystal" clock reference. +# This file contains common pin mappings for the BigTreeTech Octopus +# and Octopus Pro boards. To use this config, start by identifying the +# micro-controller on the board - it may be an STM32F446, STM32F429, +# or an STM32H723. Select the appropriate micro-controller in "make +# menuconfig" and select "Enable low-level configuration options". For +# STM32F446 boards the firmware should be compiled with a "32KiB +# bootloader" and a "12MHz crystal" clock reference. For STM32F429 +# boards use a "32KiB bootloader" and an "8MHz crystal". For STM32H723 +# boards use a "128KiB bootloader" and a "25Mhz crystal". # See docs/Config_Reference.md for a description of parameters. From 9d668d63a7183a62b9f78ef7e40f1a2089a43097 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 12 Dec 2022 22:54:17 -0500 Subject: [PATCH 04/40] stm32: Rework usb_reboot_for_dfu_bootloader() so it works on stm32h723 Signed-off-by: Kevin O'Connor --- src/stm32/stm32h7.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stm32/stm32h7.c b/src/stm32/stm32h7.c index 3423e7ebd789..4f9ec68ca722 100644 --- a/src/stm32/stm32h7.c +++ b/src/stm32/stm32h7.c @@ -208,7 +208,7 @@ clock_setup(void) * Bootloader ****************************************************************/ -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 1024) +#define USB_BOOT_FLAG_ADDR (0x24000000 + 0x8000) // Place flag in "AXI SRAM" #define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" // Flag that bootloader is desired and reboot @@ -216,6 +216,7 @@ static void usb_reboot_for_dfu_bootloader(void) { irq_disable(); + SCB_DisableDCache(); *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; NVIC_SystemReset(); } From e33b41abaabe7d2be2207c79d5ed59cb8ce7babc Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 12 Dec 2022 22:14:09 +0100 Subject: [PATCH 05/40] stm32g0: add stm32g0b0 support Signed-off-by: Alex Voinea --- src/stm32/Kconfig | 16 ++++++++++++---- src/stm32/stm32f0_serial.c | 6 ++++-- src/stm32/stm32f0_timer.c | 19 +++++++++++-------- src/stm32/stm32g0.c | 6 +++++- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index 83bf64492161..504453a8475f 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -65,9 +65,14 @@ choice bool "STM32F072" select MACH_STM32F0 select MACH_STM32F0x2 + config MACH_STM32G0B0 + bool "STM32G0B0" + select MACH_STM32G0 + select MACH_STM32G0Bx config MACH_STM32G0B1 bool "STM32G0B1" select MACH_STM32G0 + select MACH_STM32G0Bx config MACH_STM32G431 bool "STM32G431" select MACH_STM32G4 @@ -99,6 +104,8 @@ config MACH_STM32F4 bool config MACH_STM32G0 bool +config MACH_STM32G0Bx + bool config MACH_STM32G4 bool config MACH_STM32H7 @@ -111,7 +118,7 @@ config MACH_STM32L4 bool config HAVE_STM32_USBFS bool - default y if MACH_STM32F0x2 || MACH_STM32G0 || MACH_STM32L4 || MACH_STM32G4 + default y if MACH_STM32F0x2 || MACH_STM32GBx || MACH_STM32L4 || MACH_STM32G4 default y if (MACH_STM32F103 || MACH_STM32F070) && !STM32_CLOCK_REF_INTERNAL config HAVE_STM32_USBOTG bool @@ -121,7 +128,7 @@ config HAVE_STM32_CANBUS default y if MACH_STM32F1 || MACH_STM32F2 || MACH_STM32F4x5 || MACH_STM32F446 || MACH_STM32F0x2 config HAVE_STM32_FDCANBUS bool - default y if MACH_STM32G0 || MACH_STM32H7 || MACH_STM32G4 + default y if MACH_STM32G0B1 || MACH_STM32H7 || MACH_STM32G4 config HAVE_STM32_USBCANBUS bool depends on HAVE_STM32_USBFS || HAVE_STM32_USBOTG @@ -142,6 +149,7 @@ config MCU default "stm32f407xx" if MACH_STM32F407 default "stm32f429xx" if MACH_STM32F429 default "stm32f446xx" if MACH_STM32F446 + default "stm32g0b0xx" if MACH_STM32G0B0 default "stm32g0b1xx" if MACH_STM32G0B1 default "stm32g431xx" if MACH_STM32G431 default "stm32h723xx" if MACH_STM32H723 @@ -171,7 +179,7 @@ config FLASH_SIZE default 0x10000 if MACH_STM32F103 || MACH_STM32L412 # Flash size of stm32f103x8 (64KiB) default 0x40000 if MACH_STM32F2 || MACH_STM32F401 || MACH_STM32H723 default 0x80000 if MACH_STM32F4x5 || MACH_STM32F446 - default 0x20000 if MACH_STM32G0B1 || MACH_STM32G431 + default 0x20000 if MACH_STM32G0 || MACH_STM32G431 default 0x20000 if MACH_STM32H750 default 0x200000 if MACH_STM32H743 @@ -195,7 +203,7 @@ config RAM_SIZE default 0x20000 if MACH_STM32F207 default 0x10000 if MACH_STM32F401 default 0x20000 if MACH_STM32F4x5 || MACH_STM32F446 - default 0x24000 if MACH_STM32G0B1 + default 0x24000 if MACH_STM32G0Bx default 0x20000 if MACH_STM32H7 config STACK_SIZE diff --git a/src/stm32/stm32f0_serial.c b/src/stm32/stm32f0_serial.c index bb4ec69ac9ce..4e0f39fe0641 100644 --- a/src/stm32/stm32f0_serial.c +++ b/src/stm32/stm32f0_serial.c @@ -87,8 +87,10 @@ #endif #if CONFIG_MACH_STM32G0 - // The stm32g0 has slightly different register names - #define USART2_IRQn USART2_LPUART2_IRQn + // Some of the stm32g0 MCUs have slightly different register names + #ifdef LPUART2 + #define USART2_IRQn USART2_LPUART2_IRQn + #endif #define USART_CR1_RXNEIE USART_CR1_RXNEIE_RXFNEIE #define USART_CR1_TXEIE USART_CR1_TXEIE_TXFNFIE #define USART_ISR_RXNE USART_ISR_RXNE_RXFNE diff --git a/src/stm32/stm32f0_timer.c b/src/stm32/stm32f0_timer.c index 4f5e6d38285b..0d8ed3a35b56 100644 --- a/src/stm32/stm32f0_timer.c +++ b/src/stm32/stm32f0_timer.c @@ -20,14 +20,17 @@ ****************************************************************/ // Use 32bit TIM2 timer if available (otherwise use 16bit TIM3 timer) -#ifdef TIM2 -#define TIMx TIM2 -#define TIMx_IRQn TIM2_IRQn -#define HAVE_TIMER_32BIT 1 -#else -#define TIMx TIM3 -#define TIMx_IRQn TIM3_IRQn -#define HAVE_TIMER_32BIT 0 +#if defined(TIM2) + #define TIMx TIM2 + #define TIMx_IRQn TIM2_IRQn + #define HAVE_TIMER_32BIT 1 +#elif defined(TIM3) + #define TIMx TIM3 + #define TIMx_IRQn TIM3_IRQn + #define HAVE_TIMER_32BIT 0 + #ifdef TIM4 + #define TIM3_IRQn TIM3_TIM4_IRQn + #endif #endif static inline uint32_t diff --git a/src/stm32/stm32g0.c b/src/stm32/stm32g0.c index 244e00d9d030..847117091b41 100644 --- a/src/stm32/stm32g0.c +++ b/src/stm32/stm32g0.c @@ -32,12 +32,16 @@ lookup_clock_line(uint32_t periph_base) uint32_t bit = 1 << ((periph_base - AHBPERIPH_BASE) / 0x400); return (struct cline){.en=&RCC->AHBENR, .rst=&RCC->AHBRSTR, .bit=bit}; } +#if defined(FDCAN1_BASE) || defined(FDCAN2_BASE) if ((periph_base == FDCAN1_BASE) || (periph_base == FDCAN2_BASE)) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<12}; +#endif if (periph_base == USB_BASE) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<13}; +#ifdef CRS_BASE if (periph_base == CRS_BASE) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<16}; +#endif if (periph_base == I2C3_BASE) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<23}; if (periph_base == TIM1_BASE) @@ -56,7 +60,7 @@ lookup_clock_line(uint32_t periph_base) return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<18}; if (periph_base == ADC1_BASE) return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<20}; - if (periph_base >= APBPERIPH_BASE && periph_base <= LPTIM1_BASE) + if (periph_base >= APBPERIPH_BASE && periph_base < APBPERIPH_BASE + 0x8000) { uint32_t bit = 1 << ((periph_base - APBPERIPH_BASE) / 0x400); return (struct cline){.en=&RCC->APBENR1, .rst=&RCC->APBRSTR1, .bit=bit}; From f31540b3571c211739cfad4c207309e222f25842 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 15 Dec 2022 10:23:37 -0500 Subject: [PATCH 06/40] stm32: Minor changes to stm32g0b0 ifdefs Signed-off-by: Kevin O'Connor --- src/stm32/stm32f0_serial.c | 2 +- src/stm32/stm32f0_timer.c | 8 +++++--- src/stm32/stm32g0.c | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/stm32/stm32f0_serial.c b/src/stm32/stm32f0_serial.c index 4e0f39fe0641..4f6495f7ecb7 100644 --- a/src/stm32/stm32f0_serial.c +++ b/src/stm32/stm32f0_serial.c @@ -88,7 +88,7 @@ #if CONFIG_MACH_STM32G0 // Some of the stm32g0 MCUs have slightly different register names - #ifdef LPUART2 + #if CONFIG_MACH_STM32G0B1 #define USART2_IRQn USART2_LPUART2_IRQn #endif #define USART_CR1_RXNEIE USART_CR1_RXNEIE_RXFNEIE diff --git a/src/stm32/stm32f0_timer.c b/src/stm32/stm32f0_timer.c index 0d8ed3a35b56..f4a963964c56 100644 --- a/src/stm32/stm32f0_timer.c +++ b/src/stm32/stm32f0_timer.c @@ -28,9 +28,11 @@ #define TIMx TIM3 #define TIMx_IRQn TIM3_IRQn #define HAVE_TIMER_32BIT 0 - #ifdef TIM4 - #define TIM3_IRQn TIM3_TIM4_IRQn - #endif +#endif + +// Some chips have slightly different register names +#if CONFIG_MACH_STM32G0B0 + #define TIM3_IRQn TIM3_TIM4_IRQn #endif static inline uint32_t diff --git a/src/stm32/stm32g0.c b/src/stm32/stm32g0.c index 847117091b41..f42ac7773025 100644 --- a/src/stm32/stm32g0.c +++ b/src/stm32/stm32g0.c @@ -60,8 +60,8 @@ lookup_clock_line(uint32_t periph_base) return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<18}; if (periph_base == ADC1_BASE) return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<20}; - if (periph_base >= APBPERIPH_BASE && periph_base < APBPERIPH_BASE + 0x8000) - { + if (periph_base >= APBPERIPH_BASE + && periph_base < APBPERIPH_BASE + 32*0x400) { uint32_t bit = 1 << ((periph_base - APBPERIPH_BASE) / 0x400); return (struct cline){.en=&RCC->APBENR1, .rst=&RCC->APBRSTR1, .bit=bit}; } From ac090d9d52a80c207d99545fcb65ed50612436a3 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 15 Dec 2022 11:14:46 -0500 Subject: [PATCH 07/40] stm32: Fix stm32l4 build Commit c5d56f44 neglected to define ADCIN_BANK_SIZE in stm32h7_adc.c on stm32l4. Signed-off-by: Kevin O'Connor --- src/stm32/stm32h7_adc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stm32/stm32h7_adc.c b/src/stm32/stm32h7_adc.c index 8a9bb318dfb8..a42ff5871e61 100644 --- a/src/stm32/stm32h7_adc.c +++ b/src/stm32/stm32h7_adc.c @@ -35,6 +35,7 @@ #define ADC_ISR_LDORDY ADC_ISR_LDORDY_Msk #elif CONFIG_MACH_STM32L4 + #define ADCIN_BANK_SIZE (19) #define RCC_AHBENR_ADC (RCC->AHB2ENR) #define RCC_AHBENR_ADCEN (RCC_AHB2ENR_ADCEN) #define ADC_CKMODE (0) From 41c7bb818fac8d803628aa1b07379869361f6485 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 13 Dec 2022 12:51:41 -0500 Subject: [PATCH 08/40] test: Add compile test builds for stm32g431, stm32h723, stm32l412 Signed-off-by: Kevin O'Connor --- test/configs/stm32g431.cfg | 3 +++ test/configs/stm32h723.cfg | 3 +++ test/configs/stm32l412.cfg | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 test/configs/stm32g431.cfg create mode 100644 test/configs/stm32h723.cfg create mode 100644 test/configs/stm32l412.cfg diff --git a/test/configs/stm32g431.cfg b/test/configs/stm32g431.cfg new file mode 100644 index 000000000000..79f1816cb225 --- /dev/null +++ b/test/configs/stm32g431.cfg @@ -0,0 +1,3 @@ +# Base config file for STM32G431 ARM processor +CONFIG_MACH_STM32=y +CONFIG_MACH_STM32G431=y diff --git a/test/configs/stm32h723.cfg b/test/configs/stm32h723.cfg new file mode 100644 index 000000000000..0a6e03abfa1f --- /dev/null +++ b/test/configs/stm32h723.cfg @@ -0,0 +1,3 @@ +# Base config file for STM32H723 ARM processor +CONFIG_MACH_STM32=y +CONFIG_MACH_STM32H723=y diff --git a/test/configs/stm32l412.cfg b/test/configs/stm32l412.cfg new file mode 100644 index 000000000000..9e76d645ef9d --- /dev/null +++ b/test/configs/stm32l412.cfg @@ -0,0 +1,3 @@ +# Base config file for STM32L412 ARM processor +CONFIG_MACH_STM32=y +CONFIG_MACH_STM32L412=y From 7d1df81e5eddca79b888f6ae1ba9b196c57ceb16 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 15 Dec 2022 11:44:12 -0500 Subject: [PATCH 09/40] stm32: Fix USB support on stm32g0b1 A typo in commit e33b41ab broke USB selection on stm32g0b1. Reported by @Pmant. Signed-off-by: Kevin O'Connor --- src/stm32/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index 504453a8475f..13cf8d848cd2 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -118,7 +118,7 @@ config MACH_STM32L4 bool config HAVE_STM32_USBFS bool - default y if MACH_STM32F0x2 || MACH_STM32GBx || MACH_STM32L4 || MACH_STM32G4 + default y if MACH_STM32F0x2 || MACH_STM32G0Bx || MACH_STM32L4 || MACH_STM32G4 default y if (MACH_STM32F103 || MACH_STM32F070) && !STM32_CLOCK_REF_INTERNAL config HAVE_STM32_USBOTG bool From b0d9cbfb4bf91674cf460aac531c8d79f3bd4303 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 15 Dec 2022 18:42:31 -0500 Subject: [PATCH 10/40] stm32: Fix usb build on stm32g0b0 Signed-off-by: Kevin O'Connor --- src/stm32/usbfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/stm32/usbfs.c b/src/stm32/usbfs.c index f144b2c9237b..f7559efd6fa0 100644 --- a/src/stm32/usbfs.c +++ b/src/stm32/usbfs.c @@ -29,9 +29,14 @@ // Transfer memory is accessed with 32bits and contains 32bits of data typedef volatile uint32_t epmword_t; #define WSIZE 4 - #define USBx_IRQn USB_UCPD1_2_IRQn + #define USBx_IRQn USB_IRQn +#endif - // The stm32g0 has slightly different register names +// The stm32g0 has slightly different register names +#if CONFIG_MACH_STM32G0 + #if CONFIG_MACH_STM32G0B1 + #define USB_IRQn USB_UCPD1_2_IRQn + #endif #define USB USB_DRD_FS #define USB_PMAADDR USB_DRD_PMAADDR #define USB_EPADDR_FIELD USB_CHEP_ADDR From 02b45c91fb1e6c02265692555097f34f41f15604 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 16 Dec 2022 12:30:22 -0500 Subject: [PATCH 11/40] armcm_reset: Flush dcache before rebooting into canboot Signed-off-by: Kevin O'Connor --- src/generic/armcm_reset.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/generic/armcm_reset.c b/src/generic/armcm_reset.c index d747d9fc9623..fb9bf0b13a7d 100644 --- a/src/generic/armcm_reset.c +++ b/src/generic/armcm_reset.c @@ -23,14 +23,16 @@ canboot_reset(uint64_t req_signature) uint32_t *bl_vectors = (uint32_t *)CONFIG_FLASH_BOOT_ADDRESS; uint64_t *boot_sig = (uint64_t *)(bl_vectors[1] - 9); uint64_t *req_sig = (uint64_t *)bl_vectors[0]; - if (boot_sig == (void *)ALIGN((size_t)boot_sig, 8) && - *boot_sig == CANBOOT_SIGNATURE && - req_sig == (void *)ALIGN((size_t)req_sig, 8)) - { - irq_disable(); - *req_sig = req_signature; - NVIC_SystemReset(); - } + if (boot_sig != (void*)ALIGN((size_t)boot_sig, 8) + || *boot_sig != CANBOOT_SIGNATURE + || req_sig != (void*)ALIGN((size_t)req_sig, 8)) + return; + irq_disable(); + *req_sig = req_signature; +#if __CORTEX_M >= 7 + SCB_CleanDCache_by_Addr((void*)req_sig, sizeof(*req_sig)); +#endif + NVIC_SystemReset(); } void From 0c43ae1fd4d3dc245038b39afe55197c9397f100 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 16 Dec 2022 17:29:45 -0500 Subject: [PATCH 12/40] stm32: Just clean dcache instead of disabling on stm32h7 dfu reboot Signed-off-by: Kevin O'Connor --- src/stm32/stm32h7.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/stm32/stm32h7.c b/src/stm32/stm32h7.c index 4f9ec68ca722..43b7aa6ede8a 100644 --- a/src/stm32/stm32h7.c +++ b/src/stm32/stm32h7.c @@ -216,8 +216,9 @@ static void usb_reboot_for_dfu_bootloader(void) { irq_disable(); - SCB_DisableDCache(); - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; + uint64_t *bflag = (void*)USB_BOOT_FLAG_ADDR; + *bflag = USB_BOOT_FLAG; + SCB_CleanDCache_by_Addr((void*)bflag, sizeof(*bflag)); NVIC_SystemReset(); } From 3c1ed3bb2731b49249d6aaacf01248783e4c8bf6 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 16 Dec 2022 22:46:47 -0500 Subject: [PATCH 13/40] initial_pins: Add check to reduce compile time size when not in use Add a check to the start of initial_pins_setup() to make it easier for gcc to optimize the code if it is not in use. Signed-off-by: Kevin O'Connor --- src/initial_pins.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/initial_pins.c b/src/initial_pins.c index cd478508c682..af01b3acc7ed 100644 --- a/src/initial_pins.c +++ b/src/initial_pins.c @@ -16,6 +16,8 @@ DECL_CTR("DECL_INITIAL_PINS " __stringify(CONFIG_INITIAL_PINS)); void initial_pins_setup(void) { + if (sizeof(CONFIG_INITIAL_PINS) <= 1) + return; int i; for (i=0; i Date: Sat, 17 Dec 2022 10:39:25 -0600 Subject: [PATCH 14/40] screws_tilt_adjust: Add get_status() method (#5921) Signed-off-by: Christopher Meredith --- docs/Status_Reference.md | 22 ++++++++++++++++++++++ klippy/extras/screws_tilt_adjust.py | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/docs/Status_Reference.md b/docs/Status_Reference.md index e6595ddbbec0..ff6a30bcba5c 100644 --- a/docs/Status_Reference.md +++ b/docs/Status_Reference.md @@ -369,6 +369,28 @@ The following information is available in the `query_endstops` object the QUERY_ENDSTOP command must be run prior to the macro containing this reference. +## screws_tilt_adjust + +The following information is available in the `screws_tilt_adjust` +object: +- `error`: Returns True if the most recent `SCREWS_TILT_CALCULATE` + command included the `MAX_DEVIATION` parameter and any of the probed + screw points exceeded the specified `MAX_DEVIATION`. +- `results`: A list of the probed screw locations. Each entry in + the list will be a dictionary containing the following keys: + - `name`: The name of the screw as specified in the config file. + - `x`: The X coordinate of the screw as specified in the config file. + - `y`: The Y coordinate of the screw as specified in the config file. + - `z`: The measured Z height of the screw location. + - `sign`: A string specifying the direction to turn to screw for the + necessary adjustment. Either "CW" for clockwise or "CCW" for + counterclockwise. The base screw will not have a `sign` key. + - `adjust`: The number of screw turns to adjust the screw, given in + the format "HH:MM," where "HH" is the number of full screw turns + and "MM" is the number of "minutes of a clock face" representing + a partial screw turn. (E.g. "01:15" would mean to turn the screw + one and a quarter revolutions.) + ## servo The following information is available in diff --git a/klippy/extras/screws_tilt_adjust.py b/klippy/extras/screws_tilt_adjust.py index 1bb599ed3376..82d12bc18013 100644 --- a/klippy/extras/screws_tilt_adjust.py +++ b/klippy/extras/screws_tilt_adjust.py @@ -12,7 +12,9 @@ def __init__(self, config): self.config = config self.printer = config.get_printer() self.screws = [] + self.results = [] self.max_diff = None + self.max_diff_error = False # Read config for i in range(99): prefix = "screw%d" % (i + 1,) @@ -57,7 +59,13 @@ def cmd_SCREWS_TILT_CALCULATE(self, gcmd): self.direction = direction self.probe_helper.start_probe(gcmd) + def get_status(self, eventtime): + return {'error': self.max_diff_error, + 'results': self.results} + def probe_finalize(self, offsets, positions): + self.results = [] + self.max_diff_error = False # Factors used for CW-M3, CCW-M3, CW-M4, CCW-M4, CW-M5 and CCW-M5 threads_factor = {0: 0.5, 1: 0.5, 2: 0.7, 3: 0.7, 4: 0.8, 5: 0.8} is_clockwise_thread = (self.thread & 1) == 0 @@ -84,6 +92,8 @@ def probe_finalize(self, offsets, positions): self.gcode.respond_info( "%s : x=%.1f, y=%.1f, z=%.5f" % (name + ' (base)', coord[0], coord[1], z)) + self.results.append({'name': name + ' (base)', 'x': coord[0], + 'y': coord[1], 'z': z, 'sign': 'CW', 'adjust':'00:00'}) else: # Calculate how knob must be adjusted for other positions diff = z_base - z @@ -104,7 +114,11 @@ def probe_finalize(self, offsets, positions): self.gcode.respond_info( "%s : x=%.1f, y=%.1f, z=%.5f : adjust %s %02d:%02d" % (name, coord[0], coord[1], z, sign, full_turns, minutes)) + self.results.append({'name': name, 'x': coord[0], 'y': coord[1], + 'z': z, 'sign': sign, + 'adjust':"%02d:%02d" % (full_turns, minutes)}) if self.max_diff and any((d > self.max_diff) for d in screw_diff): + self.max_diff_error = True raise self.gcode.error( "bed level exceeds configured limits ({}mm)! " \ "Adjust screws and restart print.".format(self.max_diff)) From be74c72555533dbaadafdbc65e6dd2256105954f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 15 Dec 2022 11:04:43 -0500 Subject: [PATCH 15/40] stm32: Separate out USB DFU reboot logic in stm32g4.c Signed-off-by: Kevin O'Connor --- src/stm32/stm32g4.c | 66 ++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/src/stm32/stm32g4.c b/src/stm32/stm32g4.c index bd4c6ee02e42..a0dd32c0dcd4 100644 --- a/src/stm32/stm32g4.c +++ b/src/stm32/stm32g4.c @@ -7,7 +7,6 @@ #include "autoconf.h" // CONFIG_CLOCK_REF_FREQ #include "board/armcm_boot.h" // VectorTable #include "board/irq.h" // irq_disable -#include "board/usb_cdc.h" // usb_request_bootloader #include "command.h" // DECL_CONSTANT_STR #include "internal.h" // enable_pclock #include "sched.h" // sched_main @@ -66,19 +65,6 @@ gpio_clock_enable(GPIO_TypeDef *regs) RCC->AHB2ENR; } -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Handle USB reboot requests -void -bootloader_request(void) -{ - irq_disable(); - // System DFU Bootloader - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; - NVIC_SystemReset(); -} - #if !CONFIG_STM32_CLOCK_REF_INTERNAL DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PF0,PF1"); #endif @@ -148,15 +134,53 @@ clock_setup(void) ; } + +/**************************************************************** + * Bootloader + ****************************************************************/ + +#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) +#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" + +// Flag that bootloader is desired and reboot +static void +usb_reboot_for_dfu_bootloader(void) +{ + irq_disable(); + // System DFU Bootloader + *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; + NVIC_SystemReset(); +} + +// Check if rebooting into system DFU Bootloader +static void +check_usb_dfu_bootloader(void) +{ + if (!CONFIG_USB || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) + return; + *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; + uint32_t *sysbase = (uint32_t*)0x1fff0000; + asm volatile("mov sp, %0\n bx %1" + : : "r"(sysbase[0]), "r"(sysbase[1])); +} + +// Handle USB reboot requests +void +bootloader_request(void) +{ + usb_reboot_for_dfu_bootloader(); +} + + +/**************************************************************** + * Startup + ****************************************************************/ + // Main entry point - called from armcm_boot.c:ResetHandler() void -armcm_main(void) { - if (CONFIG_USBSERIAL && *(uint64_t*)USB_BOOT_FLAG_ADDR == USB_BOOT_FLAG) { - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1fff0000; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); - } +armcm_main(void) +{ + check_usb_dfu_bootloader(); // Run SystemInit() and then restore VTOR SystemInit(); From b6cd77f6e377060d2625126ffef9b2842e1cc25b Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 15 Dec 2022 11:20:37 -0500 Subject: [PATCH 16/40] stm32: Separate out USB DFU reboot logic in stm32l4.c Signed-off-by: Kevin O'Connor --- src/stm32/stm32l4.c | 69 ++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/src/stm32/stm32l4.c b/src/stm32/stm32l4.c index 8fb50a23ea8d..b5c939bbf144 100644 --- a/src/stm32/stm32l4.c +++ b/src/stm32/stm32l4.c @@ -7,7 +7,6 @@ #include "autoconf.h" // CONFIG_CLOCK_REF_FREQ #include "board/armcm_boot.h" // VectorTable #include "board/irq.h" // irq_disable -#include "board/usb_cdc.h" // usb_request_bootloader #include "command.h" // DECL_CONSTANT_STR #include "internal.h" // enable_pclock #include "sched.h" // sched_main @@ -68,25 +67,6 @@ gpio_clock_enable(GPIO_TypeDef *regs) RCC->AHB2ENR; } -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Handle USB reboot requests -void -usb_request_bootloader(void) -{ - irq_disable(); - // System DFU Bootloader - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; - NVIC_SystemReset(); -} - -void -bootloader_request(void) -{ - usb_request_bootloader(); -} - #if !CONFIG_STM32_CLOCK_REF_INTERNAL DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PC14,PC15"); #endif @@ -154,16 +134,53 @@ clock_setup(void) ; } + +/**************************************************************** + * Bootloader + ****************************************************************/ + +#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) +#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" + +// Flag that bootloader is desired and reboot +static void +usb_reboot_for_dfu_bootloader(void) +{ + irq_disable(); + // System DFU Bootloader + *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; + NVIC_SystemReset(); +} + +// Check if rebooting into system DFU Bootloader +static void +check_usb_dfu_bootloader(void) +{ + if (!CONFIG_USB || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) + return; + *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; + uint32_t *sysbase = (uint32_t*)0x1fff0000; + asm volatile("mov sp, %0\n bx %1" + : : "r"(sysbase[0]), "r"(sysbase[1])); +} + +// Handle USB reboot requests +void +bootloader_request(void) +{ + usb_reboot_for_dfu_bootloader(); +} + + +/**************************************************************** + * Startup + ****************************************************************/ + // Main entry point - called from armcm_boot.c:ResetHandler() void armcm_main(void) { - if (CONFIG_USBSERIAL && *(uint64_t*)USB_BOOT_FLAG_ADDR == USB_BOOT_FLAG) { - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1fff0000; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); - } + check_usb_dfu_bootloader(); // Run SystemInit() and then restore VTOR SystemInit(); From 4af87865875755b421873e7e4e43ece958ab00ee Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 15 Dec 2022 11:23:28 -0500 Subject: [PATCH 17/40] stm32: Move dfu reboot logic to new dfu_reboot.c file Move the stm32 DFU reboot logic to a new dfu_reboot.c file. This simplifies the per-chip code. Signed-off-by: Kevin O'Connor --- src/stm32/Kconfig | 9 +++++++ src/stm32/Makefile | 3 ++- src/stm32/dfu_reboot.c | 57 ++++++++++++++++++++++++++++++++++++++++++ src/stm32/internal.h | 4 +++ src/stm32/stm32f0.c | 31 ++--------------------- src/stm32/stm32f4.c | 28 ++------------------- src/stm32/stm32g0.c | 28 ++------------------- src/stm32/stm32g4.c | 29 ++------------------- src/stm32/stm32h7.c | 30 ++-------------------- src/stm32/stm32l4.c | 29 ++------------------- 10 files changed, 84 insertions(+), 164 deletions(-) create mode 100644 src/stm32/dfu_reboot.c diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index 13cf8d848cd2..dac884a03331 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -220,6 +220,15 @@ config STM32F103GD_DISABLE_SWD and PA14 pins from being available. Selecting this option disables SWD at startup and thus makes these pins available. +config STM32_DFU_ROM_ADDRESS + hex + default 0 if !USB + default 0x1fffc400 if MACH_STM32F042 + default 0x1fffc800 if MACH_STM32F072 + default 0x1fff0000 if MACH_STM32F4 || MACH_STM32G0 || MACH_STM32G4 || MACH_STM32L4 + default 0x1ff09800 if MACH_STM32H7 + default 0 + ###################################################################### # Bootloader diff --git a/src/stm32/Makefile b/src/stm32/Makefile index d9efd0859e5a..15ea4e2bf3a9 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -31,7 +31,8 @@ CFLAGS_klipper.elf += -T $(OUT)src/generic/armcm_link.ld $(OUT)klipper.elf: $(OUT)src/generic/armcm_link.ld # Add source files -src-y += stm32/watchdog.c stm32/gpio.c stm32/clockline.c generic/crc16_ccitt.c +src-y += stm32/watchdog.c stm32/gpio.c stm32/clockline.c stm32/dfu_reboot.c +src-y += generic/crc16_ccitt.c src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c src-$(CONFIG_MACH_STM32F0) += ../lib/stm32f0/system_stm32f0xx.c src-$(CONFIG_MACH_STM32F0) += generic/timer_irq.c stm32/stm32f0_timer.c diff --git a/src/stm32/dfu_reboot.c b/src/stm32/dfu_reboot.c new file mode 100644 index 000000000000..04952a483cfe --- /dev/null +++ b/src/stm32/dfu_reboot.c @@ -0,0 +1,57 @@ +// Reboot into stm32 ROM dfu bootloader +// +// Copyright (C) 2019-2022 Kevin O'Connor +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include "internal.h" // NVIC_SystemReset +#include "board/irq.h" // irq_disable + +// Many stm32 chips have a USB capable "DFU bootloader" in their ROM. +// In order to invoke that bootloader it is necessary to reset the +// chip and jump to a chip specific hardware address. +// +// To reset the chip, the dfu_reboot() code sets a flag in memory (at +// an arbitrary position that is unlikely to be overwritten during a +// chip reset), and resets the chip. If dfu_reboot_check() sees that +// flag on the next boot it will perform a code jump to the ROM +// address. + +// Location of ram address to set internal flag +#if CONFIG_MACH_STM32H7 + #define USB_BOOT_FLAG_ADDR (0x24000000 + 0x8000) // Place flag in "AXI SRAM" +#else + #define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 1024) +#endif + +// Signature to set in memory to flag that a dfu reboot is requested +#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" + +// Flag that bootloader is desired and reboot +void +dfu_reboot(void) +{ + if (!CONFIG_STM32_DFU_ROM_ADDRESS) + return; + irq_disable(); + uint64_t *bflag = (void*)USB_BOOT_FLAG_ADDR; + *bflag = USB_BOOT_FLAG; +#if CONFIG_MACH_STM32H7 + SCB_CleanDCache_by_Addr((void*)bflag, sizeof(*bflag)); +#endif + NVIC_SystemReset(); +} + +// Check if rebooting into system DFU Bootloader +void +dfu_reboot_check(void) +{ + if (!CONFIG_STM32_DFU_ROM_ADDRESS) + return; + if (*(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) + return; + *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; + uint32_t *sysbase = (uint32_t*)CONFIG_STM32_DFU_ROM_ADDRESS; + asm volatile("mov sp, %0\n bx %1" + : : "r"(sysbase[0]), "r"(sysbase[1])); +} diff --git a/src/stm32/internal.h b/src/stm32/internal.h index 2ba7abe27cfe..b5971ed7a15a 100644 --- a/src/stm32/internal.h +++ b/src/stm32/internal.h @@ -40,6 +40,10 @@ void gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup); void enable_pclock(uint32_t periph_base); int is_enabled_pclock(uint32_t periph_base); +// dfu_reboot.c +void dfu_reboot(void); +void dfu_reboot_check(void); + // stm32??.c struct cline { volatile uint32_t *en, *rst; uint32_t bit; }; struct cline lookup_clock_line(uint32_t periph_base); diff --git a/src/stm32/stm32f0.c b/src/stm32/stm32f0.c index e63f1b5b44c3..72fc1645e08a 100644 --- a/src/stm32/stm32f0.c +++ b/src/stm32/stm32f0.c @@ -134,39 +134,12 @@ hsi14_setup(void) * Bootloader ****************************************************************/ -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 1024) -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Flag that bootloader is desired and reboot -static void -usb_reboot_for_dfu_bootloader(void) -{ - irq_disable(); - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; - NVIC_SystemReset(); -} - -// Check if rebooting into system DFU Bootloader -static void -check_usb_dfu_bootloader(void) -{ - if (!CONFIG_USB || !CONFIG_MACH_STM32F0x2 - || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) - return; - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1fffc400; - if (CONFIG_MACH_STM32F072) - sysbase = (uint32_t*)0x1fffc800; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); -} - // Handle reboot requests void bootloader_request(void) { try_request_canboot(); - usb_reboot_for_dfu_bootloader(); + dfu_reboot(); } @@ -193,7 +166,7 @@ enable_ram_vectortable(void) void armcm_main(void) { - check_usb_dfu_bootloader(); + dfu_reboot_check(); SystemInit(); enable_pclock(SYSCFG_BASE); diff --git a/src/stm32/stm32f4.c b/src/stm32/stm32f4.c index 4f1dc084b86a..a2060d763626 100644 --- a/src/stm32/stm32f4.c +++ b/src/stm32/stm32f4.c @@ -204,30 +204,6 @@ usb_hid_bootloader(void) NVIC_SystemReset(); } -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Flag that bootloader is desired and reboot -static void -usb_reboot_for_dfu_bootloader(void) -{ - irq_disable(); - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; - NVIC_SystemReset(); -} - -// Check if rebooting into system DFU Bootloader -static void -check_usb_dfu_bootloader(void) -{ - if (!CONFIG_USB || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) - return; - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1fff0000; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); -} - // Handle reboot requests void bootloader_request(void) @@ -235,7 +211,7 @@ bootloader_request(void) try_request_canboot(); if (CONFIG_STM32_FLASH_START_4000) usb_hid_bootloader(); - usb_reboot_for_dfu_bootloader(); + dfu_reboot(); } @@ -247,7 +223,7 @@ bootloader_request(void) void armcm_main(void) { - check_usb_dfu_bootloader(); + dfu_reboot_check(); // Run SystemInit() and then restore VTOR SystemInit(); diff --git a/src/stm32/stm32g0.c b/src/stm32/stm32g0.c index f42ac7773025..41f7f6f2c1c9 100644 --- a/src/stm32/stm32g0.c +++ b/src/stm32/stm32g0.c @@ -128,36 +128,12 @@ clock_setup(void) * Bootloader ****************************************************************/ -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 1024) -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Flag that bootloader is desired and reboot -static void -usb_reboot_for_dfu_bootloader(void) -{ - irq_disable(); - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; - NVIC_SystemReset(); -} - -// Check if rebooting into system DFU Bootloader -static void -check_usb_dfu_bootloader(void) -{ - if (!CONFIG_USB || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) - return; - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1fff0000; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); -} - // Handle USB reboot requests void bootloader_request(void) { try_request_canboot(); - usb_reboot_for_dfu_bootloader(); + dfu_reboot(); } @@ -185,7 +161,7 @@ armcm_main(void) RCC->APBENR1 = 0x00000000; RCC->APBENR2 = 0x00000000; - check_usb_dfu_bootloader(); + dfu_reboot_check(); // Set flash latency, cache and prefetch; use reset value as base uint32_t acr = 0x00040600; diff --git a/src/stm32/stm32g4.c b/src/stm32/stm32g4.c index a0dd32c0dcd4..c3cf0969cc97 100644 --- a/src/stm32/stm32g4.c +++ b/src/stm32/stm32g4.c @@ -139,36 +139,11 @@ clock_setup(void) * Bootloader ****************************************************************/ -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Flag that bootloader is desired and reboot -static void -usb_reboot_for_dfu_bootloader(void) -{ - irq_disable(); - // System DFU Bootloader - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; - NVIC_SystemReset(); -} - -// Check if rebooting into system DFU Bootloader -static void -check_usb_dfu_bootloader(void) -{ - if (!CONFIG_USB || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) - return; - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1fff0000; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); -} - // Handle USB reboot requests void bootloader_request(void) { - usb_reboot_for_dfu_bootloader(); + dfu_reboot(); } @@ -180,7 +155,7 @@ bootloader_request(void) void armcm_main(void) { - check_usb_dfu_bootloader(); + dfu_reboot_check(); // Run SystemInit() and then restore VTOR SystemInit(); diff --git a/src/stm32/stm32h7.c b/src/stm32/stm32h7.c index 43b7aa6ede8a..dc9a29d1047e 100644 --- a/src/stm32/stm32h7.c +++ b/src/stm32/stm32h7.c @@ -208,38 +208,12 @@ clock_setup(void) * Bootloader ****************************************************************/ -#define USB_BOOT_FLAG_ADDR (0x24000000 + 0x8000) // Place flag in "AXI SRAM" -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Flag that bootloader is desired and reboot -static void -usb_reboot_for_dfu_bootloader(void) -{ - irq_disable(); - uint64_t *bflag = (void*)USB_BOOT_FLAG_ADDR; - *bflag = USB_BOOT_FLAG; - SCB_CleanDCache_by_Addr((void*)bflag, sizeof(*bflag)); - NVIC_SystemReset(); -} - -// Check if rebooting into system DFU Bootloader -static void -check_usb_dfu_bootloader(void) -{ - if (!CONFIG_USB || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) - return; - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1FF09800; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); -} - // Handle reboot requests void bootloader_request(void) { try_request_canboot(); - usb_reboot_for_dfu_bootloader(); + dfu_reboot(); } @@ -259,7 +233,7 @@ armcm_main(void) RCC->D3CCIPR = 0x00000000; SCB->VTOR = (uint32_t)VectorTable; - check_usb_dfu_bootloader(); + dfu_reboot_check(); clock_setup(); diff --git a/src/stm32/stm32l4.c b/src/stm32/stm32l4.c index b5c939bbf144..709473c8606e 100644 --- a/src/stm32/stm32l4.c +++ b/src/stm32/stm32l4.c @@ -139,36 +139,11 @@ clock_setup(void) * Bootloader ****************************************************************/ -#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) -#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" - -// Flag that bootloader is desired and reboot -static void -usb_reboot_for_dfu_bootloader(void) -{ - irq_disable(); - // System DFU Bootloader - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; - NVIC_SystemReset(); -} - -// Check if rebooting into system DFU Bootloader -static void -check_usb_dfu_bootloader(void) -{ - if (!CONFIG_USB || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) - return; - *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; - uint32_t *sysbase = (uint32_t*)0x1fff0000; - asm volatile("mov sp, %0\n bx %1" - : : "r"(sysbase[0]), "r"(sysbase[1])); -} - // Handle USB reboot requests void bootloader_request(void) { - usb_reboot_for_dfu_bootloader(); + dfu_reboot(); } @@ -180,7 +155,7 @@ bootloader_request(void) void armcm_main(void) { - check_usb_dfu_bootloader(); + dfu_reboot_check(); // Run SystemInit() and then restore VTOR SystemInit(); From 8621ebbed20e726acaad3922845cf141cd9e3d31 Mon Sep 17 00:00:00 2001 From: Keyan Mobli Date: Mon, 19 Dec 2022 10:14:45 -0600 Subject: [PATCH 18/40] bed_mesh: Allow bedmeshing at 1mm spaced intervals (#5918) Signed-off-by: Keyan Mobli --- klippy/extras/bed_mesh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index 0618c97071fa..19e89e604b15 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -315,7 +315,7 @@ def _generate_points(self, error): # floor distances down to next hundredth x_dist = math.floor(x_dist * 100) / 100 y_dist = math.floor(y_dist * 100) / 100 - if x_dist <= 1. or y_dist <= 1.: + if x_dist < 1. or y_dist < 1.: raise error("bed_mesh: min/max points too close together") if self.radius is not None: From f078a279059670e692ea676237b152b4d42518e4 Mon Sep 17 00:00:00 2001 From: janherich Date: Fri, 25 Nov 2022 13:09:56 +0100 Subject: [PATCH 19/40] manual_probe: Add Z_OFFSET_APPLY_ENDSTOP for delta Current Z_OFFSET_APPLY_ENDSTOP command only works for printers with cartesian architecture which have separate Z axis defined. But this functionality (persisting Z babystep value to endstops) is exactly as convinient for delta printers, therefore this PR implements it. Signed-off-by: Jan Herich --- klippy/extras/manual_probe.py | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/klippy/extras/manual_probe.py b/klippy/extras/manual_probe.py index c6e9dc64f64b..496455fa0d71 100644 --- a/klippy/extras/manual_probe.py +++ b/klippy/extras/manual_probe.py @@ -13,9 +13,25 @@ def __init__(self, config): self.gcode_move = self.printer.load_object(config, "gcode_move") self.gcode.register_command('MANUAL_PROBE', self.cmd_MANUAL_PROBE, desc=self.cmd_MANUAL_PROBE_help) + # Endstop value for cartesian printers with separate Z axis zconfig = config.getsection('stepper_z') self.z_position_endstop = zconfig.getfloat('position_endstop', None, note_valid=False) + # Endstop values for linear delta printers with vertical A,B,C towers + a_tower_config = config.getsection('stepper_a') + self.a_position_endstop = a_tower_config.getfloat('position_endstop', + None, + note_valid=False) + b_tower_config = config.getsection('stepper_b') + self.b_position_endstop = b_tower_config.getfloat('position_endstop', + None, + note_valid=False) + c_tower_config = config.getsection('stepper_c') + self.c_position_endstop = c_tower_config.getfloat('position_endstop', + None, + note_valid=False) + # Conditionally register appropriate commands depending on printer + # Cartestian printers with separate Z Axis if self.z_position_endstop is not None: self.gcode.register_command( 'Z_ENDSTOP_CALIBRATE', self.cmd_Z_ENDSTOP_CALIBRATE, @@ -24,6 +40,12 @@ def __init__(self, config): 'Z_OFFSET_APPLY_ENDSTOP', self.cmd_Z_OFFSET_APPLY_ENDSTOP, desc=self.cmd_Z_OFFSET_APPLY_ENDSTOP_help) + # Linear delta printers with A,B,C towers + if 'delta' == config.getsection('printer').get('kinematics'): + self.gcode.register_command( + 'Z_OFFSET_APPLY_ENDSTOP', + self.cmd_Z_OFFSET_APPLY_DELTA_ENDSTOPS, + desc=self.cmd_Z_OFFSET_APPLY_ENDSTOP_help) self.reset_status() def manual_probe_finalize(self, kin_pos): if kin_pos is not None: @@ -66,6 +88,29 @@ def cmd_Z_OFFSET_APPLY_ENDSTOP(self,gcmd): "with the above and restart the printer." % (new_calibrate)) configfile.set('stepper_z', 'position_endstop', "%.3f" % (new_calibrate,)) + def cmd_Z_OFFSET_APPLY_DELTA_ENDSTOPS(self,gcmd): + offset = self.gcode_move.get_status()['homing_origin'].z + configfile = self.printer.lookup_object('configfile') + if offset == 0: + self.gcode.respond_info("Nothing to do: Z Offset is 0") + else: + new_a_calibrate = self.a_position_endstop - offset + new_b_calibrate = self.b_position_endstop - offset + new_c_calibrate = self.c_position_endstop - offset + self.gcode.respond_info( + "stepper_a: position_endstop: %.3f\n" + "stepper_b: position_endstop: %.3f\n" + "stepper_c: position_endstop: %.3f\n" + "The SAVE_CONFIG command will update the printer config file\n" + "with the above and restart the printer." % (new_a_calibrate, + new_b_calibrate, + new_c_calibrate)) + configfile.set('stepper_a', 'position_endstop', + "%.3f" % (new_a_calibrate,)) + configfile.set('stepper_b', 'position_endstop', + "%.3f" % (new_b_calibrate,)) + configfile.set('stepper_c', 'position_endstop', + "%.3f" % (new_c_calibrate,)) cmd_Z_OFFSET_APPLY_ENDSTOP_help = "Adjust the z endstop_position" # Verify that a manual probe isn't already in progress From aac613bf44ca1feb4334ab35378b48711baccb60 Mon Sep 17 00:00:00 2001 From: Chris Lee Date: Mon, 19 Dec 2022 12:30:12 -0700 Subject: [PATCH 20/40] scripts: support CanBoot on RP2040 in flash_usb.py Signed-off-by: Chris Lee --- scripts/flash_usb.py | 6 +++++- src/rp2040/Makefile | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py index 83422f91a33e..e43c457c5cff 100755 --- a/scripts/flash_usb.py +++ b/scripts/flash_usb.py @@ -193,6 +193,7 @@ def call_picoboot(bus, addr, binfile, sudo): # Flash via Klipper modified "picoboot" def flash_picoboot(device, binfile, sudo): + ttyname, serbypath = translate_serial_to_tty(device) buspath, devpath = translate_serial_to_usb_path(device) # We need one level up to get access to busnum/devnum files usbdir = os.path.dirname(devpath) @@ -202,7 +203,10 @@ def flash_picoboot(device, binfile, sudo): bus = f.read().strip() with open(usbdir + "/devnum") as f: addr = f.read().strip() - call_picoboot(bus, addr, binfile, sudo) + if detect_canboot(devpath): + call_flashcan(serbypath, binfile) + else: + call_picoboot(bus, addr, binfile, sudo) ###################################################################### diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile index 32d731f2f084..71ed90a0cc0a 100644 --- a/src/rp2040/Makefile +++ b/src/rp2040/Makefile @@ -45,7 +45,7 @@ $(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 +rptarget-$(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 @@ -54,10 +54,11 @@ $(OUT)klipper.bin: $(OUT)klipper.elf @echo " Creating bin file $@" $(Q)$(OBJCOPY) -O binary $< $@ -target-$(CONFIG_RP2040_HAVE_BOOTLOADER) += $(OUT)klipper.bin +rptarget-$(CONFIG_RP2040_HAVE_BOOTLOADER) := $(OUT)klipper.bin rplink-$(CONFIG_RP2040_HAVE_BOOTLOADER) := $(OUT)src/generic/armcm_link.ld # Set klipper.elf linker rules +target-y += $(rptarget-y) CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs -T $(rplink-y) OBJS_klipper.elf += $(stage2-y) $(OUT)klipper.elf: $(stage2-y) $(rplink-y) @@ -67,6 +68,6 @@ lib/rp2040_flash/rp2040_flash: @echo " Building rp2040_flash" $(Q)make -C lib/rp2040_flash rp2040_flash -flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash +flash: $(rptarget-y) 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 + $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(rptarget-y) From 9b60daf62dd7c02164c53f2baa72e3e6c8af441f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 22 Dec 2022 03:23:23 +0100 Subject: [PATCH 21/40] tmc: Configurable microstep lookup table (#5920) Make all the microstep lookup table registers configurable via the config file. It also loads the default values. TMC220x and TMC2660 do not support this feature. Signed-off-by: Alex Voinea --- docs/Config_Reference.md | 48 ++++++++++++++++++++++++++++++++++++++++ klippy/extras/tmc.py | 21 ++++++++++++++++++ klippy/extras/tmc2130.py | 32 +++++++++++++++++++++++---- klippy/extras/tmc5160.py | 22 ++++++++++++++++++ 4 files changed, 119 insertions(+), 4 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 4319a0568b81..eff6a23676a5 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -3073,6 +3073,30 @@ run_current: # set, "stealthChop" mode will be enabled if the stepper motor # velocity is below this value. The default is 0, which disables # "stealthChop" mode. +#driver_MSLUT0: 2863314260 +#driver_MSLUT1: 1251300522 +#driver_MSLUT2: 608774441 +#driver_MSLUT3: 269500962 +#driver_MSLUT4: 4227858431 +#driver_MSLUT5: 3048961917 +#driver_MSLUT6: 1227445590 +#driver_MSLUT7: 4211234 +#driver_W0: 2 +#driver_W1: 1 +#driver_W2: 1 +#driver_W3: 1 +#driver_X1: 128 +#driver_X2: 255 +#driver_X3: 255 +#driver_START_SIN: 0 +#driver_START_SIN90: 247 +# These fields control the Microstep Table registers directly. The optimal +# wave table is specific to each motor and might vary with current. An +# optimal configuration will have minimal print artifacts caused by +# non-linear stepper movement. The values specified above are the default +# values used by the driver. The value must be specified as a decimal integer +# (hex form is not supported). In order to compute the wave table fields, +# see the tmc2130 "Calculation Sheet" from the Trinamic website. #driver_IHOLDDELAY: 8 #driver_TPOWERDOWN: 0 #driver_TBL: 1 @@ -3328,6 +3352,30 @@ run_current: # set, "stealthChop" mode will be enabled if the stepper motor # velocity is below this value. The default is 0, which disables # "stealthChop" mode. +#driver_MSLUT0: 2863314260 +#driver_MSLUT1: 1251300522 +#driver_MSLUT2: 608774441 +#driver_MSLUT3: 269500962 +#driver_MSLUT4: 4227858431 +#driver_MSLUT5: 3048961917 +#driver_MSLUT6: 1227445590 +#driver_MSLUT7: 4211234 +#driver_W0: 2 +#driver_W1: 1 +#driver_W2: 1 +#driver_W3: 1 +#driver_X1: 128 +#driver_X2: 255 +#driver_X3: 255 +#driver_START_SIN: 0 +#driver_START_SIN90: 247 +# These fields control the Microstep Table registers directly. The optimal +# wave table is specific to each motor and might vary with current. An +# optimal configuration will have minimal print artifacts caused by +# non-linear stepper movement. The values specified above are the default +# values used by the driver. The value must be specified as a decimal integer +# (hex form is not supported). In order to compute the wave table fields, +# see the tmc2130 "Calculation Sheet" from the Trinamic website. #driver_IHOLDDELAY: 6 #driver_TPOWERDOWN: 10 #driver_TBL: 2 diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py index df3c705bd840..519905368875 100644 --- a/klippy/extras/tmc.py +++ b/klippy/extras/tmc.py @@ -501,6 +501,27 @@ def handle_homing_move_end(self, hmove): # Config reading helpers ###################################################################### +# Helper to initialize the wave table from config or defaults +def TMCWaveTableHelper(config, mcu_tmc): + set_config_field = mcu_tmc.get_fields().set_config_field + set_config_field(config, "mslut0", 0xAAAAB554) + set_config_field(config, "mslut1", 0x4A9554AA) + set_config_field(config, "mslut2", 0x24492929) + set_config_field(config, "mslut3", 0x10104222) + set_config_field(config, "mslut4", 0xFBFFFFFF) + set_config_field(config, "mslut5", 0xB5BB777D) + set_config_field(config, "mslut6", 0x49295556) + set_config_field(config, "mslut7", 0x00404222) + set_config_field(config, "w0", 2) + set_config_field(config, "w1", 1) + set_config_field(config, "w2", 1) + set_config_field(config, "w3", 1) + set_config_field(config, "x1", 128) + set_config_field(config, "x2", 255) + set_config_field(config, "x3", 255) + set_config_field(config, "start_sin", 0) + set_config_field(config, "start_sin90", 247) + # Helper to configure and query the microstep settings def TMCMicrostepHelper(config, mcu_tmc): fields = mcu_tmc.get_fields() diff --git a/klippy/extras/tmc2130.py b/klippy/extras/tmc2130.py index f2142d26fd0f..128c1d93fdef 100644 --- a/klippy/extras/tmc2130.py +++ b/klippy/extras/tmc2130.py @@ -11,10 +11,12 @@ Registers = { "GCONF": 0x00, "GSTAT": 0x01, "IOIN": 0x04, "IHOLD_IRUN": 0x10, "TPOWERDOWN": 0x11, "TSTEP": 0x12, "TPWMTHRS": 0x13, "TCOOLTHRS": 0x14, - "THIGH": 0x15, "XDIRECT": 0x2d, "MSLUT0": 0x60, "MSLUTSEL": 0x68, - "MSLUTSTART": 0x69, "MSCNT": 0x6a, "MSCURACT": 0x6b, "CHOPCONF": 0x6c, - "COOLCONF": 0x6d, "DCCTRL": 0x6e, "DRV_STATUS": 0x6f, "PWMCONF": 0x70, - "PWM_SCALE": 0x71, "ENCM_CTRL": 0x72, "LOST_STEPS": 0x73, + "THIGH": 0x15, "XDIRECT": 0x2d, "MSLUT0": 0x60, "MSLUT1": 0x61, + "MSLUT2": 0x62, "MSLUT3": 0x63, "MSLUT4": 0x64, "MSLUT5": 0x65, + "MSLUT6": 0x66, "MSLUT7": 0x67, "MSLUTSEL": 0x68, "MSLUTSTART": 0x69, + "MSCNT": 0x6a, "MSCURACT": 0x6b, "CHOPCONF": 0x6c, "COOLCONF": 0x6d, + "DCCTRL": 0x6e, "DRV_STATUS": 0x6f, "PWMCONF": 0x70, "PWM_SCALE": 0x71, + "ENCM_CTRL": 0x72, "LOST_STEPS": 0x73, } ReadRegisters = [ @@ -45,6 +47,27 @@ Fields["TPWMTHRS"] = { "tpwmthrs": 0xfffff } Fields["TCOOLTHRS"] = { "tcoolthrs": 0xfffff } Fields["THIGH"] = { "thigh": 0xfffff } +Fields["MSLUT0"] = { "mslut0": 0xffffffff } +Fields["MSLUT1"] = { "mslut1": 0xffffffff } +Fields["MSLUT2"] = { "mslut2": 0xffffffff } +Fields["MSLUT3"] = { "mslut3": 0xffffffff } +Fields["MSLUT4"] = { "mslut4": 0xffffffff } +Fields["MSLUT5"] = { "mslut5": 0xffffffff } +Fields["MSLUT6"] = { "mslut6": 0xffffffff } +Fields["MSLUT7"] = { "mslut7": 0xffffffff } +Fields["MSLUTSEL"] = { + "x3": 0xFF << 24, + "x2": 0xFF << 16, + "x1": 0xFF << 8, + "w3": 0x03 << 6, + "w2": 0x03 << 4, + "w1": 0x03 << 2, + "w0": 0x03 << 0, +} +Fields["MSLUTSTART"] = { + "start_sin": 0xFF << 0, + "start_sin90": 0xFF << 16, +} Fields["MSCNT"] = { "mscnt": 0x3ff } Fields["MSCURACT"] = { "cur_a": 0x1ff, "cur_b": 0x1ff << 16 } Fields["CHOPCONF"] = { @@ -268,6 +291,7 @@ def __init__(self, config): self.get_phase_offset = cmdhelper.get_phase_offset self.get_status = cmdhelper.get_status # Setup basic register values + tmc.TMCWaveTableHelper(config, self.mcu_tmc) tmc.TMCStealthchopHelper(config, self.mcu_tmc, TMC_FREQUENCY) # Allow other registers to be set from the config set_config_field = self.fields.set_config_field diff --git a/klippy/extras/tmc5160.py b/klippy/extras/tmc5160.py index 4d9702711d7b..5d570958af61 100644 --- a/klippy/extras/tmc5160.py +++ b/klippy/extras/tmc5160.py @@ -171,6 +171,27 @@ Fields["LOST_STEPS"] = { "lost_steps": 0xfffff << 0 } +Fields["MSLUT0"] = { "mslut0": 0xffffffff } +Fields["MSLUT1"] = { "mslut1": 0xffffffff } +Fields["MSLUT2"] = { "mslut2": 0xffffffff } +Fields["MSLUT3"] = { "mslut3": 0xffffffff } +Fields["MSLUT4"] = { "mslut4": 0xffffffff } +Fields["MSLUT5"] = { "mslut5": 0xffffffff } +Fields["MSLUT6"] = { "mslut6": 0xffffffff } +Fields["MSLUT7"] = { "mslut7": 0xffffffff } +Fields["MSLUTSEL"] = { + "x3": 0xFF << 24, + "x2": 0xFF << 16, + "x1": 0xFF << 8, + "w3": 0x03 << 6, + "w2": 0x03 << 4, + "w1": 0x03 << 2, + "w0": 0x03 << 0, +} +Fields["MSLUTSTART"] = { + "start_sin": 0xFF << 0, + "start_sin90": 0xFF << 16, +} Fields["MSCNT"] = { "mscnt": 0x3ff << 0 } @@ -299,6 +320,7 @@ def __init__(self, config): self.get_phase_offset = cmdhelper.get_phase_offset self.get_status = cmdhelper.get_status # Setup basic register values + tmc.TMCWaveTableHelper(config, self.mcu_tmc) tmc.TMCStealthchopHelper(config, self.mcu_tmc, TMC_FREQUENCY) # CHOPCONF set_config_field = self.fields.set_config_field From 4753315601b4203c500c979f87b2e55be2aedaa5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 19 Dec 2022 11:51:31 -0500 Subject: [PATCH 22/40] Kconfig: No need to specify "default n" in main Kconfig file A "bool" option already defaults to "n" so no need to state that explicitly. Signed-off-by: Kevin O'Connor --- src/Kconfig | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Kconfig b/src/Kconfig index cfad688d5179..2309fe9edd87 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -4,7 +4,6 @@ mainmenu "Klipper Firmware Configuration" config LOW_LEVEL_OPTIONS bool "Enable extra low-level configuration options" - default n help Enable low-level configuration options that (if modified) may result in a build that does not function correctly. @@ -111,31 +110,22 @@ config INITIAL_PINS # if the hardware does not support the feature. config HAVE_GPIO bool - default n config HAVE_GPIO_ADC bool - default n config HAVE_GPIO_SPI bool - default n config HAVE_GPIO_I2C bool - default n config HAVE_GPIO_HARD_PWM bool - default n config HAVE_GPIO_BITBANGING bool - default n config HAVE_STRICT_TIMING bool - default n config HAVE_CHIPID bool - default n config HAVE_STEPPER_BOTH_EDGE bool - default n config INLINE_STEPPER_HACK # Enables gcc to inline stepper_event() into the main timer irq handler From 4ca1e5f670616491cf27de833a90290d0aaf6fb0 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 19 Dec 2022 11:54:19 -0500 Subject: [PATCH 23/40] serial_irq: Rename SERIAL_BOOTLOADER_SIDECHANNEL to HAVE_BOOTLOADER_REQUEST Rename the build symbol. This is in preparation for enabling HAVE_BOOTLOADER_REQUEST on usb and canbus. Signed-off-by: Kevin O'Connor --- src/Kconfig | 4 ++-- src/generic/serial_irq.c | 2 +- src/lpc176x/Kconfig | 2 +- src/stm32/Kconfig | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Kconfig b/src/Kconfig index 2309fe9edd87..53b6d1662f39 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -43,8 +43,6 @@ source "src/simulator/Kconfig" # Generic configuration options for serial ports config SERIAL bool -config SERIAL_BOOTLOADER_SIDECHANNEL - bool config SERIAL_BAUD depends on SERIAL int "Baud rate for serial port" if LOW_LEVEL_OPTIONS @@ -126,6 +124,8 @@ config HAVE_CHIPID bool config HAVE_STEPPER_BOTH_EDGE bool +config HAVE_BOOTLOADER_REQUEST + bool config INLINE_STEPPER_HACK # Enables gcc to inline stepper_event() into the main timer irq handler diff --git a/src/generic/serial_irq.c b/src/generic/serial_irq.c index 434a98bbe007..98910735add3 100644 --- a/src/generic/serial_irq.c +++ b/src/generic/serial_irq.c @@ -79,7 +79,7 @@ console_task(void) if (ret > 0) command_dispatch(receive_buf, pop_count); if (ret) { - if (CONFIG_SERIAL_BOOTLOADER_SIDECHANNEL && ret < 0 && pop_count == 32 + if (CONFIG_HAVE_BOOTLOADER_REQUEST && ret < 0 && pop_count == 32 && !memcmp(receive_buf, " \x1c Request Serial Bootloader!! ~", 32)) bootloader_request(); console_pop_input(pop_count); diff --git a/src/lpc176x/Kconfig b/src/lpc176x/Kconfig index 02da06da36a6..79c3b3006c01 100644 --- a/src/lpc176x/Kconfig +++ b/src/lpc176x/Kconfig @@ -14,7 +14,7 @@ config LPC_SELECT select HAVE_CHIPID select HAVE_GPIO_HARD_PWM select HAVE_STEPPER_BOTH_EDGE - select SERIAL_BOOTLOADER_SIDECHANNEL + select HAVE_BOOTLOADER_REQUEST config BOARD_DIRECTORY string diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index dac884a03331..a3a9da022284 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -14,7 +14,7 @@ config STM32_SELECT select HAVE_STRICT_TIMING select HAVE_CHIPID select HAVE_STEPPER_BOTH_EDGE - select SERIAL_BOOTLOADER_SIDECHANNEL + select HAVE_BOOTLOADER_REQUEST config BOARD_DIRECTORY string From 806cf233ec238802ce75c1f0a35cf9dcba1644f0 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 19 Dec 2022 11:57:39 -0500 Subject: [PATCH 24/40] stm32: Include "misc.h" in stm32l4.c and stm32g4.c Include for bootloader_request() definition. Signed-off-by: Kevin O'Connor --- src/stm32/stm32g4.c | 1 + src/stm32/stm32l4.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/stm32/stm32g4.c b/src/stm32/stm32g4.c index c3cf0969cc97..4ed8bc6c2dd7 100644 --- a/src/stm32/stm32g4.c +++ b/src/stm32/stm32g4.c @@ -7,6 +7,7 @@ #include "autoconf.h" // CONFIG_CLOCK_REF_FREQ #include "board/armcm_boot.h" // VectorTable #include "board/irq.h" // irq_disable +#include "board/misc.h" // bootloader_request #include "command.h" // DECL_CONSTANT_STR #include "internal.h" // enable_pclock #include "sched.h" // sched_main diff --git a/src/stm32/stm32l4.c b/src/stm32/stm32l4.c index 709473c8606e..0555ae3ee030 100644 --- a/src/stm32/stm32l4.c +++ b/src/stm32/stm32l4.c @@ -7,6 +7,7 @@ #include "autoconf.h" // CONFIG_CLOCK_REF_FREQ #include "board/armcm_boot.h" // VectorTable #include "board/irq.h" // irq_disable +#include "board/misc.h" // bootloader_request #include "command.h" // DECL_CONSTANT_STR #include "internal.h" // enable_pclock #include "sched.h" // sched_main From 34fd3f41ea1f819fb43b386334d01c13ffb4f781 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 19 Dec 2022 12:04:54 -0500 Subject: [PATCH 25/40] usb_cdc: Only call bootloader_request() if CONFIG_HAVE_BOOTLOADER_REQUEST Check for the build symbol prior to calling bootloader_request(). Enable the build symbol on rp2040, atsam, and atsamd chips. This also enables serial bootloader requsts on rp2040, atsam, and atsamd. Signed-off-by: Kevin O'Connor --- src/atsam/Kconfig | 1 + src/atsamd/Kconfig | 1 + src/generic/usb_cdc.c | 2 ++ src/rp2040/Kconfig | 1 + 4 files changed, 5 insertions(+) diff --git a/src/atsam/Kconfig b/src/atsam/Kconfig index 4e2e839ec93f..aa802072ea33 100644 --- a/src/atsam/Kconfig +++ b/src/atsam/Kconfig @@ -14,6 +14,7 @@ config ATSAM_SELECT select HAVE_STRICT_TIMING select HAVE_CHIPID select HAVE_STEPPER_BOTH_EDGE + select HAVE_BOOTLOADER_REQUEST config BOARD_DIRECTORY string diff --git a/src/atsamd/Kconfig b/src/atsamd/Kconfig index d6643ffd7bfe..05e4c50efac6 100644 --- a/src/atsamd/Kconfig +++ b/src/atsamd/Kconfig @@ -14,6 +14,7 @@ config ATSAMD_SELECT select HAVE_STRICT_TIMING select HAVE_CHIPID select HAVE_STEPPER_BOTH_EDGE + select HAVE_BOOTLOADER_REQUEST config HAVE_SERCOM depends on HAVE_GPIO_I2C || HAVE_GPIO_SPI diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c index 40ff74ba62fc..143c213f0620 100644 --- a/src/generic/usb_cdc.c +++ b/src/generic/usb_cdc.c @@ -446,6 +446,8 @@ static uint8_t line_control_state; static void check_reboot(void) { + if (!CONFIG_HAVE_BOOTLOADER_REQUEST) + return; if (line_coding.dwDTERate == 1200 && !(line_control_state & 0x01)) // A baud of 1200 is an Arduino style request to enter the bootloader bootloader_request(); diff --git a/src/rp2040/Kconfig b/src/rp2040/Kconfig index 904699f84be4..ba6f00f80db4 100644 --- a/src/rp2040/Kconfig +++ b/src/rp2040/Kconfig @@ -14,6 +14,7 @@ config RP2040_SELECT select HAVE_CHIPID select HAVE_GPIO_HARD_PWM select HAVE_STEPPER_BOTH_EDGE + select HAVE_BOOTLOADER_REQUEST config BOARD_DIRECTORY string From c620f4836e0035ed36d13f2e44f9097ec7ae700d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 19 Dec 2022 12:07:51 -0500 Subject: [PATCH 26/40] canserial: Only call bootloader_request() if CONFIG_HAVE_BOOTLOADER_REQUEST Signed-off-by: Kevin O'Connor --- src/generic/canserial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/generic/canserial.c b/src/generic/canserial.c index fa46a6d2521e..0607e4893e91 100644 --- a/src/generic/canserial.c +++ b/src/generic/canserial.c @@ -7,6 +7,7 @@ // This file may be distributed under the terms of the GNU GPLv3 license. #include // memcpy +#include "autoconf.h" // CONFIG_HAVE_BOOTLOADER_REQUEST #include "board/io.h" // readb #include "board/irq.h" // irq_save #include "board/misc.h" // console_sendf @@ -185,7 +186,7 @@ can_process_set_klipper_nodeid(struct canbus_msg *msg) static void can_process_request_bootloader(struct canbus_msg *msg) { - if (!can_check_uuid(msg)) + if (!CONFIG_HAVE_BOOTLOADER_REQUEST || !can_check_uuid(msg)) return; bootloader_request(); } From b51b06844213b3aede71fa3de2100e82ec7d35dc Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 19 Dec 2022 12:09:28 -0500 Subject: [PATCH 27/40] avr: No need to define bootloader_request() Since avr does not define HAVE_BOOTLOADER_REQUEST it is not necessary to define the function. Signed-off-by: Kevin O'Connor --- src/avr/usbserial.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c index ab61fde2207b..e95ab040e44a 100644 --- a/src/avr/usbserial.c +++ b/src/avr/usbserial.c @@ -7,7 +7,6 @@ #include // USB_COM_vect #include // NULL #include "autoconf.h" // CONFIG_MACH_at90usb1286 -#include "board/misc.h" // bootloader_request #include "board/usb_cdc.h" // usb_notify_ep0 #include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN #include "pgm.h" // READP @@ -179,11 +178,6 @@ usb_set_configure(void) UEIENX = 1< Date: Mon, 19 Dec 2022 12:11:43 -0500 Subject: [PATCH 28/40] stm32: Check for CONFIG_HAVE_BOOTLOADER_REQUEST in dfu_reboot.c Support disabling dfu_reboot if HAVE_BOOTLOADER_REQUEST is disabled in the Kconfig rules. Signed-off-by: Kevin O'Connor --- src/stm32/dfu_reboot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stm32/dfu_reboot.c b/src/stm32/dfu_reboot.c index 04952a483cfe..68f023d17a3a 100644 --- a/src/stm32/dfu_reboot.c +++ b/src/stm32/dfu_reboot.c @@ -31,7 +31,7 @@ void dfu_reboot(void) { - if (!CONFIG_STM32_DFU_ROM_ADDRESS) + if (!CONFIG_STM32_DFU_ROM_ADDRESS || !CONFIG_HAVE_BOOTLOADER_REQUEST) return; irq_disable(); uint64_t *bflag = (void*)USB_BOOT_FLAG_ADDR; @@ -46,7 +46,7 @@ dfu_reboot(void) void dfu_reboot_check(void) { - if (!CONFIG_STM32_DFU_ROM_ADDRESS) + if (!CONFIG_STM32_DFU_ROM_ADDRESS || !CONFIG_HAVE_BOOTLOADER_REQUEST) return; if (*(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) return; From 29ba5ab05af87a4cab88da0157a97fc3b97354ae Mon Sep 17 00:00:00 2001 From: janherich Date: Wed, 30 Nov 2022 23:33:24 +0100 Subject: [PATCH 29/40] delta: Better delta build volume constraint check Existing code uses very restrictive build volume constraint checking with just narrow cone on top of fully cylinder for delta printers. Code here implements more permissive and still safe build volume constraint checks. Signed-off-by: Jan Herich --- klippy/kinematics/delta.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/klippy/kinematics/delta.py b/klippy/kinematics/delta.py index 2278dbca76ae..bb81ab18abeb 100644 --- a/klippy/kinematics/delta.py +++ b/klippy/kinematics/delta.py @@ -65,6 +65,8 @@ def __init__(self, toolhead, config): self.min_z = config.getfloat('minimum_z_position', 0, maxval=self.max_z) self.limit_z = min([ep - arm for ep, arm in zip(self.abs_endstops, arm_lengths)]) + self.min_arm_length = min_arm_length = min(arm_lengths) + self.min_arm2 = min_arm_length**2 logging.info( "Delta max build height %.2fmm (radius tapered above %.2fmm)" % (self.max_z, self.limit_z)) @@ -123,7 +125,11 @@ def check_move(self, move): end_z = end_pos[2] limit_xy2 = self.max_xy2 if end_z > self.limit_z: - limit_xy2 = min(limit_xy2, (self.max_z - end_z)**2) + above_z_limit = end_z - self.limit_z + allowed_radius = self.radius - math.sqrt( + self.min_arm2 - (self.min_arm_length - above_z_limit)**2 + ) + limit_xy2 = min(limit_xy2, allowed_radius**2) if end_xy2 > limit_xy2 or end_z > self.max_z or end_z < self.min_z: # Move out of range - verify not a homing move if (end_pos[:2] != self.home_position[:2] From f57ff2c07e25c3946e598dc2b3a5525c63a2c8e5 Mon Sep 17 00:00:00 2001 From: CODeRUS Date: Thu, 29 Dec 2022 19:08:50 +0300 Subject: [PATCH 30/40] docs: Fix typo in mpu9250 documentation Adding MPU-6515, replacing MPU-9255 duplicate Signed-off-by: Andrei Kozhevnikov --- docs/Config_Reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index eff6a23676a5..445d8674e514 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1640,7 +1640,7 @@ cs_pin: ### [mpu9250] -Support for MPU-9250, MPU-9255, MPU-9255, MPU-6050, and MPU-6500 +Support for MPU-9250, MPU-9255, MPU-6515, MPU-6050, and MPU-6500 accelerometers (one may define any number of sections with an "mpu9250" prefix). From 6ae6aaf71179ef1a57dde9c7d3b0b2efb3baf05d Mon Sep 17 00:00:00 2001 From: JamesH1978 <87171443+JamesH1978@users.noreply.github.com> Date: Sat, 31 Dec 2022 23:26:30 +0000 Subject: [PATCH 31/40] board_defs: Add Fysetc Cheetah V2 to spi_flash (#5952) As discussed with user HiitsameAsh on discord, he has confirmed this addition will flash a Fysetc Cheetah V2 Signed-off-by: James Hartley --- scripts/spi_flash/board_defs.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/spi_flash/board_defs.py b/scripts/spi_flash/board_defs.py index 51ff276dca85..e136c7d97923 100644 --- a/scripts/spi_flash/board_defs.py +++ b/scripts/spi_flash/board_defs.py @@ -110,6 +110,12 @@ 'mcu': "stm32f405xx", 'spi_bus': "spi1", "cs_pin": "PA4" + }, + 'fysetc-cheetah': { + 'mcu': "stm32f401xc", + 'spi_bus': "spi1", + "cs_pin": "PA4", + "current_firmware_path": "OLD.BIN" } } @@ -151,6 +157,7 @@ 'btt-skr-pro-v1.2': BOARD_DEFS['btt-skr-pro'], 'btt-gtr-v1': BOARD_DEFS['btt-gtr'], 'mks-robin-e3d': BOARD_DEFS['mks-robin-e3'], + 'fysetc-cheetah-v2': BOARD_DEFS['fysetc-cheetah'], 'fysetc-spider-v1': BOARD_DEFS['fysetc-spider'], 'fysetc-s6-v1.2': BOARD_DEFS['fysetc-spider'], 'fysetc-s6-v2': BOARD_DEFS['fysetc-spider'], From 40d8c2ef1653ed59dc1d9fe4cb4e26b2e98a8967 Mon Sep 17 00:00:00 2001 From: Clifford Roche Date: Fri, 30 Dec 2022 21:05:47 -0500 Subject: [PATCH 32/40] palette2: Fix errors with bad handling of NoneType in a few locations Issue specific to Python 3, NoneType is being used to compare heartbeat time (actually caused by invalid condition operator), and by returning NoneType in timer functions. Signed-off-by: Clifford Roche --- klippy/extras/palette2.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/klippy/extras/palette2.py b/klippy/extras/palette2.py index c3c43ea693c1..ec8631b0a50e 100644 --- a/klippy/extras/palette2.py +++ b/klippy/extras/palette2.py @@ -221,9 +221,9 @@ def cmd_OmegaDefault(self, gcmd): def _wait_for_heartbeat(self): startTs = self.reactor.monotonic() currTs = startTs - while self.heartbeat is None and self.heartbeat < ( - currTs - SETUP_TIMEOUT) and startTs > ( - currTs - SETUP_TIMEOUT): + while self.heartbeat is None or (self.heartbeat < ( + currTs - SETUP_TIMEOUT) and startTs > ( + currTs - SETUP_TIMEOUT)): currTs = self.reactor.pause(currTs + 1.) if self.heartbeat < (currTs - SETUP_TIMEOUT): @@ -401,7 +401,7 @@ def p2cmd_O50(self, params): try: fw = params[0][1:] logging.info( - "Palette 2 firmware version %s detected" % os.fwalk) + "Palette 2 firmware version %s detected" % fw) except (TypeError, IndexError): logging.error("Unable to parse firmware version") @@ -583,7 +583,7 @@ def _run_Heartbeat(self, eventtime): self.write_queue.put(COMMAND_HEARTBEAT) eventtime = self.reactor.pause(eventtime + 5) if self.heartbeat and self.heartbeat < ( - eventtime - HEARTBEAT_TIMEOUT): + eventtime - HEARTBEAT_TIMEOUT): logging.error( "P2 has not responded to heartbeat") if not self.is_printing or self.is_setup_complete: @@ -612,6 +612,7 @@ def _run_Write(self, eventtime): logging.error("Unable to communicate with the Palette 2") self.signal_disconnect = True return self.reactor.NEVER + return eventtime + SERIAL_TIMER return eventtime + SERIAL_TIMER def _run_Smart_Load(self, eventtime): From b337cc3ee87c6620d2211a08e5568d59ad92b681 Mon Sep 17 00:00:00 2001 From: Stas Yakobov <16795594+fire1ce@users.noreply.github.com> Date: Mon, 2 Jan 2023 22:22:46 +0200 Subject: [PATCH 33/40] config: Added precise location of [bed_screws] for Ender-3-s1 (#5944) Signed-off-by: Stas Yakobov --- config/printer-creality-ender3-s1-2021.cfg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/printer-creality-ender3-s1-2021.cfg b/config/printer-creality-ender3-s1-2021.cfg index e46ae6def30f..6c64be0e3f71 100644 --- a/config/printer-creality-ender3-s1-2021.cfg +++ b/config/printer-creality-ender3-s1-2021.cfg @@ -129,3 +129,9 @@ runout_gcode: PAUSE [pause_resume] recover_velocity: 25 + +[bed_screws] +screw1: 20, 29 +screw2: 195, 29 +screw3: 195, 198 +screw4: 20, 198 From 9c2ccceb9f4890abe9d2c8a0953ae59fd529b8ef Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 3 Jan 2023 19:43:46 +0200 Subject: [PATCH 34/40] stm32: Expand stm32g0 family (#5838) Add stm32g07x family support. Signed-off-by: Alex Voinea --- src/stm32/Kconfig | 13 ++++++++++ src/stm32/hard_pwm.c | 4 +++ src/stm32/stm32f0_i2c.c | 55 ++++++++++++++++++++++++----------------- src/stm32/stm32g0.c | 13 ++++++++-- 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index a3a9da022284..e44604c12fe0 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -65,6 +65,14 @@ choice bool "STM32F072" select MACH_STM32F0 select MACH_STM32F0x2 + config MACH_STM32G070 + bool "STM32G070" + select MACH_STM32G0 + select MACH_STM32G07x + config MACH_STM32G071 + bool "STM32G071" + select MACH_STM32G0 + select MACH_STM32G07x config MACH_STM32G0B0 bool "STM32G0B0" select MACH_STM32G0 @@ -104,6 +112,8 @@ config MACH_STM32F4 bool config MACH_STM32G0 bool +config MACH_STM32G07x + bool config MACH_STM32G0Bx bool config MACH_STM32G4 @@ -149,6 +159,8 @@ config MCU default "stm32f407xx" if MACH_STM32F407 default "stm32f429xx" if MACH_STM32F429 default "stm32f446xx" if MACH_STM32F446 + default "stm32g070xx" if MACH_STM32G070 + default "stm32g071xx" if MACH_STM32G071 default "stm32g0b0xx" if MACH_STM32G0B0 default "stm32g0b1xx" if MACH_STM32G0B1 default "stm32g431xx" if MACH_STM32G431 @@ -203,6 +215,7 @@ config RAM_SIZE default 0x20000 if MACH_STM32F207 default 0x10000 if MACH_STM32F401 default 0x20000 if MACH_STM32F4x5 || MACH_STM32F446 + default 0x9000 if MACH_STM32G07x default 0x24000 if MACH_STM32G0Bx default 0x20000 if MACH_STM32H7 diff --git a/src/stm32/hard_pwm.c b/src/stm32/hard_pwm.c index 449de8b9ba63..0aafe7d49bd1 100644 --- a/src/stm32/hard_pwm.c +++ b/src/stm32/hard_pwm.c @@ -117,10 +117,12 @@ static const struct gpio_pwm_info pwm_regs[] = { {TIM1, GPIO('B', 3), 2, GPIO_FUNCTION(1)}, {TIM3, GPIO('B', 4), 1, GPIO_FUNCTION(1)}, {TIM3, GPIO('B', 5), 2, GPIO_FUNCTION(1)}, +#if CONFIG_MACH_STM32G0Bx {TIM4, GPIO('B', 6), 1, GPIO_FUNCTION(9)}, {TIM4, GPIO('B', 7), 2, GPIO_FUNCTION(9)}, {TIM4, GPIO('B', 8), 3, GPIO_FUNCTION(9)}, {TIM4, GPIO('B', 9), 4, GPIO_FUNCTION(9)}, +#endif {TIM15, GPIO('B', 14), 1, GPIO_FUNCTION(5)}, {TIM15, GPIO('B', 15), 2, GPIO_FUNCTION(5)}, {TIM15, GPIO('C', 1), 1, GPIO_FUNCTION(2)}, @@ -134,10 +136,12 @@ static const struct gpio_pwm_info pwm_regs[] = { {TIM14, GPIO('C', 12), 1, GPIO_FUNCTION(2)}, {TIM16, GPIO('D', 0), 1, GPIO_FUNCTION(2)}, {TIM17, GPIO('D', 1), 1, GPIO_FUNCTION(2)}, +#if CONFIG_MACH_STM32G0Bx {TIM4, GPIO('D', 12), 1, GPIO_FUNCTION(2)}, {TIM4, GPIO('D', 13), 2, GPIO_FUNCTION(2)}, {TIM4, GPIO('D', 14), 3, GPIO_FUNCTION(2)}, {TIM4, GPIO('D', 15), 4, GPIO_FUNCTION(2)}, +#endif {TIM3, GPIO('E', 3), 1, GPIO_FUNCTION(1)}, {TIM3, GPIO('E', 4), 2, GPIO_FUNCTION(1)}, {TIM3, GPIO('E', 5), 3, GPIO_FUNCTION(1)}, diff --git a/src/stm32/stm32f0_i2c.c b/src/stm32/stm32f0_i2c.c index 6096b673c700..9e8994fc475c 100644 --- a/src/stm32/stm32f0_i2c.c +++ b/src/stm32/stm32f0_i2c.c @@ -27,27 +27,34 @@ DECL_ENUMERATION("i2c_bus", "i2c1", 0); DECL_CONSTANT_STR("BUS_PINS_i2c1", "PB6,PB7"); DECL_ENUMERATION("i2c_bus", "i2c1a", 1); DECL_CONSTANT_STR("BUS_PINS_i2c1a", "PF1,PF0"); - -#elif CONFIG_MACH_STM32G0 || CONFIG_MACH_STM32L4 +#elif CONFIG_MACH_STM32G0 DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 1); DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); -#if CONFIG_MACH_STM32G0 -#define GPIO_AF_INDEX 6 -DECL_ENUMERATION("i2c_bus", "i2c3_PB3_PB4", 2); +DECL_ENUMERATION("i2c_bus", "i2c1_PA9_PA10", 2); +DECL_CONSTANT_STR("BUS_PINS_i2c1_PA9_PA10", "PA9,PA10"); +DECL_ENUMERATION("i2c_bus", "i2c2_PB10_PB11", 3); +DECL_CONSTANT_STR("BUS_PINS_i2c2_PB10_PB11", "PB10,PB11"); +DECL_ENUMERATION("i2c_bus", "i2c2_PB13_PB14", 4); +DECL_CONSTANT_STR("BUS_PINS_i2c2_PB13_PB14", "PB13,PB14"); +#ifdef I2C3 +DECL_ENUMERATION("i2c_bus", "i2c3_PB3_PB4", 5); DECL_CONSTANT_STR("BUS_PINS_i2c3_PB3_PB4", "PB3,PB4"); -#elif CONFIG_MACH_STM32L4 -#define GPIO_AF_INDEX 4 -DECL_ENUMERATION("i2c_bus", "i2c3_PA7_PB4", 2); -DECL_CONSTANT_STR("BUS_PINS_i2c3_PA7_PB4", "PA7,PB4"); #endif +#elif CONFIG_MACH_STM32L4 +DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); +DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); +DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 1); +DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); +DECL_ENUMERATION("i2c_bus", "i2c1_PA9_PA10", 2); +DECL_CONSTANT_STR("BUS_PINS_i2c1_PA9_PA10", "PA9,PA10"); DECL_ENUMERATION("i2c_bus", "i2c2_PB10_PB11", 3); DECL_CONSTANT_STR("BUS_PINS_i2c2_PB10_PB11", "PB10,PB11"); DECL_ENUMERATION("i2c_bus", "i2c2_PB13_PB14", 4); DECL_CONSTANT_STR("BUS_PINS_i2c2_PB13_PB14", "PB13,PB14"); -DECL_ENUMERATION("i2c_bus", "i2c1_PA9_PA10", 5); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PA9_PA10", "PA9,PA10"); +DECL_ENUMERATION("i2c_bus", "i2c3_PA7_PB4", 5); +DECL_CONSTANT_STR("BUS_PINS_i2c3_PA7_PB4", "PA7,PB4"); #elif CONFIG_MACH_STM32G4 DECL_ENUMERATION("i2c_bus", "i2c1_PA13_PA14", 0); DECL_CONSTANT_STR("BUS_PINS_i2c1_PA13_PA14", "PA13,PA14"); @@ -72,18 +79,22 @@ static const struct i2c_info i2c_bus[] = { { I2C1, GPIO('B', 6), GPIO('B', 7), GPIO_FUNCTION(1) }, { I2C1, GPIO('F', 1), GPIO('F', 0), GPIO_FUNCTION(1) }, { I2C1, GPIO('B', 8), GPIO('B', 9), GPIO_FUNCTION(1) }, - -#elif CONFIG_MACH_STM32G0 || CONFIG_MACH_STM32L4 - { I2C1, GPIO('B', 6), GPIO('B', 7), GPIO_FUNCTION(GPIO_AF_INDEX) }, - { I2C1, GPIO('B', 8), GPIO('B', 9), GPIO_FUNCTION(GPIO_AF_INDEX) }, -#if CONFIG_MACH_STM32G0 - { I2C3, GPIO('B', 3), GPIO('B', 4), GPIO_FUNCTION(GPIO_AF_INDEX) }, -#elif CONFIG_MACH_STM32L4 - { I2C3, GPIO('A', 7), GPIO('B', 4), GPIO_FUNCTION(GPIO_AF_INDEX) }, +#elif CONFIG_MACH_STM32G0 + { I2C1, GPIO('B', 6), GPIO('B', 7), GPIO_FUNCTION(6) }, + { I2C1, GPIO('B', 8), GPIO('B', 9), GPIO_FUNCTION(6) }, + { I2C1, GPIO('A', 9), GPIO('A', 10), GPIO_FUNCTION(6) }, + { I2C2, GPIO('B', 10), GPIO('B', 11), GPIO_FUNCTION(6) }, + { I2C2, GPIO('B', 13), GPIO('B', 14), GPIO_FUNCTION(6) }, +#ifdef I2C3 + { I2C3, GPIO('B', 3), GPIO('B', 4), GPIO_FUNCTION(6) }, #endif - { I2C2, GPIO('B', 10), GPIO('B', 11), GPIO_FUNCTION(GPIO_AF_INDEX) }, - { I2C2, GPIO('B', 13), GPIO('B', 14), GPIO_FUNCTION(GPIO_AF_INDEX) }, - { I2C1, GPIO('A', 9), GPIO('A', 10), GPIO_FUNCTION(GPIO_AF_INDEX) }, +#elif CONFIG_MACH_STM32L4 + { I2C1, GPIO('B', 6), GPIO('B', 7), GPIO_FUNCTION(4) }, + { I2C1, GPIO('B', 8), GPIO('B', 9), GPIO_FUNCTION(4) }, + { I2C1, GPIO('A', 9), GPIO('A', 10), GPIO_FUNCTION(4) }, + { I2C2, GPIO('B', 10), GPIO('B', 11), GPIO_FUNCTION(4) }, + { I2C2, GPIO('B', 13), GPIO('B', 14), GPIO_FUNCTION(4) }, + { I2C3, GPIO('A', 7), GPIO('B', 4), GPIO_FUNCTION(4) }, #elif CONFIG_MACH_STM32G4 { I2C1, GPIO('A', 13), GPIO('A', 14), GPIO_FUNCTION(4) }, { I2C1, GPIO('A', 15), GPIO('A', 14), GPIO_FUNCTION(4) }, diff --git a/src/stm32/stm32g0.c b/src/stm32/stm32g0.c index 41f7f6f2c1c9..b96d4a517fd1 100644 --- a/src/stm32/stm32g0.c +++ b/src/stm32/stm32g0.c @@ -36,14 +36,18 @@ lookup_clock_line(uint32_t periph_base) if ((periph_base == FDCAN1_BASE) || (periph_base == FDCAN2_BASE)) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<12}; #endif +#ifdef USB_BASE if (periph_base == USB_BASE) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<13}; +#endif #ifdef CRS_BASE if (periph_base == CRS_BASE) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<16}; #endif +#ifdef I2C3_BASE if (periph_base == I2C3_BASE) return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<23}; +#endif if (periph_base == TIM1_BASE) return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<11}; if (periph_base == SPI1_BASE) @@ -106,8 +110,11 @@ clock_setup(void) } pllcfgr |= (pll_freq/pll_base) << RCC_PLLCFGR_PLLN_Pos; pllcfgr |= (pll_freq/CONFIG_CLOCK_FREQ - 1) << RCC_PLLCFGR_PLLR_Pos; - pllcfgr |= (pll_freq/FREQ_USB - 1) << RCC_PLLCFGR_PLLQ_Pos; - RCC->PLLCFGR = pllcfgr | RCC_PLLCFGR_PLLREN | RCC_PLLCFGR_PLLQEN; +#ifdef RCC_PLLCFGR_PLLQ + pllcfgr |= ((pll_freq/FREQ_USB - 1) << RCC_PLLCFGR_PLLQ_Pos) + | RCC_PLLCFGR_PLLQEN; +#endif + RCC->PLLCFGR = pllcfgr | RCC_PLLCFGR_PLLREN; RCC->CR |= RCC_CR_PLLON; // Wait for PLL lock @@ -119,8 +126,10 @@ clock_setup(void) while ((RCC->CFGR & RCC_CFGR_SWS_Msk) != (2 << RCC_CFGR_SWS_Pos)) ; +#ifdef USB_BASE // Use PLLQCLK for USB (setting USBSEL=2 works in practice) RCC->CCIPR2 = 2 << RCC_CCIPR2_USBSEL_Pos; +#endif } From 448c1a1488d57b4587250355bb720859d1812a61 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 3 Jan 2023 12:52:35 -0500 Subject: [PATCH 35/40] stm32: Reindent ifdefs in stm32f0_i2c.c A whitespace and comment change only - no functional changes. Signed-off-by: Kevin O'Connor --- src/stm32/stm32f0_i2c.c | 111 ++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/src/stm32/stm32f0_i2c.c b/src/stm32/stm32f0_i2c.c index 9e8994fc475c..a37306e8c3d8 100644 --- a/src/stm32/stm32f0_i2c.c +++ b/src/stm32/stm32f0_i2c.c @@ -16,62 +16,62 @@ struct i2c_info { }; #if CONFIG_MACH_STM32F0 -DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); -DECL_ENUMERATION("i2c_bus", "i2c1_PF1_PF0", 1); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PF1_PF0", "PF1,PF0"); -DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 2); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); -// Deprecated "i2c1a" style mappings -DECL_ENUMERATION("i2c_bus", "i2c1", 0); -DECL_CONSTANT_STR("BUS_PINS_i2c1", "PB6,PB7"); -DECL_ENUMERATION("i2c_bus", "i2c1a", 1); -DECL_CONSTANT_STR("BUS_PINS_i2c1a", "PF1,PF0"); + DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); + DECL_ENUMERATION("i2c_bus", "i2c1_PF1_PF0", 1); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PF1_PF0", "PF1,PF0"); + DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 2); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); + // Deprecated "i2c1a" style mappings + DECL_ENUMERATION("i2c_bus", "i2c1", 0); + DECL_CONSTANT_STR("BUS_PINS_i2c1", "PB6,PB7"); + DECL_ENUMERATION("i2c_bus", "i2c1a", 1); + DECL_CONSTANT_STR("BUS_PINS_i2c1a", "PF1,PF0"); #elif CONFIG_MACH_STM32G0 -DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); -DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 1); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); -DECL_ENUMERATION("i2c_bus", "i2c1_PA9_PA10", 2); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PA9_PA10", "PA9,PA10"); -DECL_ENUMERATION("i2c_bus", "i2c2_PB10_PB11", 3); -DECL_CONSTANT_STR("BUS_PINS_i2c2_PB10_PB11", "PB10,PB11"); -DECL_ENUMERATION("i2c_bus", "i2c2_PB13_PB14", 4); -DECL_CONSTANT_STR("BUS_PINS_i2c2_PB13_PB14", "PB13,PB14"); -#ifdef I2C3 -DECL_ENUMERATION("i2c_bus", "i2c3_PB3_PB4", 5); -DECL_CONSTANT_STR("BUS_PINS_i2c3_PB3_PB4", "PB3,PB4"); -#endif + DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); + DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 1); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); + DECL_ENUMERATION("i2c_bus", "i2c1_PA9_PA10", 2); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PA9_PA10", "PA9,PA10"); + DECL_ENUMERATION("i2c_bus", "i2c2_PB10_PB11", 3); + DECL_CONSTANT_STR("BUS_PINS_i2c2_PB10_PB11", "PB10,PB11"); + DECL_ENUMERATION("i2c_bus", "i2c2_PB13_PB14", 4); + DECL_CONSTANT_STR("BUS_PINS_i2c2_PB13_PB14", "PB13,PB14"); + #ifdef I2C3 + DECL_ENUMERATION("i2c_bus", "i2c3_PB3_PB4", 5); + DECL_CONSTANT_STR("BUS_PINS_i2c3_PB3_PB4", "PB3,PB4"); + #endif #elif CONFIG_MACH_STM32L4 -DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); -DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 1); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); -DECL_ENUMERATION("i2c_bus", "i2c1_PA9_PA10", 2); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PA9_PA10", "PA9,PA10"); -DECL_ENUMERATION("i2c_bus", "i2c2_PB10_PB11", 3); -DECL_CONSTANT_STR("BUS_PINS_i2c2_PB10_PB11", "PB10,PB11"); -DECL_ENUMERATION("i2c_bus", "i2c2_PB13_PB14", 4); -DECL_CONSTANT_STR("BUS_PINS_i2c2_PB13_PB14", "PB13,PB14"); -DECL_ENUMERATION("i2c_bus", "i2c3_PA7_PB4", 5); -DECL_CONSTANT_STR("BUS_PINS_i2c3_PA7_PB4", "PA7,PB4"); + DECL_ENUMERATION("i2c_bus", "i2c1_PB6_PB7", 0); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB6_PB7", "PB6,PB7"); + DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 1); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); + DECL_ENUMERATION("i2c_bus", "i2c1_PA9_PA10", 2); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PA9_PA10", "PA9,PA10"); + DECL_ENUMERATION("i2c_bus", "i2c2_PB10_PB11", 3); + DECL_CONSTANT_STR("BUS_PINS_i2c2_PB10_PB11", "PB10,PB11"); + DECL_ENUMERATION("i2c_bus", "i2c2_PB13_PB14", 4); + DECL_CONSTANT_STR("BUS_PINS_i2c2_PB13_PB14", "PB13,PB14"); + DECL_ENUMERATION("i2c_bus", "i2c3_PA7_PB4", 5); + DECL_CONSTANT_STR("BUS_PINS_i2c3_PA7_PB4", "PA7,PB4"); #elif CONFIG_MACH_STM32G4 -DECL_ENUMERATION("i2c_bus", "i2c1_PA13_PA14", 0); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PA13_PA14", "PA13,PA14"); -DECL_ENUMERATION("i2c_bus", "i2c1_PA15_PA14", 1); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PA15_PA14", "PA15,PA14"); -DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB7", 2); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB7", "PB8,PB7"); -DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 3); -DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); -DECL_ENUMERATION("i2c_bus", "i2c2_PA9_PA8", 4); -DECL_CONSTANT_STR("BUS_PINS_i2c2_PA9_PA8", "PA9,PA8"); -DECL_ENUMERATION("i2c_bus", "i2c2_PC4_PF0", 5); -DECL_CONSTANT_STR("BUS_PINS_i2c2_PC4_PF0", "PC4,PF0"); -DECL_ENUMERATION("i2c_bus", "i2c3_PC8_PC9", 6); -DECL_CONSTANT_STR("BUS_PINS_i2c3_PC8_PC9", "PC8,PC9"); -DECL_ENUMERATION("i2c_bus", "i2c3_PC8_PC11", 7); -DECL_CONSTANT_STR("BUS_PINS_i2c3_PC8_PC11", "PC8,PC11"); + DECL_ENUMERATION("i2c_bus", "i2c1_PA13_PA14", 0); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PA13_PA14", "PA13,PA14"); + DECL_ENUMERATION("i2c_bus", "i2c1_PA15_PA14", 1); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PA15_PA14", "PA15,PA14"); + DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB7", 2); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB7", "PB8,PB7"); + DECL_ENUMERATION("i2c_bus", "i2c1_PB8_PB9", 3); + DECL_CONSTANT_STR("BUS_PINS_i2c1_PB8_PB9", "PB8,PB9"); + DECL_ENUMERATION("i2c_bus", "i2c2_PA9_PA8", 4); + DECL_CONSTANT_STR("BUS_PINS_i2c2_PA9_PA8", "PA9,PA8"); + DECL_ENUMERATION("i2c_bus", "i2c2_PC4_PF0", 5); + DECL_CONSTANT_STR("BUS_PINS_i2c2_PC4_PF0", "PC4,PF0"); + DECL_ENUMERATION("i2c_bus", "i2c3_PC8_PC9", 6); + DECL_CONSTANT_STR("BUS_PINS_i2c3_PC8_PC9", "PC8,PC9"); + DECL_ENUMERATION("i2c_bus", "i2c3_PC8_PC11", 7); + DECL_CONSTANT_STR("BUS_PINS_i2c3_PC8_PC11", "PC8,PC11"); #endif static const struct i2c_info i2c_bus[] = { @@ -85,9 +85,9 @@ static const struct i2c_info i2c_bus[] = { { I2C1, GPIO('A', 9), GPIO('A', 10), GPIO_FUNCTION(6) }, { I2C2, GPIO('B', 10), GPIO('B', 11), GPIO_FUNCTION(6) }, { I2C2, GPIO('B', 13), GPIO('B', 14), GPIO_FUNCTION(6) }, -#ifdef I2C3 + #ifdef I2C3 { I2C3, GPIO('B', 3), GPIO('B', 4), GPIO_FUNCTION(6) }, -#endif + #endif #elif CONFIG_MACH_STM32L4 { I2C1, GPIO('B', 6), GPIO('B', 7), GPIO_FUNCTION(4) }, { I2C1, GPIO('B', 8), GPIO('B', 9), GPIO_FUNCTION(4) }, @@ -104,7 +104,6 @@ static const struct i2c_info i2c_bus[] = { { I2C2, GPIO('C', 4), GPIO('F', 0), GPIO_FUNCTION(4) }, { I2C3, GPIO('C', 8), GPIO('C', 9), GPIO_FUNCTION(8) }, { I2C3, GPIO('C', 8), GPIO('C', 11), GPIO_FUNCTION(8) }, -// { I2C3, GPIO('A', 8), GPIO('B', 5), GPIO_FUNCTION(4) }, #endif }; From 3cd8a72e60f8d42b7defe70248e5754c089a6be9 Mon Sep 17 00:00:00 2001 From: JamesH1978 <87171443+JamesH1978@users.noreply.github.com> Date: Wed, 4 Jan 2023 17:01:28 +0000 Subject: [PATCH 36/40] spi_flash: Add SKR2 F429 chip variant to spi_flash (#5956) Later addition of a F429 variant SKR2 was released. Changed btt-skr2 to btt-skr-2-f407 and added a new alias for btt-skr-2-f429 Signed-off-by: James Hartley --- docs/Config_Changes.md | 4 ++++ scripts/spi_flash/board_defs.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index 75b4d0b13f43..54af4b8b6901 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -7,6 +7,10 @@ document when upgrading the Klipper software. All dates in this document are approximate. ## Changes +20230103: It is now possible with the flash-sdcard.sh script to flash +both variants of the Bigtreetech SKR-2, STM32F407 and STM32F429. +This means that the original tag of btt-skr2 now has changed to either +btt-skr-2-f407 or btt-skr-2-f429. 20221122: Previously, with safe_z_home, it was possible that the z_hop after the g28 homing would go in the negative z direction. diff --git a/scripts/spi_flash/board_defs.py b/scripts/spi_flash/board_defs.py index e136c7d97923..e95816afa02e 100644 --- a/scripts/spi_flash/board_defs.py +++ b/scripts/spi_flash/board_defs.py @@ -144,7 +144,8 @@ 'btt-skr-e3-dip': BOARD_DEFS['btt-skr-mini'], 'btt002-v1': BOARD_DEFS['btt-skr-mini'], 'creality-v4.2.7': BOARD_DEFS['creality-v4.2.2'], - 'btt-skr-2': BOARD_DEFS['btt-octopus-f407-v1'], + 'btt-skr-2-f407': BOARD_DEFS['btt-octopus-f407-v1'], + 'btt-skr-2-f429': BOARD_DEFS['btt-octopus-f429-v1'], 'btt-octopus-f407-v1.0': BOARD_DEFS['btt-octopus-f407-v1'], 'btt-octopus-f407-v1.1': BOARD_DEFS['btt-octopus-f407-v1'], 'btt-octopus-f429-v1.0': BOARD_DEFS['btt-octopus-f429-v1'], From cbc17a7cb6569ea39621404456e55c4b6ce01189 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 4 Jan 2023 12:04:45 -0500 Subject: [PATCH 37/40] docs: Note v0.11.0 release in Config_Changes.md Signed-off-by: Kevin O'Connor --- docs/Config_Changes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index 54af4b8b6901..c22ed1fa1c7c 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -7,11 +7,14 @@ document when upgrading the Klipper software. All dates in this document are approximate. ## Changes + 20230103: It is now possible with the flash-sdcard.sh script to flash both variants of the Bigtreetech SKR-2, STM32F407 and STM32F429. This means that the original tag of btt-skr2 now has changed to either btt-skr-2-f407 or btt-skr-2-f429. +20221128: Klipper v0.11.0 released. + 20221122: Previously, with safe_z_home, it was possible that the z_hop after the g28 homing would go in the negative z direction. Now, a z_hop is performed after g28 only if it results in a positive From a564824009cd63c12000198676ad8abaaa9c4efe Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 5 Jan 2023 03:09:43 -0500 Subject: [PATCH 38/40] serialqueue: Add comment to do_write() Signed-off-by: Kevin O'Connor --- klippy/chelper/serialqueue.c | 1 + 1 file changed, 1 insertion(+) diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index 75d39d2124bc..684710c1d8cd 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -356,6 +356,7 @@ kick_event(struct serialqueue *sq, double eventtime) pollreactor_update_timer(sq->pr, SQPT_COMMAND, PR_NOW); } +// OS write of data to be sent to the mcu static void do_write(struct serialqueue *sq, void *buf, int buflen) { From 4395ae96a73edcbcea24dd1dd0475f65f3fde80a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 4 Jan 2023 23:02:59 -0500 Subject: [PATCH 39/40] serialhdl: Add a get_serialqueue() method Signed-off-by: Kevin O'Connor --- klippy/mcu.py | 4 ++-- klippy/serialhdl.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 4aaf626943cc..ce1fee4c5c46 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -71,7 +71,7 @@ def _build_config(self): "trsync_state oid=%c can_trigger=%c trigger_reason=%c clock=%u") ffi_main, ffi_lib = chelper.get_ffi() self._trdispatch_mcu = ffi_main.gc(ffi_lib.trdispatch_mcu_alloc( - self._trdispatch, mcu._serial.serialqueue, # XXX + self._trdispatch, mcu._serial.get_serialqueue(), # XXX self._cmd_queue, self._oid, set_timeout_tag, trigger_tag, state_tag), ffi_lib.free) def _shutdown(self): @@ -746,7 +746,7 @@ def _connect(self): raise error("Too few moves available on MCU '%s'" % (self._name,)) ffi_main, ffi_lib = chelper.get_ffi() self._steppersync = ffi_main.gc( - ffi_lib.steppersync_alloc(self._serial.serialqueue, + ffi_lib.steppersync_alloc(self._serial.get_serialqueue(), self._stepqueues, len(self._stepqueues), move_count-self._reserved_move_slots), ffi_lib.steppersync_free) diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index 15d1cc21d727..0285799385fb 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -226,6 +226,8 @@ def get_reactor(self): return self.reactor def get_msgparser(self): return self.msgparser + def get_serialqueue(self): + return self.serialqueue def get_default_command_queue(self): return self.default_cmd_queue # Serial response callbacks From 01f90e8f28b5dccf803f92e9516fdc634083d1a1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 7 Jan 2023 11:53:09 -0500 Subject: [PATCH 40/40] console: No need to import pins module The pins module is no longer used in console.py. Signed-off-by: Kevin O'Connor --- klippy/console.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/klippy/console.py b/klippy/console.py index da32e18b034f..0a20e09e357b 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -5,7 +5,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import sys, optparse, os, re, logging -import util, reactor, serialhdl, pins, msgproto, clocksync +import util, reactor, serialhdl, msgproto, clocksync help_txt = """ This is a debugging console for the Klipper micro-controller. @@ -43,7 +43,6 @@ def __init__(self, reactor, serialport, baud, canbus_iface, canbus_nodeid): self.fd = sys.stdin.fileno() util.set_nonblock(self.fd) self.mcu_freq = 0 - self.pins = pins.PinResolver(validate_aliases=False) self.data = "" reactor.register_fd(self.fd, self.process_kbd) reactor.register_callback(self.connect) @@ -223,11 +222,7 @@ def translate(self, line, eventtime): return None line = ''.join(evalparts) self.output("Eval: %s" % (line,)) - try: - line = self.pins.update_command(line).strip() - except: - self.output("Unable to map pin: %s" % (line,)) - return None + line = line.strip() if line: parts = line.split() if parts[0] in self.local_commands: