From 15853da28c32543e40dd571a49fb7a819adbfc4f Mon Sep 17 00:00:00 2001 From: Cabia Rangris Date: Sun, 30 Aug 2020 18:59:28 +0200 Subject: [PATCH] config: Added TronXY X5SA support (#3265) Added printer-tronxy-x5sa-v6 config. Added "chitu" bootloader option to stm32 Kconfig. Added chitu_crypt. Signed-off-by: Vladimir Serov --- config/printer-tronxy-x5sa-v6-2019.cfg | 140 +++++++++++++++++++++++++ scripts/chitu_crypt.py | 130 +++++++++++++++++++++++ src/stm32/Kconfig | 3 + 3 files changed, 273 insertions(+) create mode 100644 config/printer-tronxy-x5sa-v6-2019.cfg create mode 100755 scripts/chitu_crypt.py diff --git a/config/printer-tronxy-x5sa-v6-2019.cfg b/config/printer-tronxy-x5sa-v6-2019.cfg new file mode 100644 index 00000000..698875ae --- /dev/null +++ b/config/printer-tronxy-x5sa-v6-2019.cfg @@ -0,0 +1,140 @@ +# This is a Klipper configuration for TronXY X5SA, with +# CXY-V6 motherboard. + + +# === FLASHING WITH STOCK BOOTLOADER === +# You should make firmware for STM32F103 with bootloader offset +# at 0x8008800 (Chitu v6 Bootloader). Uncheck USB, and leave default +# serial settings. +# +# Use "./chitu_crypt.py out/klipper.bin" to generate update.cbz. +# Put `update.cbz` onto SD card, and reboot the printer. +# It will be automatically installed, and you will be able to update it this way. + +[mcu] +serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 +restart_method: command + +[printer] +kinematics: corexy +max_velocity: 300 +max_accel: 7000 +max_accel_to_decel: 7000 +max_z_velocity: 25 +max_z_accel: 30 + +[stepper_x] +step_pin: PE5 +dir_pin: !PE6 +enable_pin: !PC13 +step_distance: .006275 +endstop_pin: !PG10 +position_endstop: -1 +position_min: -1 +position_max: 350 +homing_speed: 50 +homing_retract_dist: 10 +second_homing_speed: 10.0 + +[stepper_y] +step_pin: PE2 +dir_pin: !PE3 +enable_pin: !PE4 +step_distance: .006275 +endstop_pin: !PA12 +position_endstop: 0 +position_max: 330 +homing_retract_dist: 10 +homing_speed: 50.0 +second_homing_speed: 10.0 + +[stepper_z] +step_pin: PB9 +dir_pin: PE0 +enable_pin: !PE1 +step_distance: .00125 +endstop_pin: probe:z_virtual_endstop +position_max: 400 +position_min: -2 + +[extruder] +step_pin: PB4 +dir_pin: PB5 +enable_pin: !PB8 +step_distance: 0.0111 +nozzle_diameter: 0.400 +filament_diameter: 1.750 +heater_pin: PG12 +sensor_type: ATC Semitec 104GT-2 +sensor_pin: PA1 +control: pid +pid_Kp=18.831 +pid_Ki=0.821 +pid_Kd=108.044 +min_temp: 0 +max_temp: 250 +max_extrude_only_distance: 300 +pressure_advance: 0 + +[heater_bed] +heater_pin: PG11 +sensor_type: EPCOS 100K B57560G104F +sensor_pin: PA0 +control: pid +min_temp: 0 +max_temp: 130 +pid_Kp=73.932 +pid_Ki=1.521 +pid_Kd=898.279 + +[heater_fan hotend_fan] +pin: PG14 +heater: extruder +heater_temp: 50 +fan_speed: 0.5 + +[fan] +pin: PG13 +max_power: 0.5 + +[controller_fan drivers_fan] +pin: PD6 + +[filament_switch_sensor sentinel] +pause_on_runout: True +runout_gcode: + M25 +switch_pin: PA15 + +[output_pin beeper] +pin: PB0 + +[safe_z_home] +home_xy_position: 165,165 +speed: 50 +z_hop: 10 +z_hop_speed: 5 + +[bed_screws] +screw1: 5,5 +screw2: 165,5 +screw3: 325,5 +screw4: 5,325 +screw5: 165,325 +screw6: 325,325 + +[bed_mesh] +speed: 120 +probe_count: 5,5 +horizontal_move_z: 5 +algorithm: lagrange +mesh_min : 20,20 +mesh_max : 310,310 +mesh_pps: 0 + +[probe] +x_offset: -40 +y_offset: 0 +pin: !PG9 +speed: 30 +z_offset: 2 diff --git a/scripts/chitu_crypt.py b/scripts/chitu_crypt.py new file mode 100755 index 00000000..080b9f47 --- /dev/null +++ b/scripts/chitu_crypt.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python2 +# Encrypts STM32 firmwares to be flashable from SD card by Chitu motherboards. +# Relocate firmware to 0x08008800! + +# Copied from Marlin and modified. +# Licensed under GPL-3.0 + +import os +import random +import struct +import uuid +import sys + +def calculate_crc(contents, seed): + accumulating_xor_value = seed; + + for i in range(0, len(contents), 4): + value = struct.unpack('> ip + + # load a byte into IP + ip = r0[loop_counter] + + # XOR the seed with r7 + xor_seed = xor_seed ^ r7 + + # and then with IP + xor_seed = xor_seed ^ ip + + #Now store the byte back + r1[loop_counter] = xor_seed & 0xFF + + #increment the loop_counter + loop_counter = loop_counter + 1 + + +def encrypt_file(input, output_file, file_length): + input_file = bytearray(input.read()) + block_size = 0x800 + key_length = 0x18 + + uid_value = uuid.uuid4() + file_key = int(uid_value.hex[0:8], 16) + + xor_crc = 0xef3d4323; + + # the input file is exepcted to be in chunks of 0x800 + # so round the size + while len(input_file) % block_size != 0: + input_file.extend(b'0x0') + + # write the file header + output_file.write(struct.pack(">I", 0x443D2D3F)) + # encrypt the contents using a known file header key + + # write the file_key + output_file.write(struct.pack("