From c55675f8a7e82ba4deaf8bb7f69d2dd7958d11fc Mon Sep 17 00:00:00 2001 From: Elias Bakken Date: Mon, 30 Oct 2023 22:34:16 +0100 Subject: [PATCH] Enhancement/add support for 32 kb mcu (#390) * Compile both 16 KB and 32 KB versions of the klipper binaries * Clean before compiling again. Clean folder to reset sed command * Use patch to add features --- roles/install_klipper/files/enable-i2c.patch | 43 +++++++++++++++++++ roles/install_klipper/files/flash-stm32 | 3 ++ .../files/stm32f031-32KB-serial.config | 10 +++++ roles/install_klipper/tasks/recore.yml | 43 +++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 roles/install_klipper/files/enable-i2c.patch create mode 100644 roles/install_klipper/files/stm32f031-32KB-serial.config diff --git a/roles/install_klipper/files/enable-i2c.patch b/roles/install_klipper/files/enable-i2c.patch new file mode 100644 index 00000000..1cdc5429 --- /dev/null +++ b/roles/install_klipper/files/enable-i2c.patch @@ -0,0 +1,43 @@ +diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig +index e3961176..66363170 100644 +--- a/src/stm32/Kconfig ++++ b/src/stm32/Kconfig +@@ -7,7 +7,7 @@ config STM32_SELECT + default y + select HAVE_GPIO + select HAVE_GPIO_ADC +- select HAVE_GPIO_I2C if !MACH_STM32F031 ++ select HAVE_GPIO_I2C + select HAVE_GPIO_SPI if !MACH_STM32F031 + select HAVE_GPIO_SDIO if MACH_STM32F4 + select HAVE_GPIO_HARD_PWM if MACH_STM32F1 || MACH_STM32F4 || MACH_STM32F7 || MACH_STM32G0 || MACH_STM32H7 +@@ -206,7 +206,7 @@ config CLOCK_FREQ + + config FLASH_SIZE + hex +- default 0x4000 if MACH_STM32F031 ++ default 0x8000 if MACH_STM32F031 + default 0x8000 if MACH_STM32F042 + default 0x20000 if MACH_STM32F070 || MACH_STM32F072 + default 0x10000 if MACH_STM32F103 || MACH_STM32L412 # Flash size of stm32f103x8 (64KiB) +diff --git a/src/stm32/stm32f0_i2c.c b/src/stm32/stm32f0_i2c.c +index e9cadccb..0157bd32 100644 +--- a/src/stm32/stm32f0_i2c.c ++++ b/src/stm32/stm32f0_i2c.c +@@ -22,6 +22,8 @@ struct i2c_info { + 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"); ++ DECL_ENUMERATION("i2c_bus", "i2c1_PB7_PB8", 3); ++ DECL_CONSTANT_STR("BUS_PINS_i2c1_PB7_PB8", "PB7,PB8"); + // Deprecated "i2c1a" style mappings + DECL_ENUMERATION("i2c_bus", "i2c1", 0); + DECL_CONSTANT_STR("BUS_PINS_i2c1", "PB6,PB7"); +@@ -89,6 +91,7 @@ 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) }, ++ { I2C1, GPIO('B', 7), GPIO('B', 8), GPIO_FUNCTION(1) }, + #elif CONFIG_MACH_STM32F7 + { I2C1, GPIO('B', 6), GPIO('B', 7), GPIO_FUNCTION(1) }, + #elif CONFIG_MACH_STM32G0 diff --git a/roles/install_klipper/files/flash-stm32 b/roles/install_klipper/files/flash-stm32 index 0b93c256..8c21b2bc 100644 --- a/roles/install_klipper/files/flash-stm32 +++ b/roles/install_klipper/files/flash-stm32 @@ -17,6 +17,9 @@ REVISION=`cat "$CONFIG" | jq -r ".Revision" | tr '[:upper:]' '[:lower:]'` FLASH_DEVICE=/dev/ttyS2 STM32_BINARY=/opt/firmware/stm32.bin +if [ "$REVISION" == "a7" ] ; then + STM32_BINARY=/opt/firmware/stm32-32KB.bin +fi systemctl stop klipper diff --git a/roles/install_klipper/files/stm32f031-32KB-serial.config b/roles/install_klipper/files/stm32f031-32KB-serial.config new file mode 100644 index 00000000..78414502 --- /dev/null +++ b/roles/install_klipper/files/stm32f031-32KB-serial.config @@ -0,0 +1,10 @@ +# Base config file for STM32F031 boards with serial on PA14/PA15 +CONFIG_MACH_STM32=y +CONFIG_MACH_STM32F031=y +CONFIG_SERIAL=y +CONFIG_STM32_FLASH_START_0000=y +CONFIG_STM32_SERIAL_USART2_ALT_PA15_PA14=y +CONFIG_STM32_CLOCK_REF_INTERNAL=y +CONFIG_LOW_LEVEL_OPTIONS=y +CONFIG_WANT_GPIO_BITBANGING=y +CONFIG_WANT_DISPLAYS=n diff --git a/roles/install_klipper/tasks/recore.yml b/roles/install_klipper/tasks/recore.yml index 2560ce12..b91b7067 100644 --- a/roles/install_klipper/tasks/recore.yml +++ b/roles/install_klipper/tasks/recore.yml @@ -189,6 +189,49 @@ remote_src: yes force: no +- name: Recore - Copy patch + copy: + src: "{{ role_path }}/files/enable-i2c.patch" + dest: "{{ klipper_home }}" + owner: debian + group: debian + +- name: Recore - Increase flash size and add i2c + shell: | + patch -p1 < enable-i2c.patch + args: + chdir: "{{ klipper_home }}" + +- name: Recore - Copy STM32 config with 32 KB flash + copy: + src: "{{ role_path }}/files/stm32f031-32KB-serial.config" + dest: "{{ klipper_home }}/.config" + owner: debian + group: debian + +- name: Recore - Compile STM32 binary with 32 KB flash + shell: | + make clean + make olddefconfig + make -j + args: + chdir: "{{ klipper_home }}" + +- name: Recore - Copy STM32 binary with 32 KB flash + copy: + src: "{{ klipper_home }}/out/klipper.bin" + dest: /opt/firmware/stm32-32KB.bin + owner: debian + group: debian + remote_src: yes + force: no + +- name: Recore - reset folder + shell: | + git reset --hard + args: + chdir: "{{ klipper_home }}" + - name: Recore - Install stm32 flasher script copy: src: "{{ role_path }}/files/flash-stm32"