Compare commits
43
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6a75ed910 | ||
|
|
ce4bf91f71 | ||
|
|
ef7f0efb62 | ||
|
|
b1f597c550 | ||
|
|
ecc9bbf52a | ||
|
|
5edc7fee7e | ||
|
|
7eabf02f5b | ||
|
|
83ef0e135e | ||
|
|
447125faae | ||
|
|
043f18da26 | ||
|
|
615db729e7 | ||
|
|
6adff3954b | ||
|
|
78ae83c314 | ||
|
|
5b204866c5 | ||
|
|
472fd32cab | ||
|
|
90427fe30e | ||
|
|
bdeec0f56d | ||
|
|
83eecae028 | ||
|
|
cd8d57c2c6 | ||
|
|
b1361d9e5b | ||
|
|
01ac5334e9 | ||
|
|
1e3ace2170 | ||
|
|
aa726cb7cb | ||
|
|
7bd32994d4 | ||
|
|
a4cd0336bd | ||
|
|
21b7842979 | ||
|
|
e9bf2d4c5c | ||
|
|
8ef0f7d7e3 | ||
|
|
2acfa28294 | ||
|
|
8f178b892a | ||
|
|
5f58fe7484 | ||
|
|
5f990f93d5 | ||
|
|
073665cebb | ||
|
|
ec1dcf3bd2 | ||
|
|
c9aa7ac871 | ||
|
|
01ed8096d8 | ||
|
|
261efdd86c | ||
|
|
4292136b16 | ||
|
|
15c3824e9b | ||
|
|
dd368c107c | ||
|
|
07792a02b4 | ||
|
|
aa8ba30f8a | ||
|
|
594c024355 |
No files matched your search
@@ -6,10 +6,10 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ci_cache
|
||||
key: ${{ runner.os }}-build-${{ hashFiles('scripts/ci-install.sh') }}
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
run: ./scripts/ci-build.sh 2>&1
|
||||
|
||||
- name: Upload micro-controller data dictionaries
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: data-dict
|
||||
path: ci_build/dict
|
||||
@@ -12,12 +12,12 @@ jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup python
|
||||
uses: actions/setup-python@v2
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.8'
|
||||
- uses: actions/cache@v2
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('docs/_klipper3d/mkdocs-requirements.txt') }}
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
- name: Build MkDocs Pages
|
||||
run: docs/_klipper3d/build-translations.sh
|
||||
- name: Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@v4.2.5
|
||||
uses: JamesIves/github-pages-deploy-action@v4.4.3
|
||||
with:
|
||||
branch: gh-pages # The branch the action should deploy to.
|
||||
folder: site # The folder the action should deploy.
|
||||
@@ -9,7 +9,7 @@ jobs:
|
||||
if: github.repository == 'Klipper3d/klipper'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v8
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: |
|
||||
@@ -31,6 +31,8 @@ jobs:
|
||||
exempt-issue-labels: 'enhancement,bug'
|
||||
days-before-stale: 35
|
||||
days-before-close: 7
|
||||
days-before-pr-stale: -1
|
||||
days-before-pr-close: -1
|
||||
# Close tickets marked with "not on github" label
|
||||
close_not_on_github:
|
||||
if: github.repository == 'Klipper3d/klipper'
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
# This file contains common pin mappings for MKS Monster8
|
||||
# boards. To use this config, the firmware should be compiled for the
|
||||
# stm32f407. When running "make menuconfig", select the 48KiB
|
||||
# bootloader, and enable "USB for communication".
|
||||
|
||||
# The "make flash" command does not work on the MKS Monster8. Instead,
|
||||
# after running "make", copy the generated "out/klipper.bin" file to a
|
||||
# file named "mks_monster8.bin" on an SD card or Udisk and then restart the
|
||||
# MKS Monster8 with that SD card or Udisk.
|
||||
|
||||
# See docs/Config_Reference.md for a description of parameters.
|
||||
|
||||
[stepper_x]
|
||||
step_pin: PC14
|
||||
dir_pin: PC13
|
||||
enable_pin: !PC15
|
||||
microsteps: 16
|
||||
rotation_distance: 40
|
||||
endstop_pin: !PA14 # PA13 for X-max; endstop have'!' is NO
|
||||
position_endstop: 0
|
||||
position_max: 200
|
||||
homing_speed: 50
|
||||
|
||||
[stepper_y]
|
||||
step_pin: PE5
|
||||
dir_pin: !PE4
|
||||
enable_pin: !PC15
|
||||
microsteps: 16
|
||||
rotation_distance: 40
|
||||
endstop_pin: !PA15 # PC5 for Y-max; endstop have'!' is NO
|
||||
position_endstop: 0
|
||||
position_max: 200
|
||||
homing_speed: 50
|
||||
|
||||
[stepper_z]
|
||||
step_pin: PE1
|
||||
dir_pin: PE0
|
||||
enable_pin: !PE2
|
||||
microsteps: 16
|
||||
rotation_distance: 8
|
||||
endstop_pin: !PB13 # PB12 for Z-max; endstop have'!' is NO
|
||||
position_endstop: 0
|
||||
position_max: 220
|
||||
|
||||
[extruder]
|
||||
step_pin: PB5
|
||||
dir_pin: !PB4
|
||||
enable_pin: !PB6
|
||||
microsteps: 16
|
||||
rotation_distance: 33.500
|
||||
nozzle_diameter: 0.400
|
||||
filament_diameter: 1.750
|
||||
heater_pin: PB1
|
||||
sensor_type: EPCOS 100K B57560G104F
|
||||
sensor_pin: PC1
|
||||
control: pid
|
||||
pid_Kp: 22
|
||||
pid_Ki: 1.08
|
||||
pid_Kd: 114
|
||||
min_temp: 0
|
||||
max_temp: 260
|
||||
|
||||
#[extruder1]
|
||||
#step_pin: PD6
|
||||
#dir_pin: !PD5
|
||||
#enable_pin: !PD7
|
||||
#heater_pin: PB0
|
||||
#sensor_pin: PC2
|
||||
|
||||
#[extruder2]
|
||||
#step_pin: PD2
|
||||
#dir_pin: !PD1
|
||||
#enable_pin: !PD3
|
||||
#heater_pin: PA3
|
||||
#sensor_pin: PC3
|
||||
|
||||
#[extruder3]
|
||||
#step_pin: PC7
|
||||
#dir_pin: PC6
|
||||
#enable_pin: !PC8
|
||||
|
||||
#[extruder4]
|
||||
#step_pin: PD13
|
||||
#dir_pin: !PD12
|
||||
#enable_pin: !PD14
|
||||
|
||||
[heater_bed]
|
||||
heater_pin: PB10
|
||||
sensor_type: NTC 100K MGB18-104F39050L32
|
||||
sensor_pin: PC0
|
||||
max_power: 1.0
|
||||
control: pid
|
||||
pid_kp: 71.039
|
||||
pid_ki: 2.223
|
||||
pid_kd: 567.421
|
||||
min_temp: 0
|
||||
max_temp: 200
|
||||
|
||||
#fan for printed model FAN0
|
||||
[fan]
|
||||
pin: PA2
|
||||
|
||||
#fan for hotend FAN1
|
||||
#[heater_fan my_nozzle_fan]
|
||||
[heater_fan fan1]
|
||||
pin: PA1
|
||||
shutdown_speed: 1
|
||||
|
||||
#fan for control board FAN2
|
||||
#[heater_fan my_control_fan]
|
||||
[heater_fan fan2]
|
||||
pin: PA0
|
||||
shutdown_speed: 1
|
||||
|
||||
[mcu]
|
||||
serial: /dev/serial/by-id/usb-Klipper_stm32f407xx_4D0045001850314335393520-if00
|
||||
|
||||
[printer]
|
||||
kinematics: cartesian
|
||||
max_velocity: 10000
|
||||
max_accel: 20000
|
||||
max_z_velocity: 100
|
||||
max_z_accel: 1000
|
||||
|
||||
#####################################################################
|
||||
# LED Control
|
||||
#####################################################################
|
||||
|
||||
#[output_pin caselight ](Use PA9)
|
||||
## Chamber Lighting - In 5V-RGB Position
|
||||
#pin: PA9
|
||||
#pwm: true
|
||||
#shutdown_value: 0
|
||||
#value:100
|
||||
#cycle_time: 0.01
|
||||
|
||||
########################################
|
||||
# TMC UART configuration
|
||||
########################################
|
||||
|
||||
#[tmc2208 stepper_x]
|
||||
#uart_pin: PE6
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2208 stepper_y]
|
||||
#uart_pin: PE3
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2208 stepper_z]
|
||||
#uart_pin: PB7
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2208 extruder]
|
||||
#uart_pin: PB3
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#sense_resistor: 0.110
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2208 extruder1]
|
||||
#uart_pin: PD4
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2208 extruder2]
|
||||
#uart_pin: PD0
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2208 extruder3]
|
||||
#uart_pin: PD15
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2208 extruder4]
|
||||
#uart_pin: PD11
|
||||
#run_current: 0.8
|
||||
#hold_current: 0.5
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
########################################
|
||||
# TMC SPI configuration
|
||||
########################################
|
||||
|
||||
#[tmc2130 stepper_x]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PE6
|
||||
#diag1_pin: PA14
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2130 stepper_y]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PE3
|
||||
#diag1_pin: PA15
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2130 stepper_z]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PB7
|
||||
#diag1_pin: PB13
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2130 extruder]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PB3
|
||||
#diag1_pin: PA13
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2130 extruder1]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PD4
|
||||
#diag1_pin: PC5
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2130 extruder2]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PD0
|
||||
#diag1_pin: PB12
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2130 extruder3]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PD15
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
#[tmc2130 extruder4]
|
||||
#spi_bus: spi4
|
||||
#cs_pin: PD11
|
||||
#run_current: 0.800
|
||||
#hold_current: 0.500
|
||||
#stealthchop_threshold: 999999
|
||||
|
||||
########################################
|
||||
# EXP1 / EXP2 (display) pins
|
||||
########################################
|
||||
|
||||
[board_pins]
|
||||
aliases:
|
||||
# EXP1 header
|
||||
EXP1_1=PB2, EXP1_3=PE11, EXP1_5=PD9, EXP1_7=PE15, EXP1_9=<GND>,
|
||||
EXP1_2=PE10, EXP1_4=PD10, EXP1_6=PD8, EXP1_8=PE7, EXP1_10=<5V>,
|
||||
# EXP2 header
|
||||
EXP2_1=PA6, EXP2_3=PE9, EXP2_5=PE8, EXP2_7=PB11, EXP2_9=<GND>,
|
||||
EXP2_2=PA5, EXP2_4=PA4, EXP2_6=PA7, EXP2_8=<RST>, EXP2_10=<3.3v>
|
||||
# Pins EXP2_1, EXP2_6, EXP2_2 are also MISO, MOSI, SCK of bus "ssp1"
|
||||
@@ -0,0 +1,154 @@
|
||||
# This file contains pin mappings for the Creality CR-10S Pro V2. To use
|
||||
# this config, the firmware should be compiled for the AVR atmega2560.
|
||||
|
||||
# See docs/Config_Reference.md for a description of parameters.
|
||||
|
||||
## General Config
|
||||
[mcu]
|
||||
serial: /dev/serial/by-id/<YOUR_USB_ID>
|
||||
|
||||
[printer]
|
||||
kinematics: cartesian
|
||||
max_velocity: 200
|
||||
max_accel: 1500
|
||||
max_z_velocity: 10
|
||||
max_z_accel: 100
|
||||
|
||||
## Stepper Motors and Extruder
|
||||
[stepper_x]
|
||||
step_pin: PF0 #ar54
|
||||
dir_pin: PF1 #ar55
|
||||
enable_pin: !PD7 #!ar38
|
||||
rotation_distance: 40
|
||||
microsteps: 16
|
||||
full_steps_per_rotation: 200
|
||||
endstop_pin: ^PE5 #^ar3
|
||||
position_endstop: 0
|
||||
position_min: 0
|
||||
position_max: 300
|
||||
homing_speed: 50
|
||||
homing_retract_dist: 5
|
||||
|
||||
[stepper_y]
|
||||
step_pin: PF6 #ar60
|
||||
dir_pin: !PF7 #ar61
|
||||
enable_pin: !PF2 #!ar56
|
||||
rotation_distance: 40
|
||||
microsteps: 16
|
||||
full_steps_per_rotation: 200
|
||||
endstop_pin: ^PJ1 #^ar14
|
||||
position_endstop: 0
|
||||
position_min: 0
|
||||
position_max: 310
|
||||
homing_speed: 50
|
||||
homing_retract_dist: 5
|
||||
|
||||
[stepper_z]
|
||||
step_pin: PL3 #ar46
|
||||
dir_pin: !PL1 #!ar48
|
||||
enable_pin: !PK0 #!ar62
|
||||
rotation_distance: 8
|
||||
microsteps: 16
|
||||
full_steps_per_rotation: 200
|
||||
endstop_pin: probe:z_virtual_endstop
|
||||
position_min: -3
|
||||
position_max: 363 # you can go higher but then the cables crimp
|
||||
|
||||
[extruder]
|
||||
step_pin: PA4 # ar26
|
||||
dir_pin: PA6 # !ar28
|
||||
enable_pin: !PA2 # !ar24
|
||||
rotation_distance: 22.900
|
||||
microsteps: 16
|
||||
full_steps_per_rotation: 200
|
||||
nozzle_diameter: 0.400
|
||||
filament_diameter: 1.750
|
||||
max_extrude_only_distance: 500.0
|
||||
max_extrude_only_velocity: 70.0
|
||||
max_extrude_only_accel: 1000.0
|
||||
heater_pin: PB4 #ar10
|
||||
sensor_type: EPCOS 100K B57560G104F
|
||||
sensor_pin: PK5 #analog13
|
||||
control: pid #calibrated in Klipper, you will need to run this for your machine
|
||||
pid_kp: 28.359
|
||||
pid_ki: 1.616
|
||||
pid_kd: 124.426
|
||||
min_extrude_temp: 170
|
||||
min_temp: 5
|
||||
max_temp: 275
|
||||
|
||||
[fan]
|
||||
pin: PH6 #ar9
|
||||
|
||||
[heater_bed]
|
||||
heater_pin: PH5 #ar8
|
||||
sensor_type: EPCOS 100K B57560G104F
|
||||
sensor_pin: PK6 #analog14
|
||||
control: pid #calibrated in Klipper, you will need to run this for your machine
|
||||
pid_kp: 70.936
|
||||
pid_ki: 1.151
|
||||
pid_kd: 1093.298
|
||||
min_temp: 5
|
||||
max_temp: 140
|
||||
|
||||
## BLTouch and Safe Z Settings
|
||||
[bltouch]
|
||||
sensor_pin: ^PD2
|
||||
control_pin: PB5
|
||||
stow_on_each_sample: False # Be careful
|
||||
probe_with_touch_mode: True
|
||||
x_offset: -27
|
||||
y_offset: -2
|
||||
z_offset: 2 # you will need to calibrate this in Klipper
|
||||
speed: 4.0
|
||||
samples: 2
|
||||
sample_retract_dist: 3.0
|
||||
|
||||
[safe_z_home]
|
||||
home_xy_position: 177,155
|
||||
speed: 80.0
|
||||
z_hop: 10.0
|
||||
z_hop_speed: 5.0
|
||||
|
||||
[bed_mesh]
|
||||
speed: 120
|
||||
horizontal_move_z: 5
|
||||
mesh_min: 5, 5
|
||||
mesh_max: 268, 305
|
||||
probe_count: 5,5
|
||||
fade_start: 1
|
||||
fade_end: 10
|
||||
|
||||
[filament_switch_sensor e0_sensor]
|
||||
switch_pin: PE4 #ar2
|
||||
pause_on_runout: False
|
||||
runout_gcode:
|
||||
PAUSE_PARK
|
||||
|
||||
## Calibrating the Bed
|
||||
# this is for the bltouch to calibrate the bed
|
||||
[screws_tilt_adjust]
|
||||
screw1: 40,40
|
||||
screw1_name: front left screw
|
||||
screw2: 295,40
|
||||
screw2_name: front right screw
|
||||
screw3: 295,280
|
||||
screw3_name: rear right screw
|
||||
screw4: 40,280
|
||||
screw4_name: rear left screw
|
||||
speed: 50
|
||||
horizontal_move_z: 10
|
||||
screw_thread: CW-M3
|
||||
|
||||
[bed_screws]
|
||||
screw1: 13,38
|
||||
screw1_name: front left screw
|
||||
screw2: 268,38
|
||||
screw2_name: front right screw
|
||||
screw3: 268,278
|
||||
screw3_name: rear right screw
|
||||
screw4: 13,38
|
||||
screw4_name: rear left screw
|
||||
horizontal_move_z: 5
|
||||
|
||||
[pause_resume]
|
||||
@@ -0,0 +1,95 @@
|
||||
# This file contains pin mappings for the Creality Ender2 Pro
|
||||
# with the HC32F460. The board is CR-FDM-v2.5.S4.170
|
||||
# To use this config, during "make menuconfig" select HC32F460
|
||||
|
||||
# Flash this firmware by copying "out/klipper.bin" to a SD card
|
||||
# as /user/firmware.bin
|
||||
# Turn on the printer with the card inserted.
|
||||
|
||||
# See docs/Config_Reference.md for a description of parameters.
|
||||
|
||||
[stepper_x]
|
||||
step_pin: PC1
|
||||
dir_pin: PC0
|
||||
enable_pin: !PC2
|
||||
microsteps: 16
|
||||
rotation_distance: 40
|
||||
endstop_pin: ^PA5
|
||||
position_min: -20
|
||||
position_endstop: -20
|
||||
position_max: 165
|
||||
homing_speed: 50
|
||||
|
||||
[stepper_y]
|
||||
step_pin: PB9
|
||||
dir_pin: PB8
|
||||
enable_pin: !PH2
|
||||
microsteps: 16
|
||||
rotation_distance: 40
|
||||
endstop_pin: ^PA6
|
||||
position_min: -5
|
||||
position_endstop: -5
|
||||
position_max: 165
|
||||
homing_speed: 50
|
||||
|
||||
[stepper_z]
|
||||
step_pin: PB6
|
||||
dir_pin: !PB5
|
||||
enable_pin: !PB7
|
||||
microsteps: 16
|
||||
rotation_distance: 8
|
||||
endstop_pin: ^PB0
|
||||
position_endstop: 0.0
|
||||
position_max: 180
|
||||
|
||||
[extruder]
|
||||
max_extrude_only_distance: 100.0
|
||||
step_pin: PB3
|
||||
dir_pin: PA15
|
||||
enable_pin: !PB4
|
||||
microsteps: 16
|
||||
rotation_distance: 27.53480577
|
||||
nozzle_diameter: 0.400
|
||||
filament_diameter: 1.750
|
||||
heater_pin: PA1
|
||||
sensor_pin: PC5
|
||||
sensor_type: Generic 3950
|
||||
control: pid
|
||||
pid_Kp: 29.634
|
||||
pid_Ki: 2.102
|
||||
pid_Kd: 104.459
|
||||
min_temp: 0
|
||||
max_temp: 260
|
||||
|
||||
[heater_bed]
|
||||
heater_pin: PB10
|
||||
sensor_type: Generic 3950
|
||||
sensor_pin: PC4
|
||||
control: pid
|
||||
pid_Kp: 72.921
|
||||
pid_Ki: 1.594
|
||||
pid_Kd: 834.031
|
||||
min_temp: 0
|
||||
max_temp: 80
|
||||
|
||||
[fan]
|
||||
pin: PA0
|
||||
|
||||
[mcu]
|
||||
serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
|
||||
restart_method: command
|
||||
|
||||
[printer]
|
||||
kinematics: cartesian
|
||||
max_velocity: 300
|
||||
max_accel: 3000
|
||||
max_z_velocity: 5
|
||||
max_z_accel: 100
|
||||
|
||||
[display]
|
||||
lcd_type: st7920
|
||||
cs_pin: PB15
|
||||
sclk_pin: PB14
|
||||
sid_pin: PB12
|
||||
encoder_pins: ^PB13,^PA2
|
||||
click_pin: ^!PC7
|
||||
@@ -1,10 +1,12 @@
|
||||
# This file contains common pin mappings for the 2019 Creality
|
||||
# Ender 5. To use this config, the firmware should be compiled for the
|
||||
# AVR atmega1284p.
|
||||
# AVR atmega1284p. This also works for the v1.1.5 silent boards.
|
||||
|
||||
# Note, a number of Melzi boards are shipped with a bootloader that
|
||||
# requires the following command to flash the board:
|
||||
# avrdude -p atmega1284p -c arduino -b 57600 -P /dev/ttyUSB0 -U out/klipper.elf.hex
|
||||
# For v1.1.5 silent boards, the following command is used:
|
||||
# avrdude -p atmega1284p -c arduino -P /dev/ttyUSB0 -b 115200 -U flash:w:out/klipper.elf.hex
|
||||
# If the above command does not work and "make flash" does not work
|
||||
# then one may need to flash a bootloader to the board - see the
|
||||
# Klipper docs/Bootloaders.md file for more information.
|
||||
@@ -80,6 +82,8 @@ pin: PB4
|
||||
|
||||
[mcu]
|
||||
serial: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
|
||||
# Silent boards tend to have the exact same serial ID, except without USB2.0, using USB instead.
|
||||
# e.g. /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
|
||||
|
||||
[printer]
|
||||
kinematics: cartesian
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# This file contains common pin mappings for the Duet3 1LC. To use
|
||||
# this config, the firmware should be compiled for the SAMC21G18 with:
|
||||
# Bootloader offset of "No Bootloader"
|
||||
# Clock Reference of "25 Mhz crystal" if the board version is v1.1 or later
|
||||
# Clock Reference of "12 Mhz crystal" if the board version is v1.0 or earlier
|
||||
# Communication interface of "CAN bus (on PA25/PA24)"
|
||||
|
||||
# To flash the board use a debugger, or use a raspberry pi and follow
|
||||
# the instructions at docs/Bootloaders.md fot the SAMC21. You may
|
||||
# supply power to the 1LC by connecting the 3.3v rail on the Pi to the
|
||||
# 5v input of the SWD header on the 1LC.
|
||||
|
||||
# See docs/Config_Reference.md for a description of parameters.
|
||||
|
||||
|
||||
# Pins for reference, v1.3 board:
|
||||
# Driver Step Pin - PA27
|
||||
# Driver Dir Pin - PA28
|
||||
# Driver Enable - !PB2
|
||||
# Thermistor Pins - TEMP0:PB9 TEMP1:PA2
|
||||
# Pullup Resistor - 2200
|
||||
# Vssa Sense:PA6 | Vref Sense:PA7
|
||||
# Current Sense resistor for drivers - 0.091ohm
|
||||
# CAN Pins - CAN0_TX:PA24 CAN0_RX:PA25
|
||||
# Heaters - OUT_0:PA11
|
||||
# Fan outputs - OUT_1:PA10 OUT_2:PB11
|
||||
# Tach Pins for Fans - OUT_1_TACHO:PA13 OUT_2_TACHO:PB10
|
||||
# GPIO_out - IO0:PA12
|
||||
# GPIO_in - IO0:PA9 IO1:PA21 IO2:PA18
|
||||
# Driver Diag - 0:PB3
|
||||
|
||||
[adc_scaled toolboard_vref_scaled]
|
||||
vref_pin: toolboard:PA7
|
||||
vssa_pin: toolboard:PA6
|
||||
|
||||
[extruder]
|
||||
step_pin: toolboard:PA27
|
||||
dir_pin: toolboard:PA28
|
||||
enable_pin: !toolboard:PB2
|
||||
rotation_distance: 23.1336867485061
|
||||
gear_ratio: 50:10
|
||||
microsteps: 64
|
||||
full_steps_per_rotation: 200
|
||||
nozzle_diameter: 0.400
|
||||
filament_diameter: 1.75
|
||||
heater_pin: toolboard:PA11
|
||||
sensor_type: PT1000
|
||||
sensor_pin: toolboard_vref_scaled:PB9
|
||||
pullup_resistor: 2200
|
||||
min_temp: 0
|
||||
max_temp: 280
|
||||
max_power: 1.0
|
||||
control: pid
|
||||
pwm_cycle_time: 0.01666
|
||||
pid_Kp: 26.454
|
||||
pid_Ki: 1.357
|
||||
pid_Kd: 128.955
|
||||
|
||||
[tmc2209 extruder]
|
||||
uart_pin: toolboard:PA20
|
||||
tx_pin: toolboard:PA22
|
||||
interpolate: False
|
||||
run_current: 0.35
|
||||
sense_resistor: 0.091
|
||||
|
||||
[fan]
|
||||
pin: toolboard:PA10
|
||||
tachometer_pin: toolboard:PA13
|
||||
|
||||
[heater_fan hotend_fan]
|
||||
pin: toolboard:PB11
|
||||
tachometer_pin: toolboard:PB10
|
||||
heater: extruder
|
||||
heater_temp: 50.0
|
||||
|
||||
[probe]
|
||||
pin: toolboard:PA9
|
||||
z_offset: 20
|
||||
|
||||
[mcu toolboard]
|
||||
canbus_uuid: 4b194673554e
|
||||
@@ -2,9 +2,8 @@
|
||||
# such as a laser or spindle.
|
||||
# See docs/Using_PWM_Tools.md for a more detailed description.
|
||||
|
||||
[output_pin TOOL]
|
||||
[pwm_tool TOOL]
|
||||
pin: !ar9 # use your fan's pin number
|
||||
pwm: True
|
||||
hardware_pwm: True
|
||||
cycle_time: 0.001
|
||||
shutdown_value: 0
|
||||
@@ -36,9 +35,9 @@ gcode:
|
||||
|
||||
[menu __main __control __toolonoff]
|
||||
type: input
|
||||
enable: {'output_pin TOOL' in printer}
|
||||
enable: {'pwm_tool TOOL' in printer}
|
||||
name: Fan: {'ON ' if menu.input else 'OFF'}
|
||||
input: {printer['output_pin TOOL'].value}
|
||||
input: {printer['pwm_tool TOOL'].value}
|
||||
input_min: 0
|
||||
input_max: 1
|
||||
input_step: 1
|
||||
@@ -47,9 +46,9 @@ gcode:
|
||||
|
||||
[menu __main __control __toolspeed]
|
||||
type: input
|
||||
enable: {'output_pin TOOL' in printer}
|
||||
enable: {'pwm_tool TOOL' in printer}
|
||||
name: Tool speed: {'%3d' % (menu.input*100)}%
|
||||
input: {printer['output_pin TOOL'].value}
|
||||
input: {printer['pwm_tool TOOL'].value}
|
||||
input_min: 0
|
||||
input_max: 1
|
||||
input_step: 0.01
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
# Bootloader Entry
|
||||
|
||||
Klipper can be instructed to reboot into a [Bootloader](Bootloaders.md) in one
|
||||
of the following ways:
|
||||
|
||||
## Requesting the bootloader
|
||||
|
||||
### Virtual Serial
|
||||
|
||||
If a virtual (USB-ACM) serial port is in use, pulsing DTR while at 1200 baud
|
||||
will request the bootloader.
|
||||
|
||||
#### Python (with `flash_usb`)
|
||||
|
||||
To enter the bootloader using python (using `flash_usb`):
|
||||
|
||||
```shell
|
||||
> cd klipper/scripts
|
||||
> python3 -c 'import flash_usb as u; u.enter_bootloader("<DEVICE>")'
|
||||
Entering bootloader on <DEVICE>
|
||||
```
|
||||
|
||||
Where `<DEVICE>` is your serial device, such as
|
||||
`/dev/serial.by-id/usb-Klipper[...]` or `/dev/ttyACM0`
|
||||
|
||||
Note that if this fails, no output will be printed, success is indicated by
|
||||
printing `Entering bootloader on <DEVICE>`.
|
||||
|
||||
#### Picocom
|
||||
|
||||
```shell
|
||||
picocom -b 1200 <DEVICE>
|
||||
<Ctrl-A><Ctrl-P>
|
||||
```
|
||||
|
||||
Where `<DEVICE>` is your serial device, such as
|
||||
`/dev/serial.by-id/usb-Klipper[...]` or `/dev/ttyACM0`
|
||||
|
||||
`<Ctrl-A><Ctrl-P>` means
|
||||
holding `Ctrl`, pressing and releasing `a`, pressing and releasing `p`, then
|
||||
releasing `Ctrl`
|
||||
|
||||
### Physical serial
|
||||
|
||||
If a physical serial port is being used on the MCU (even if a USB serial adapter
|
||||
is being used to connect to it), sending the string
|
||||
`<SPACE><FS><SPACE>Request Serial Bootloader!!<SPACE>~`.
|
||||
|
||||
`<SPACE>` is an ASCII literal space, 0x20.
|
||||
|
||||
`<FS>` is the ASCII File Separator,
|
||||
0x1c.
|
||||
|
||||
Note that this is not a valid message as per the
|
||||
[MCU Protocol](Protocol.md#micro-controller-interface), but sync characters(`~`)
|
||||
are still respected.
|
||||
|
||||
Because this message must be the only thing in the "block"
|
||||
it is received in, prefixing an extra sync character can increase reliability if
|
||||
other tools were previously accessing the serial port.
|
||||
|
||||
#### Shell
|
||||
|
||||
```shell
|
||||
stty <BAUD> < /dev/<DEVICE>
|
||||
echo $'~ \x1c Request Serial Bootloader!! ~' >> /dev/<DEVICE>
|
||||
```
|
||||
|
||||
Where `<DEVICE>` is your serial port, such as `/dev/ttyS0`, or
|
||||
`/dev/serial/by-id/gpio-serial2`, and
|
||||
|
||||
`<BAUD>` is the baud rate of the serial
|
||||
port, such as `115200`.
|
||||
|
||||
### CANBUS
|
||||
|
||||
If CANBUS is in use, a special
|
||||
[admin message](CANBUS_protocol.md#admin-messages) will request the bootloader.
|
||||
This message will be respected even if the device already has a nodeid, and will
|
||||
also be processed if the mcu is shutdown.
|
||||
|
||||
This method also applies to devices operating in
|
||||
[CANBridge](CANBUS.md#usb-to-can-bus-bridge-mode) mode.
|
||||
|
||||
#### Katapult's flashtool.py
|
||||
|
||||
```shell
|
||||
python3 ./katapult/scripts/flashtool.py -i <CAN_IFACE> -u <UUID> -r
|
||||
```
|
||||
|
||||
Where `<CAN_IFACE>` is the can interface to use. If using `can0`, both the `-i`
|
||||
and `<CAN_IFACE>` may be omitted.
|
||||
|
||||
`<UUID>` is the UUID of your CAN device.
|
||||
|
||||
See the
|
||||
[CANBUS Documentation](CANBUS.md#finding-the-canbus_uuid-for-new-micro-controllers)
|
||||
for information on finding the CAN UUID of your devices.
|
||||
|
||||
## Entering the bootloader
|
||||
|
||||
When klipper receives one of the above bootloader requests:
|
||||
|
||||
If Katapult (formerly known as CANBoot) is available, klipper will request that
|
||||
Katapult stay active on the next boot, then reset the MCU (therefore entering
|
||||
Katapult).
|
||||
|
||||
If Katapult is not available, klipper will then try to enter a
|
||||
platform-specific bootloader, such as STM32's DFU
|
||||
mode([see note](#stm32-dfu-warning)).
|
||||
|
||||
In short, Klipper will reboot to Katapult if installed, then a hardware specific
|
||||
bootloader if available.
|
||||
|
||||
For details about the specific bootloaders on various platforms see
|
||||
[Bootloaders](Bootloaders.md)
|
||||
|
||||
## Notes
|
||||
|
||||
### STM32 DFU Warning
|
||||
|
||||
Note that on some boards, like the Octopus Pro v1, entering DFU mode can cause
|
||||
undesired actions (such as powering the heater while in DFU mode). It is
|
||||
recommended to disconnect heaters, and otherwise prevent undesired operations
|
||||
when using DFU mode. Consult the documentation for your board for more details.
|
||||
@@ -185,6 +185,50 @@ To flash an application use something like:
|
||||
bossac --port=/dev/ttyACM0 -b -U -e -w -v -R out/klipper.bin
|
||||
```
|
||||
|
||||
## SAMDC21 micro-controllers (Duet3D Toolboard 1LC)
|
||||
|
||||
The SAMC21 is flashed via the ARM Serial Wire Debug (SWD) interface.
|
||||
This is commonly done with a dedicated SWD hardware dongle.
|
||||
Alternatively, one can use a
|
||||
[Raspberry Pi with OpenOCD](#running-openocd-on-the-raspberry-pi).
|
||||
|
||||
When using OpenOCD with the SAMC21, extra steps must be taken to first
|
||||
put the chip into Cold Plugging mode if the board makes use of the
|
||||
SWD pins for other purposes. If using OpenOCD on a Rasberry Pi, this
|
||||
can be done by running the following commands before invoking OpenOCD.
|
||||
```
|
||||
SWCLK=25
|
||||
SWDIO=24
|
||||
SRST=18
|
||||
|
||||
echo "Exporting SWCLK and SRST pins."
|
||||
echo $SWCLK > /sys/class/gpio/export
|
||||
echo $SRST > /sys/class/gpio/export
|
||||
echo "out" > /sys/class/gpio/gpio$SWCLK/direction
|
||||
echo "out" > /sys/class/gpio/gpio$SRST/direction
|
||||
|
||||
echo "Setting SWCLK low and pulsing SRST."
|
||||
echo "0" > /sys/class/gpio/gpio$SWCLK/value
|
||||
echo "0" > /sys/class/gpio/gpio$SRST/value
|
||||
echo "1" > /sys/class/gpio/gpio$SRST/value
|
||||
|
||||
echo "Unexporting SWCLK and SRST pins."
|
||||
echo $SWCLK > /sys/class/gpio/unexport
|
||||
echo $SRST > /sys/class/gpio/unexport
|
||||
```
|
||||
|
||||
To flash a program with OpenOCD use the following chip config:
|
||||
```
|
||||
source [find target/at91samdXX.cfg]
|
||||
```
|
||||
Obtain a program; for instance, klipper can be built for this chip.
|
||||
Flash with OpenOCD commands similar to:
|
||||
```
|
||||
at91samd chip-erase
|
||||
at91samd bootloader 0
|
||||
program out/klipper.elf verify
|
||||
```
|
||||
|
||||
## SAMD21 micro-controllers (Arduino Zero)
|
||||
|
||||
The SAMD21 bootloader is flashed via the ARM Serial Wire Debug (SWD)
|
||||
|
||||
@@ -8,10 +8,14 @@ All dates in this document are approximate.
|
||||
|
||||
## Changes
|
||||
|
||||
20230820: The heater `smooth_time` now defaults to not perform any
|
||||
additional temperature smoothing. To return to the previous behavior
|
||||
of one second smoothing, set `smooth_time: 1.0` in the heater config
|
||||
section.
|
||||
20230826: If `safe_distance` is set or calculated to be 0 in `[dual_carriage]`,
|
||||
the carriages proximity checks will be disabled as per documentation. A user
|
||||
may wish to configure `safe_distance` explicitly to prevent accidental crashes
|
||||
of the carriages with each other. Additionally, the homing order of the primary
|
||||
and the dual carriage is changed in some configurations (certain configurations
|
||||
when both carriages home in the same direction, see
|
||||
[[dual_carriage] configuration reference](./Config_Reference.md#dual_carriage)
|
||||
for more details).
|
||||
|
||||
20230810: The flash-sdcard.sh script now supports both variants of the
|
||||
Bigtreetech SKR-3, STM32H743 and STM32H723. For this, the original tag
|
||||
|
||||
@@ -798,10 +798,10 @@ sensor_pin:
|
||||
# The resistance (in ohms) of the pullup attached to the thermistor.
|
||||
# This parameter is only valid when the sensor is a thermistor. The
|
||||
# default is 4700 ohms.
|
||||
#smooth_time:
|
||||
#smooth_time: 1.0
|
||||
# A time value (in seconds) over which temperature measurements will
|
||||
# be smoothed to reduce the impact of measurement noise. The default
|
||||
# is to not perform any additional temperature smoothing.
|
||||
# is 1 seconds.
|
||||
control:
|
||||
# Control algorithm (either pid or watermark). This parameter must
|
||||
# be provided.
|
||||
@@ -1646,6 +1646,27 @@ cs_pin:
|
||||
# measurements.
|
||||
```
|
||||
|
||||
### [lis2dw]
|
||||
|
||||
Support for LIS2DW accelerometers.
|
||||
|
||||
```
|
||||
[lis2dw]
|
||||
cs_pin:
|
||||
# The SPI enable pin for the sensor. This parameter must be provided.
|
||||
#spi_speed: 5000000
|
||||
# The SPI speed (in hz) to use when communicating with the chip.
|
||||
# The default is 5000000.
|
||||
#spi_bus:
|
||||
#spi_software_sclk_pin:
|
||||
#spi_software_mosi_pin:
|
||||
#spi_software_miso_pin:
|
||||
# See the "common SPI settings" section for a description of the
|
||||
# above parameters.
|
||||
#axes_map: x, y, z
|
||||
# See the "adxl345" section for information on this parameter.
|
||||
```
|
||||
|
||||
### [mpu9250]
|
||||
|
||||
Support for MPU-9250, MPU-9255, MPU-6515, MPU-6050, and MPU-6500
|
||||
@@ -2044,6 +2065,14 @@ in this section (CARRIAGE=0 will return activation to the primary carriage).
|
||||
Dual carriage support is typically combined with extra extruders - the
|
||||
SET_DUAL_CARRIAGE command is often called at the same time as the
|
||||
ACTIVATE_EXTRUDER command. Be sure to park the carriages during deactivation.
|
||||
Note that during G28 homing, typically the primary carriage is homed first
|
||||
followed by the carriage defined in the `[dual_carriage]` config section.
|
||||
However, the `[dual_carriage]` carriage will be homed first if both carriages
|
||||
home in a positive direction and the [dual_carriage] carriage has a
|
||||
`position_endstop` greater than the primary carriage, or if both carriages home
|
||||
in a negative direction and the `[dual_carriage]` carriage has a
|
||||
`position_endstop` less than the primary carriage.
|
||||
|
||||
Additionally, one could use "SET_DUAL_CARRIAGE CARRIAGE=1 MODE=COPY" or
|
||||
"SET_DUAL_CARRIAGE CARRIAGE=1 MODE=MIRROR" commands to activate either copying
|
||||
or mirroring mode of the dual carriage, in which case it will follow the
|
||||
@@ -3098,6 +3127,27 @@ pin:
|
||||
# parameter.
|
||||
```
|
||||
|
||||
### [pwm_tool]
|
||||
|
||||
Pulse width modulation digital output pins capable of high speed
|
||||
updates (one may define any number of sections with an "output_pin"
|
||||
prefix). Pins configured here will be setup as output pins and one may
|
||||
modify them at run-time using "SET_PIN PIN=my_pin VALUE=.1" type
|
||||
extended [g-code commands](G-Codes.md#output_pin).
|
||||
|
||||
```
|
||||
[pwm_tool my_tool]
|
||||
pin:
|
||||
# The pin to configure as an output. This parameter must be provided.
|
||||
#value:
|
||||
#shutdown_value:
|
||||
#maximum_mcu_duration:
|
||||
#cycle_time: 0.100
|
||||
#hardware_pwm: False
|
||||
#scale:
|
||||
# See the "output_pin" section for the definition of these parameters.
|
||||
```
|
||||
|
||||
### [static_digital_output]
|
||||
|
||||
Statically configured digital output pins (one may define any number
|
||||
@@ -3421,7 +3471,7 @@ run_current:
|
||||
|
||||
### [tmc2240]
|
||||
|
||||
Configure a TMC2240 stepper motor driver via SPI bus. To use this
|
||||
Configure a TMC2240 stepper motor driver via SPI bus or UART. To use this
|
||||
feature, define a config section with a "tmc2240" prefix followed by
|
||||
the name of the corresponding stepper config section (for example,
|
||||
"[tmc2240 stepper_x]").
|
||||
@@ -3439,6 +3489,9 @@ cs_pin:
|
||||
#spi_software_miso_pin:
|
||||
# See the "common SPI settings" section for a description of the
|
||||
# above parameters.
|
||||
#uart_pin:
|
||||
# The pin connected to the TMC2240 DIAG1/SW line. If this parameter
|
||||
# is provided UART communication is used rather then SPI.
|
||||
#chain_position:
|
||||
#chain_length:
|
||||
# These parameters configure an SPI daisy chain. The two parameters
|
||||
|
||||
+2
-1
@@ -834,7 +834,8 @@ commands to manage the LED's color settings).
|
||||
### [output_pin]
|
||||
|
||||
The following command is available when an
|
||||
[output_pin config section](Config_Reference.md#output_pin) is
|
||||
[output_pin config section](Config_Reference.md#output_pin) or
|
||||
[pwm_tool config section](Config_Reference.md#pwm_tool) is
|
||||
enabled.
|
||||
|
||||
#### SET_PIN
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# Measuring Resonances
|
||||
|
||||
Klipper has built-in support for the ADXL345 and MPU-9250 compatible
|
||||
Klipper has built-in support for the ADXL345, MPU-9250 and LIS2DW compatible
|
||||
accelerometers which can be used to measure resonance frequencies of the printer
|
||||
for different axes, and auto-tune [input shapers](Resonance_Compensation.md) to
|
||||
compensate for resonances. Note that using accelerometers requires some
|
||||
soldering and crimping. The ADXL345 can be connected to the SPI interface of a
|
||||
Raspberry Pi or MCU board (it needs to be reasonably fast). The MPU family can
|
||||
soldering and crimping. The ADXL345/LIS2DW can be connected to the SPI interface
|
||||
of a Raspberry Pi or MCU board (it needs to be reasonably fast). The MPU family can
|
||||
be connected to the I2C interface of a Raspberry Pi directly, or to an I2C
|
||||
interface of an MCU board that supports 400kbit/s *fast mode* in Klipper.
|
||||
|
||||
@@ -13,7 +13,7 @@ When sourcing accelerometers, be aware that there are a variety of different PCB
|
||||
board designs and different clones of them. If it is going to be connected to a
|
||||
5V printer MCU ensure it has a voltage regulator and level shifters.
|
||||
|
||||
For ADXL345s, make sure that the board supports SPI mode (a small number of
|
||||
For ADXL345s/LIS2DWs, make sure that the board supports SPI mode (a small number of
|
||||
boards appear to be hard-configured for I2C by pulling SDO to GND).
|
||||
|
||||
For MPU-9250/MPU-9255/MPU-6515/MPU-6050/MPU-6500s there are also a variety of
|
||||
@@ -305,6 +305,26 @@ you'll also want to modify your `printer.cfg` file to include this:
|
||||
|
||||
Restart Klipper via the `RESTART` command.
|
||||
|
||||
#### Configure LIS2DW series
|
||||
|
||||
```
|
||||
[mcu lis]
|
||||
# Change <mySerial> to whatever you found above. For example,
|
||||
# usb-Klipper_rp2040_E661640843545B2E-if00
|
||||
serial: /dev/serial/by-id/usb-Klipper_rp2040_<mySerial>
|
||||
|
||||
[lis2dw]
|
||||
cs_pin: lis:gpio1
|
||||
spi_bus: spi0a
|
||||
axes_map: x,z,y
|
||||
|
||||
[resonance_tester]
|
||||
accel_chip: lis2dw
|
||||
probe_points:
|
||||
# Somewhere slightly above the middle of your print bed
|
||||
147,154, 20
|
||||
```
|
||||
|
||||
#### Configure MPU-6000/9000 series With RPi
|
||||
|
||||
Make sure the Linux I2C driver is enabled and the baud rate is
|
||||
|
||||
@@ -93,6 +93,7 @@ communication with the Klipper developers.
|
||||
Beaglebone PRU.
|
||||
- [Bootloaders](Bootloaders.md): Developer information on
|
||||
micro-controller flashing.
|
||||
- [Bootloader Entry](Bootloader_Entry.md): Requesting the bootloader.
|
||||
- [CAN bus](CANBUS.md): Information on using CAN bus with Klipper.
|
||||
- [CAN bus troubleshooting](CANBUS_Troubleshooting.md): Tips for
|
||||
troubleshooting CAN bus.
|
||||
|
||||
@@ -198,18 +198,28 @@ default on a Raspberry and can be activated by adding a line to
|
||||
dtoverlay=pwm,pin=12,func=4
|
||||
```
|
||||
This example enables only PWM0 and routes it to gpio12. If both PWM
|
||||
channels need to be enabled you can use `pwm-2chan`.
|
||||
channels need to be enabled you can use `pwm-2chan`:
|
||||
```
|
||||
# Enable pwmchip sysfs interface
|
||||
dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4
|
||||
```
|
||||
This example additionally enables PWM1 and routes it to gpio13.
|
||||
|
||||
The overlay does not expose the pwm line on sysfs on boot and needs to
|
||||
be exported by echo'ing the number of the pwm channel to
|
||||
`/sys/class/pwm/pwmchip0/export`:
|
||||
`/sys/class/pwm/pwmchip0/export`. This will create device `/sys/class/pwm/pwmchip0/pwm0` in the
|
||||
filesystem. The easiest way to do this is by adding this to
|
||||
`/etc/rc.local` before the `exit 0` line:
|
||||
```
|
||||
# Enable pwmchip sysfs interface
|
||||
echo 0 > /sys/class/pwm/pwmchip0/export
|
||||
```
|
||||
|
||||
This will create device `/sys/class/pwm/pwmchip0/pwm0` in the
|
||||
filesystem. The easiest way to do this is by adding this to
|
||||
`/etc/rc.local` before the `exit 0` line.
|
||||
When using both PWM channels, the number of the second channel needs to be echo'd as well:
|
||||
```
|
||||
# Enable pwmchip sysfs interface
|
||||
echo 0 > /sys/class/pwm/pwmchip0/export
|
||||
echo 1 > /sys/class/pwm/pwmchip0/export
|
||||
```
|
||||
|
||||
With the sysfs in place, you can now use either the pwm channel(s) by
|
||||
adding the following piece of configuration to your `printer.cfg`:
|
||||
@@ -219,9 +229,17 @@ pin: host:pwmchip0/pwm0
|
||||
pwm: True
|
||||
hardware_pwm: True
|
||||
cycle_time: 0.000001
|
||||
|
||||
[output_pin beeper]
|
||||
pin: host:pwmchip0/pwm1
|
||||
pwm: True
|
||||
hardware_pwm: True
|
||||
value: 0
|
||||
shutdown_value: 0
|
||||
cycle_time: 0.0005
|
||||
```
|
||||
This will add hardware pwm control to gpio12 on the Pi (because the
|
||||
overlay was configured to route pwm0 to pin=12).
|
||||
This will add hardware pwm control to gpio12 and gpio13 on the Pi (because the
|
||||
overlay was configured to route pwm0 to pin=12 and pwm1 to pin=13).
|
||||
|
||||
PWM0 can be routed to gpio12 and gpio18, PWM1 can be routed to gpio13
|
||||
and gpio19:
|
||||
|
||||
+3
-2
@@ -6,7 +6,7 @@ sponsors.
|
||||
|
||||
## BIGTREETECH
|
||||
|
||||
[<img src="./img/sponsors/BTT_BTT.png" width="200" />](https://bigtree-tech.com/collections/all-products)
|
||||
[<img src="./img/sponsors/BTT_BTT.png" width="200" style="margin:25px"/>](https://bigtree-tech.com/collections/all-products)
|
||||
|
||||
BIGTREETECH is the official mainboard sponsor of Klipper. BIGTREETECH
|
||||
is committed to developing innovative and competitive products to
|
||||
@@ -16,7 +16,8 @@ serve the 3D printing community better. Follow them on
|
||||
|
||||
## Sponsors
|
||||
|
||||
[<img src="./img/sponsors/obico-light-horizontal.png" width="200" />](https://obico.io/klipper.html?source=klipper_sponsor)
|
||||
[<img src="./img/sponsors/obico-light-horizontal.png" width="200" style="margin:25px" />](https://obico.io/klipper.html?source=klipper_sponsor)
|
||||
[<img src="./img/sponsors/peopoly-logo.png" width="200" style="margin:25px" />](https://peopoly.net)
|
||||
|
||||
## Klipper Developers
|
||||
|
||||
|
||||
@@ -318,7 +318,8 @@ is defined):
|
||||
## output_pin
|
||||
|
||||
The following information is available in
|
||||
[output_pin some_name](Config_Reference.md#output_pin) objects:
|
||||
[output_pin some_name](Config_Reference.md#output_pin) and
|
||||
[pwm_tool some_name](Config_Reference.md#pwm_tool) objects:
|
||||
- `value`: The "value" of the pin, as set by a `SET_PIN` command.
|
||||
|
||||
## palette2
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Using PWM tools
|
||||
|
||||
This document describes how to setup a PWM-controlled laser or spindle
|
||||
using `output_pin` and some macros.
|
||||
using `pwm_tool` and some macros.
|
||||
|
||||
## How does it work?
|
||||
|
||||
@@ -26,14 +26,6 @@ so that when your host or MCU encounters an error, the tool will stop.
|
||||
|
||||
For an example configuration, see [config/sample-pwm-tool.cfg](/config/sample-pwm-tool.cfg).
|
||||
|
||||
## Current Limitations
|
||||
|
||||
There is a limitation of how frequent PWM updates may occur.
|
||||
While being very precise, a PWM update may only occur every 0.1 seconds,
|
||||
rendering it almost useless for raster engraving.
|
||||
However, there exists an [experimental branch](https://github.com/Cirromulus/klipper/tree/laser_tool) with its own tradeoffs.
|
||||
In long term, it is planned to add this functionality to main-line klipper.
|
||||
|
||||
## Commands
|
||||
|
||||
`M3/M4 S<value>` : Set PWM duty-cycle. Values between 0 and 255.
|
||||
|
||||
@@ -133,6 +133,7 @@ nav:
|
||||
- RPi_microcontroller.md
|
||||
- Beaglebone.md
|
||||
- Bootloaders.md
|
||||
- Bootloader_Entry.md
|
||||
- CANBUS.md
|
||||
- CANBUS_Troubleshooting.md
|
||||
- TSL1401CL_Filament_Width_Sensor.md
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@@ -49,6 +49,8 @@ defs_stepcompress = """
|
||||
, uint64_t clock);
|
||||
int stepcompress_queue_msg(struct stepcompress *sc
|
||||
, uint32_t *data, int len);
|
||||
int stepcompress_queue_mq_msg(struct stepcompress *sc, uint64_t req_clock
|
||||
, uint32_t *data, int len);
|
||||
int stepcompress_extract_old(struct stepcompress *sc
|
||||
, struct pull_history_steps *p, int max
|
||||
, uint64_t start_clock, uint64_t end_clock);
|
||||
|
||||
@@ -62,6 +62,7 @@ struct serialqueue {
|
||||
int ready_bytes, upcoming_bytes, need_ack_bytes, last_ack_bytes;
|
||||
uint64_t need_kick_clock;
|
||||
struct list_head notify_queue;
|
||||
double last_write_fail_time;
|
||||
// Received messages
|
||||
struct list_head receive_queue;
|
||||
// Fastreader support
|
||||
@@ -376,8 +377,16 @@ do_write(struct serialqueue *sq, void *buf, int buflen)
|
||||
int ret = write(sq->serial_fd, &cf, sizeof(cf));
|
||||
if (ret < 0) {
|
||||
report_errno("can write", ret);
|
||||
double curtime = get_monotonic();
|
||||
if (!sq->last_write_fail_time) {
|
||||
sq->last_write_fail_time = curtime;
|
||||
} else if (curtime > sq->last_write_fail_time + 10.0) {
|
||||
errorf("Halting reads due to CAN write errors.");
|
||||
pollreactor_do_exit(sq->pr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
sq->last_write_fail_time = 0.0;
|
||||
buf += size;
|
||||
buflen -= size;
|
||||
}
|
||||
|
||||
@@ -623,6 +623,21 @@ stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Queue an mcu command that will consume space in the mcu move queue
|
||||
int __visible
|
||||
stepcompress_queue_mq_msg(struct stepcompress *sc, uint64_t req_clock
|
||||
, uint32_t *data, int len)
|
||||
{
|
||||
int ret = stepcompress_flush(sc, UINT64_MAX);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
struct queue_message *qm = message_alloc_and_encode(data, len);
|
||||
qm->min_clock = qm->req_clock = req_clock;
|
||||
list_add_tail(&qm->node, &sc->msg_queue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Return history of queue_step commands
|
||||
int __visible
|
||||
stepcompress_extract_old(struct stepcompress *sc, struct pull_history_steps *p
|
||||
|
||||
@@ -29,6 +29,8 @@ int stepcompress_set_last_position(struct stepcompress *sc, uint64_t clock
|
||||
int64_t stepcompress_find_past_position(struct stepcompress *sc
|
||||
, uint64_t clock);
|
||||
int stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len);
|
||||
int stepcompress_queue_mq_msg(struct stepcompress *sc, uint64_t req_clock
|
||||
, uint32_t *data, int len);
|
||||
int stepcompress_extract_old(struct stepcompress *sc
|
||||
, struct pull_history_steps *p, int max
|
||||
, uint64_t start_clock, uint64_t end_clock);
|
||||
|
||||
@@ -34,8 +34,7 @@ class Heater:
|
||||
is not None)
|
||||
self.can_extrude = self.min_extrude_temp <= 0. or is_fileoutput
|
||||
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
|
||||
self.smooth_time = config.getfloat('smooth_time', self.pwm_delay,
|
||||
above=0.)
|
||||
self.smooth_time = config.getfloat('smooth_time', 1., above=0.)
|
||||
self.inv_smooth_time = 1. / self.smooth_time
|
||||
self.lock = threading.Lock()
|
||||
self.last_temp = self.smoothed_temp = self.target_temp = 0.
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
# Support for reading acceleration data from an LIS2DW chip
|
||||
#
|
||||
# Copyright (C) 2023 Zhou.XianMing <zhouxm@biqu3d.com>
|
||||
# Copyright (C) 2020-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging, time, collections, threading, multiprocessing, os
|
||||
from . import bus, motion_report, adxl345
|
||||
|
||||
# LIS2DW registers
|
||||
REG_LIS2DW_WHO_AM_I_ADDR = 0x0F
|
||||
REG_LIS2DW_CTRL_REG1_ADDR = 0x20
|
||||
REG_LIS2DW_CTRL_REG2_ADDR = 0x21
|
||||
REG_LIS2DW_CTRL_REG3_ADDR = 0x22
|
||||
REG_LIS2DW_CTRL_REG6_ADDR = 0x25
|
||||
REG_LIS2DW_STATUS_REG_ADDR = 0x27
|
||||
REG_LIS2DW_OUT_XL_ADDR = 0x28
|
||||
REG_LIS2DW_OUT_XH_ADDR = 0x29
|
||||
REG_LIS2DW_OUT_YL_ADDR = 0x2A
|
||||
REG_LIS2DW_OUT_YH_ADDR = 0x2B
|
||||
REG_LIS2DW_OUT_ZL_ADDR = 0x2C
|
||||
REG_LIS2DW_OUT_ZH_ADDR = 0x2D
|
||||
REG_LIS2DW_FIFO_CTRL = 0x2E
|
||||
REG_LIS2DW_FIFO_SAMPLES = 0x2F
|
||||
REG_MOD_READ = 0x80
|
||||
# REG_MOD_MULTI = 0x40
|
||||
|
||||
LIS2DW_DEV_ID = 0x44
|
||||
|
||||
FREEFALL_ACCEL = 9.80665
|
||||
SCALE = FREEFALL_ACCEL * 1.952 / 4
|
||||
|
||||
Accel_Measurement = collections.namedtuple(
|
||||
'Accel_Measurement', ('time', 'accel_x', 'accel_y', 'accel_z'))
|
||||
|
||||
MIN_MSG_TIME = 0.100
|
||||
|
||||
BYTES_PER_SAMPLE = 6
|
||||
SAMPLES_PER_BLOCK = 8
|
||||
|
||||
# Printer class that controls LIS2DW chip
|
||||
class LIS2DW:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
adxl345.AccelCommandHelper(config, self)
|
||||
self.query_rate = 0
|
||||
am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
|
||||
'-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
|
||||
axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
|
||||
if any([a not in am for a in axes_map]):
|
||||
raise config.error("Invalid lis2dw axes_map parameter")
|
||||
self.axes_map = [am[a.strip()] for a in axes_map]
|
||||
self.data_rate = 1600
|
||||
# Measurement storage (accessed from background thread)
|
||||
self.lock = threading.Lock()
|
||||
self.raw_samples = []
|
||||
# Setup mcu sensor_lis2dw bulk query code
|
||||
self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=5000000)
|
||||
self.mcu = mcu = self.spi.get_mcu()
|
||||
self.oid = oid = mcu.create_oid()
|
||||
self.query_lis2dw_cmd = self.query_lis2dw_end_cmd = None
|
||||
self.query_lis2dw_status_cmd = None
|
||||
mcu.add_config_cmd("config_lis2dw oid=%d spi_oid=%d"
|
||||
% (oid, self.spi.get_oid()))
|
||||
mcu.add_config_cmd("query_lis2dw oid=%d clock=0 rest_ticks=0"
|
||||
% (oid,), on_restart=True)
|
||||
mcu.register_config_callback(self._build_config)
|
||||
mcu.register_response(self._handle_lis2dw_data, "lis2dw_data", oid)
|
||||
# Clock tracking
|
||||
self.last_sequence = self.max_query_duration = 0
|
||||
self.last_limit_count = self.last_error_count = 0
|
||||
self.clock_sync = adxl345.ClockSyncRegression(self.mcu, 640)
|
||||
# API server endpoints
|
||||
self.api_dump = motion_report.APIDumpHelper(
|
||||
self.printer, self._api_update, self._api_startstop, 0.100)
|
||||
self.name = config.get_name().split()[-1]
|
||||
wh = self.printer.lookup_object('webhooks')
|
||||
wh.register_mux_endpoint("lis2dw/dump_lis2dw", "sensor", self.name,
|
||||
self._handle_dump_lis2dw)
|
||||
|
||||
def _build_config(self):
|
||||
cmdqueue = self.spi.get_command_queue()
|
||||
self.query_lis2dw_cmd = self.mcu.lookup_command(
|
||||
"query_lis2dw oid=%c clock=%u rest_ticks=%u", cq=cmdqueue)
|
||||
self.query_lis2dw_end_cmd = self.mcu.lookup_query_command(
|
||||
"query_lis2dw oid=%c clock=%u rest_ticks=%u",
|
||||
"lis2dw_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
|
||||
" buffered=%c fifo=%c limit_count=%hu", oid=self.oid, cq=cmdqueue)
|
||||
self.query_lis2dw_status_cmd = self.mcu.lookup_query_command(
|
||||
"query_lis2dw_status oid=%c",
|
||||
"lis2dw_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
|
||||
" buffered=%c fifo=%c limit_count=%hu", oid=self.oid, cq=cmdqueue)
|
||||
def read_reg(self, reg):
|
||||
params = self.spi.spi_transfer([reg | REG_MOD_READ, 0x00])
|
||||
response = bytearray(params['response'])
|
||||
return response[1]
|
||||
def set_reg(self, reg, val, minclock=0):
|
||||
self.spi.spi_send([reg, val & 0xFF], minclock=minclock)
|
||||
stored_val = self.read_reg(reg)
|
||||
if stored_val != val:
|
||||
raise self.printer.command_error(
|
||||
"Failed to set LIS2DW register [0x%x] to 0x%x: got 0x%x. "
|
||||
"This is generally indicative of connection problems "
|
||||
"(e.g. faulty wiring) or a faulty lis2dw chip." % (
|
||||
reg, val, stored_val))
|
||||
# Measurement collection
|
||||
def is_measuring(self):
|
||||
return self.query_rate > 0
|
||||
def _handle_lis2dw_data(self, params):
|
||||
with self.lock:
|
||||
self.raw_samples.append(params)
|
||||
def _extract_samples(self, raw_samples):
|
||||
# Load variables to optimize inner loop below
|
||||
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
|
||||
last_sequence = self.last_sequence
|
||||
time_base, chip_base, inv_freq = self.clock_sync.get_time_translation()
|
||||
# Process every message in raw_samples
|
||||
count = seq = 0
|
||||
samples = [None] * (len(raw_samples) * SAMPLES_PER_BLOCK)
|
||||
for params in raw_samples:
|
||||
seq_diff = (last_sequence - params['sequence']) & 0xffff
|
||||
seq_diff -= (seq_diff & 0x8000) << 1
|
||||
seq = last_sequence - seq_diff
|
||||
d = bytearray(params['data'])
|
||||
msg_cdiff = seq * SAMPLES_PER_BLOCK - chip_base
|
||||
|
||||
for i in range(len(d) // BYTES_PER_SAMPLE):
|
||||
d_xyz = d[i*BYTES_PER_SAMPLE:(i+1)*BYTES_PER_SAMPLE]
|
||||
xlow, xhigh, ylow, yhigh, zlow, zhigh = d_xyz
|
||||
# Merge and perform twos-complement
|
||||
|
||||
rx = (((xhigh << 8) | xlow)) - ((xhigh & 0x80) << 9)
|
||||
ry = (((yhigh << 8) | ylow)) - ((yhigh & 0x80) << 9)
|
||||
rz = (((zhigh << 8) | zlow)) - ((zhigh & 0x80) << 9)
|
||||
|
||||
raw_xyz = (rx, ry, rz)
|
||||
|
||||
x = round(raw_xyz[x_pos] * x_scale, 6)
|
||||
y = round(raw_xyz[y_pos] * y_scale, 6)
|
||||
z = round(raw_xyz[z_pos] * z_scale, 6)
|
||||
|
||||
ptime = round(time_base + (msg_cdiff + i) * inv_freq, 6)
|
||||
samples[count] = (ptime, x, y, z)
|
||||
count += 1
|
||||
self.clock_sync.set_last_chip_clock(seq * SAMPLES_PER_BLOCK + i)
|
||||
del samples[count:]
|
||||
return samples
|
||||
def _update_clock(self, minclock=0):
|
||||
# Query current state
|
||||
for retry in range(5):
|
||||
params = self.query_lis2dw_status_cmd.send([self.oid],
|
||||
minclock=minclock)
|
||||
fifo = params['fifo'] & 0x1f
|
||||
if fifo <= 32:
|
||||
break
|
||||
else:
|
||||
raise self.printer.command_error("Unable to query lis2dw fifo")
|
||||
mcu_clock = self.mcu.clock32_to_clock64(params['clock'])
|
||||
sequence = (self.last_sequence & ~0xffff) | params['next_sequence']
|
||||
if sequence < self.last_sequence:
|
||||
sequence += 0x10000
|
||||
self.last_sequence = sequence
|
||||
buffered = params['buffered']
|
||||
limit_count = (self.last_limit_count & ~0xffff) | params['limit_count']
|
||||
if limit_count < self.last_limit_count:
|
||||
limit_count += 0x10000
|
||||
self.last_limit_count = limit_count
|
||||
duration = params['query_ticks']
|
||||
if duration > self.max_query_duration:
|
||||
# Skip measurement as a high query time could skew clock tracking
|
||||
self.max_query_duration = max(2 * self.max_query_duration,
|
||||
self.mcu.seconds_to_clock(.000005))
|
||||
return
|
||||
self.max_query_duration = 2 * duration
|
||||
msg_count = (sequence * SAMPLES_PER_BLOCK
|
||||
+ buffered // BYTES_PER_SAMPLE + fifo)
|
||||
# The "chip clock" is the message counter plus .5 for average
|
||||
# inaccuracy of query responses and plus .5 for assumed offset
|
||||
# of lis2dw hw processing time.
|
||||
chip_clock = msg_count + 1
|
||||
self.clock_sync.update(mcu_clock + duration // 2, chip_clock)
|
||||
def _start_measurements(self):
|
||||
if self.is_measuring():
|
||||
return
|
||||
# In case of miswiring, testing LIS2DW device ID prevents treating
|
||||
# noise or wrong signal as a correctly initialized device
|
||||
dev_id = self.read_reg(REG_LIS2DW_WHO_AM_I_ADDR)
|
||||
logging.info("lis2dw_dev_id: %x", dev_id)
|
||||
if dev_id != LIS2DW_DEV_ID:
|
||||
raise self.printer.command_error(
|
||||
"Invalid lis2dw id (got %x vs %x).\n"
|
||||
"This is generally indicative of connection problems\n"
|
||||
"(e.g. faulty wiring) or a faulty lis2dw chip."
|
||||
% (dev_id, LIS2DW_DEV_ID))
|
||||
# Setup chip in requested query rate
|
||||
# ODR/2, +-16g, low-pass filter, Low-noise abled
|
||||
self.set_reg(REG_LIS2DW_CTRL_REG6_ADDR, 0x34)
|
||||
# Continuous mode: If the FIFO is full
|
||||
# the new sample overwrites the older sample.
|
||||
self.set_reg(REG_LIS2DW_FIFO_CTRL, 0xC0)
|
||||
# High-Performance / Low-Power mode 1600/200 Hz
|
||||
# High-Performance Mode (14-bit resolution)
|
||||
self.set_reg(REG_LIS2DW_CTRL_REG1_ADDR, 0x94)
|
||||
|
||||
# Setup samples
|
||||
with self.lock:
|
||||
self.raw_samples = []
|
||||
# Start bulk reading
|
||||
systime = self.printer.get_reactor().monotonic()
|
||||
print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME
|
||||
reqclock = self.mcu.print_time_to_clock(print_time)
|
||||
rest_ticks = self.mcu.seconds_to_clock(4. / self.data_rate)
|
||||
self.query_rate = self.data_rate
|
||||
self.query_lis2dw_cmd.send([self.oid, reqclock, rest_ticks],
|
||||
reqclock=reqclock)
|
||||
logging.info("LIS2DW starting '%s' measurements", self.name)
|
||||
# Initialize clock tracking
|
||||
self.last_sequence = 0
|
||||
self.last_limit_count = self.last_error_count = 0
|
||||
self.clock_sync.reset(reqclock, 0)
|
||||
self.max_query_duration = 1 << 31
|
||||
self._update_clock(minclock=reqclock)
|
||||
self.max_query_duration = 1 << 31
|
||||
def _finish_measurements(self):
|
||||
if not self.is_measuring():
|
||||
return
|
||||
# Halt bulk reading
|
||||
params = self.query_lis2dw_end_cmd.send([self.oid, 0, 0])
|
||||
self.query_rate = 0
|
||||
with self.lock:
|
||||
self.raw_samples = []
|
||||
logging.info("LIS2DW finished '%s' measurements", self.name)
|
||||
self.set_reg(REG_LIS2DW_FIFO_CTRL, 0x00)
|
||||
# API interface
|
||||
def _api_update(self, eventtime):
|
||||
self._update_clock()
|
||||
with self.lock:
|
||||
raw_samples = self.raw_samples
|
||||
self.raw_samples = []
|
||||
if not raw_samples:
|
||||
return {}
|
||||
samples = self._extract_samples(raw_samples)
|
||||
if not samples:
|
||||
return {}
|
||||
return {'data': samples, 'errors': self.last_error_count,
|
||||
'overflows': self.last_limit_count}
|
||||
def _api_startstop(self, is_start):
|
||||
if is_start:
|
||||
self._start_measurements()
|
||||
else:
|
||||
self._finish_measurements()
|
||||
def _handle_dump_lis2dw(self, web_request):
|
||||
self.api_dump.add_client(web_request)
|
||||
hdr = ('time', 'x_acceleration', 'y_acceleration', 'z_acceleration')
|
||||
web_request.send({'header': hdr})
|
||||
def start_internal_client(self):
|
||||
cconn = self.api_dump.add_internal_client()
|
||||
return adxl345.AccelQueryHelper(self.printer, cconn)
|
||||
|
||||
|
||||
def load_config(config):
|
||||
return LIS2DW(config)
|
||||
|
||||
def load_config_prefix(config):
|
||||
return LIS2DW(config)
|
||||
@@ -0,0 +1,187 @@
|
||||
# Queued PWM gpio output
|
||||
#
|
||||
# Copyright (C) 2017-2023 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import chelper
|
||||
|
||||
PIN_MIN_TIME = 0.100
|
||||
RESEND_HOST_TIME = 0.300 + PIN_MIN_TIME
|
||||
MAX_SCHEDULE_TIME = 5.0
|
||||
|
||||
class error(Exception):
|
||||
pass
|
||||
|
||||
class MCU_queued_pwm:
|
||||
def __init__(self, pin_params):
|
||||
self._mcu = pin_params['chip']
|
||||
self._hardware_pwm = False
|
||||
self._cycle_time = 0.100
|
||||
self._max_duration = 2.
|
||||
self._oid = self._mcu.create_oid()
|
||||
ffi_main, ffi_lib = chelper.get_ffi()
|
||||
self._stepqueue = ffi_main.gc(ffi_lib.stepcompress_alloc(self._oid),
|
||||
ffi_lib.stepcompress_free)
|
||||
self._mcu.register_stepqueue(self._stepqueue)
|
||||
self._stepcompress_queue_mq_msg = ffi_lib.stepcompress_queue_mq_msg
|
||||
self._mcu.register_config_callback(self._build_config)
|
||||
self._pin = pin_params['pin']
|
||||
self._invert = pin_params['invert']
|
||||
self._start_value = self._shutdown_value = float(self._invert)
|
||||
self._last_clock = self._cycle_ticks = 0
|
||||
self._pwm_max = 0.
|
||||
self._set_cmd_tag = None
|
||||
def get_mcu(self):
|
||||
return self._mcu
|
||||
def setup_max_duration(self, max_duration):
|
||||
self._max_duration = max_duration
|
||||
def setup_cycle_time(self, cycle_time, hardware_pwm=False):
|
||||
self._cycle_time = cycle_time
|
||||
self._hardware_pwm = hardware_pwm
|
||||
def setup_start_value(self, start_value, shutdown_value):
|
||||
if self._invert:
|
||||
start_value = 1. - start_value
|
||||
shutdown_value = 1. - shutdown_value
|
||||
self._start_value = max(0., min(1., start_value))
|
||||
self._shutdown_value = max(0., min(1., shutdown_value))
|
||||
def _build_config(self):
|
||||
if self._max_duration and self._start_value != self._shutdown_value:
|
||||
raise pins.error("Pin with max duration must have start"
|
||||
" value equal to shutdown value")
|
||||
cmd_queue = self._mcu.alloc_command_queue()
|
||||
curtime = self._mcu.get_printer().get_reactor().monotonic()
|
||||
printtime = self._mcu.estimated_print_time(curtime)
|
||||
self._last_clock = self._mcu.print_time_to_clock(printtime + 0.200)
|
||||
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
||||
mdur_ticks = self._mcu.seconds_to_clock(self._max_duration)
|
||||
if mdur_ticks >= 1<<31:
|
||||
raise pins.error("PWM pin max duration too large")
|
||||
if self._hardware_pwm:
|
||||
self._pwm_max = self._mcu.get_constant_float("PWM_MAX")
|
||||
self._mcu.add_config_cmd(
|
||||
"config_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
|
||||
" default_value=%d max_duration=%d"
|
||||
% (self._oid, self._pin, cycle_ticks,
|
||||
self._start_value * self._pwm_max,
|
||||
self._shutdown_value * self._pwm_max, mdur_ticks))
|
||||
svalue = int(self._start_value * self._pwm_max + 0.5)
|
||||
self._mcu.add_config_cmd("queue_pwm_out oid=%d clock=%d value=%d"
|
||||
% (self._oid, self._last_clock, svalue),
|
||||
on_restart=True)
|
||||
self._set_cmd_tag = self._mcu.lookup_command(
|
||||
"queue_pwm_out oid=%c clock=%u value=%hu",
|
||||
cq=cmd_queue).get_command_tag()
|
||||
return
|
||||
# Software PWM
|
||||
if self._shutdown_value not in [0., 1.]:
|
||||
raise pins.error("shutdown value must be 0.0 or 1.0 on soft pwm")
|
||||
if cycle_ticks >= 1<<31:
|
||||
raise pins.error("PWM pin cycle time too large")
|
||||
self._mcu.add_config_cmd(
|
||||
"config_digital_out oid=%d pin=%s value=%d"
|
||||
" default_value=%d max_duration=%d"
|
||||
% (self._oid, self._pin, self._start_value >= 1.0,
|
||||
self._shutdown_value >= 0.5, mdur_ticks))
|
||||
self._mcu.add_config_cmd(
|
||||
"set_digital_out_pwm_cycle oid=%d cycle_ticks=%d"
|
||||
% (self._oid, cycle_ticks))
|
||||
self._cycle_ticks = cycle_ticks
|
||||
svalue = int(self._start_value * cycle_ticks + 0.5)
|
||||
self._mcu.add_config_cmd(
|
||||
"queue_digital_out oid=%d clock=%d on_ticks=%d"
|
||||
% (self._oid, self._last_clock, svalue), is_init=True)
|
||||
self._set_cmd_tag = self._mcu.lookup_command(
|
||||
"queue_digital_out oid=%c clock=%u on_ticks=%u",
|
||||
cq=cmd_queue).get_command_tag()
|
||||
def set_pwm(self, print_time, value):
|
||||
clock = self._mcu.print_time_to_clock(print_time)
|
||||
minclock = self._last_clock
|
||||
self._last_clock = clock
|
||||
if self._invert:
|
||||
value = 1. - value
|
||||
max_count = self._cycle_ticks
|
||||
if self._hardware_pwm:
|
||||
max_count = self._pwm_max
|
||||
v = int(max(0., min(1., value)) * max_count + 0.5)
|
||||
data = (self._set_cmd_tag, self._oid, clock, v)
|
||||
ret = self._stepcompress_queue_mq_msg(self._stepqueue, clock,
|
||||
data, len(data))
|
||||
if ret:
|
||||
raise error("Internal error in stepcompress")
|
||||
|
||||
class PrinterOutputPin:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
ppins = self.printer.lookup_object('pins')
|
||||
# Determine pin type
|
||||
pin_params = ppins.lookup_pin(config.get('pin'), can_invert=True)
|
||||
self.mcu_pin = MCU_queued_pwm(pin_params)
|
||||
cycle_time = config.getfloat('cycle_time', 0.100, above=0.,
|
||||
maxval=MAX_SCHEDULE_TIME)
|
||||
hardware_pwm = config.getboolean('hardware_pwm', False)
|
||||
self.mcu_pin.setup_cycle_time(cycle_time, hardware_pwm)
|
||||
self.scale = config.getfloat('scale', 1., above=0.)
|
||||
self.last_print_time = 0.
|
||||
# Support mcu checking for maximum duration
|
||||
self.reactor = self.printer.get_reactor()
|
||||
self.resend_timer = None
|
||||
self.resend_interval = 0.
|
||||
max_mcu_duration = config.getfloat('maximum_mcu_duration', 0.,
|
||||
minval=0.500,
|
||||
maxval=MAX_SCHEDULE_TIME)
|
||||
self.mcu_pin.setup_max_duration(max_mcu_duration)
|
||||
if max_mcu_duration:
|
||||
self.resend_interval = max_mcu_duration - RESEND_HOST_TIME
|
||||
# Determine start and shutdown values
|
||||
self.last_value = config.getfloat(
|
||||
'value', 0., minval=0., maxval=self.scale) / self.scale
|
||||
self.shutdown_value = config.getfloat(
|
||||
'shutdown_value', 0., minval=0., maxval=self.scale) / self.scale
|
||||
self.mcu_pin.setup_start_value(self.last_value, self.shutdown_value)
|
||||
# Register commands
|
||||
pin_name = config.get_name().split()[1]
|
||||
gcode = self.printer.lookup_object('gcode')
|
||||
gcode.register_mux_command("SET_PIN", "PIN", pin_name,
|
||||
self.cmd_SET_PIN,
|
||||
desc=self.cmd_SET_PIN_help)
|
||||
def get_status(self, eventtime):
|
||||
return {'value': self.last_value}
|
||||
def _set_pin(self, print_time, value, is_resend=False):
|
||||
if value == self.last_value and not is_resend:
|
||||
return
|
||||
print_time = max(print_time, self.last_print_time)
|
||||
self.mcu_pin.set_pwm(print_time, value)
|
||||
self.last_value = value
|
||||
self.last_print_time = print_time
|
||||
if self.resend_interval and self.resend_timer is None:
|
||||
self.resend_timer = self.reactor.register_timer(
|
||||
self._resend_current_val, self.reactor.NOW)
|
||||
cmd_SET_PIN_help = "Set the value of an output pin"
|
||||
def cmd_SET_PIN(self, gcmd):
|
||||
# Read requested value
|
||||
value = gcmd.get_float('VALUE', minval=0., maxval=self.scale)
|
||||
value /= self.scale
|
||||
# Obtain print_time and apply requested settings
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
toolhead.register_lookahead_callback(
|
||||
lambda print_time: self._set_pin(print_time, value))
|
||||
def _resend_current_val(self, eventtime):
|
||||
if self.last_value == self.shutdown_value:
|
||||
self.reactor.unregister_timer(self.resend_timer)
|
||||
self.resend_timer = None
|
||||
return self.reactor.NEVER
|
||||
|
||||
systime = self.reactor.monotonic()
|
||||
print_time = self.mcu_pin.get_mcu().estimated_print_time(systime)
|
||||
time_diff = (self.last_print_time + self.resend_interval) - print_time
|
||||
if time_diff > 0.:
|
||||
# Reschedule for resend time
|
||||
return systime + time_diff
|
||||
self._set_pin(print_time + PIN_MIN_TIME, self.last_value, True)
|
||||
# Make sure move queue updates get flushed
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
toolhead.note_move_queue_activity(print_time)
|
||||
return systime + self.resend_interval
|
||||
|
||||
def load_config_prefix(config):
|
||||
return PrinterOutputPin(config)
|
||||
@@ -320,9 +320,10 @@ class MAX31865(SensorBase):
|
||||
def calc_adc(self, temp):
|
||||
# Calculate relative resistance via Callendar-Van Dusen formula:
|
||||
# resistance = rtd_nominal_r * (1 + CVD_A * temp + CVD_B * temp**2)
|
||||
temp = min(temp, 1768.3) # Melting point of platinum
|
||||
R_div_nominal = 1. + CVD_A * temp + CVD_B * temp * temp
|
||||
adc = int(R_div_nominal / self.adc_to_resist_div_nominal + 0.5)
|
||||
adc = max(0, min(MAX31865_ADC_MAX, adc))
|
||||
adc = max(0, min(MAX31865_ADC_MAX - 1, adc))
|
||||
adc = adc << 1 # Add fault bit
|
||||
return adc
|
||||
def build_spi_init(self, config):
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import math, logging
|
||||
from . import bus, tmc, tmc2130
|
||||
from . import bus, tmc, tmc2130, tmc_uart
|
||||
|
||||
TMC_FREQUENCY=12500000.
|
||||
|
||||
@@ -343,8 +343,14 @@ class TMC2240:
|
||||
def __init__(self, config):
|
||||
# Setup mcu communication
|
||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields,
|
||||
TMC_FREQUENCY)
|
||||
if config.get("uart_pin", None) is not None:
|
||||
# use UART for communication
|
||||
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields,
|
||||
3, TMC_FREQUENCY)
|
||||
else:
|
||||
# Use SPI bus for communication
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields,
|
||||
TMC_FREQUENCY)
|
||||
# Allow virtual pins to be created
|
||||
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||
# Register commands
|
||||
|
||||
@@ -30,7 +30,8 @@ class CartKinematics:
|
||||
self.rails[3].setup_itersolve('cartesian_stepper_alloc',
|
||||
dc_axis.encode())
|
||||
dc_rail_0 = idex_modes.DualCarriagesRail(
|
||||
self.rails[0], axis=self.dual_carriage_axis, active=True)
|
||||
self.rails[self.dual_carriage_axis],
|
||||
axis=self.dual_carriage_axis, active=True)
|
||||
dc_rail_1 = idex_modes.DualCarriagesRail(
|
||||
self.rails[3], axis=self.dual_carriage_axis, active=False)
|
||||
self.dc_module = idex_modes.DualCarriages(
|
||||
|
||||
@@ -65,7 +65,13 @@ class DualCarriages:
|
||||
kin.update_limits(self.axis, target_dc.get_rail().get_range())
|
||||
def home(self, homing_state):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
for i, dc_rail in enumerate(self.dc):
|
||||
enumerated_dcs = list(enumerate(self.dc))
|
||||
if (self.get_dc_order(0, 1) > 0) != \
|
||||
self.dc[0].get_rail().get_homing_info().positive_dir:
|
||||
# The second carriage must home first, because the carriages home in
|
||||
# the same direction and the first carriage homes on the second one
|
||||
enumerated_dcs.reverse()
|
||||
for i, dc_rail in enumerated_dcs:
|
||||
self.toggle_active_dc_rail(i, override_rail=True)
|
||||
kin.home_axis(homing_state, self.axis, dc_rail.get_rail())
|
||||
# Restore the original rails ordering
|
||||
@@ -78,9 +84,15 @@ class DualCarriages:
|
||||
axes_pos = [dc.get_axis_position(pos) for dc in self.dc]
|
||||
dc0_rail = self.dc[0].get_rail()
|
||||
dc1_rail = self.dc[1].get_rail()
|
||||
range_min = dc0_rail.position_min
|
||||
range_max = dc0_rail.position_max
|
||||
if mode != PRIMARY or self.dc[0].is_active():
|
||||
range_min = dc0_rail.position_min
|
||||
range_max = dc0_rail.position_max
|
||||
else:
|
||||
range_min = dc1_rail.position_min
|
||||
range_max = dc1_rail.position_max
|
||||
safe_dist = self.safe_dist
|
||||
if not safe_dist:
|
||||
return (range_min, range_max)
|
||||
|
||||
if mode == COPY:
|
||||
range_min = max(range_min,
|
||||
@@ -88,7 +100,7 @@ class DualCarriages:
|
||||
range_max = min(range_max,
|
||||
axes_pos[0] - axes_pos[1] + dc1_rail.position_max)
|
||||
elif mode == MIRROR:
|
||||
if dc0_rail.get_homing_info().positive_dir:
|
||||
if self.get_dc_order(0, 1) > 0:
|
||||
range_min = max(range_min,
|
||||
0.5 * (sum(axes_pos) + safe_dist))
|
||||
range_max = min(range_max,
|
||||
@@ -102,14 +114,39 @@ class DualCarriages:
|
||||
# mode == PRIMARY
|
||||
active_idx = 1 if self.dc[1].is_active() else 0
|
||||
inactive_idx = 1 - active_idx
|
||||
if active_idx:
|
||||
range_min = dc1_rail.position_min
|
||||
range_max = dc1_rail.position_max
|
||||
if self.dc[active_idx].get_rail().get_homing_info().positive_dir:
|
||||
if self.get_dc_order(active_idx, inactive_idx) > 0:
|
||||
range_min = max(range_min, axes_pos[inactive_idx] + safe_dist)
|
||||
else:
|
||||
range_max = min(range_max, axes_pos[inactive_idx] - safe_dist)
|
||||
if range_min > range_max:
|
||||
# During multi-MCU homing it is possible that the carriage
|
||||
# position will end up below position_min or above position_max
|
||||
# if position_endstop is too close to the rail motion ends due
|
||||
# to inherent latencies of the data transmission between MCUs.
|
||||
# This can result in an invalid range_min > range_max range
|
||||
# in certain modes, which may confuse the kinematics code.
|
||||
# So, return an empty range instead, which will correctly
|
||||
# block the carriage motion until a different mode is selected
|
||||
# which actually permits carriage motion.
|
||||
return (range_min, range_min)
|
||||
return (range_min, range_max)
|
||||
def get_dc_order(self, first, second):
|
||||
if first == second:
|
||||
return 0
|
||||
# Check the relative order of the first and second carriages and
|
||||
# return -1 if the first carriage position is always smaller
|
||||
# than the second one and 1 otherwise
|
||||
first_rail = self.dc[first].get_rail()
|
||||
second_rail = self.dc[second].get_rail()
|
||||
first_homing_info = first_rail.get_homing_info()
|
||||
second_homing_info = second_rail.get_homing_info()
|
||||
if first_homing_info.positive_dir != second_homing_info.positive_dir:
|
||||
# Carriages home away from each other
|
||||
return 1 if first_homing_info.positive_dir else -1
|
||||
# Carriages home in the same direction
|
||||
if first_rail.position_endstop > second_rail.position_endstop:
|
||||
return 1
|
||||
return -1
|
||||
def activate_dc_mode(self, index, mode):
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
toolhead.flush_step_generation()
|
||||
|
||||
+4
-2
@@ -25,14 +25,16 @@ class RetryAsyncCommand:
|
||||
self.reactor = serial.get_reactor()
|
||||
self.completion = self.reactor.completion()
|
||||
self.min_query_time = self.reactor.monotonic()
|
||||
self.need_response = True
|
||||
self.serial.register_response(self.handle_callback, name, oid)
|
||||
def handle_callback(self, params):
|
||||
if params['#sent_time'] >= self.min_query_time:
|
||||
self.min_query_time = self.reactor.NEVER
|
||||
if self.need_response and params['#sent_time'] >= self.min_query_time:
|
||||
self.need_response = False
|
||||
self.reactor.async_complete(self.completion, params)
|
||||
def get_response(self, cmds, cmd_queue, minclock=0, reqclock=0):
|
||||
cmd, = cmds
|
||||
self.serial.raw_send_wait_ack(cmd, minclock, reqclock, cmd_queue)
|
||||
self.min_query_time = 0.
|
||||
first_query_time = query_time = self.reactor.monotonic()
|
||||
while 1:
|
||||
params = self.completion.wait(query_time + self.RETRY_TIME)
|
||||
|
||||
@@ -543,6 +543,14 @@ class ToolHead:
|
||||
last_move.timing_callbacks.append(callback)
|
||||
def note_kinematic_activity(self, kin_time):
|
||||
self.last_kin_move_time = max(self.last_kin_move_time, kin_time)
|
||||
def note_move_queue_activity(self, mq_time):
|
||||
if self.special_queuing_state == "Flushed":
|
||||
# Must manually flush move queue buffers
|
||||
for m in self.all_mcus:
|
||||
m.flush_moves(mq_time)
|
||||
else:
|
||||
# Move queue will get flushed via regular toolhead flushing
|
||||
self.last_kin_move_time = max(self.last_kin_move_time, mq_time)
|
||||
def get_max_velocity(self):
|
||||
return self.max_velocity, self.max_accel
|
||||
def _calc_junction_deviation(self):
|
||||
|
||||
+1
-1
@@ -167,7 +167,7 @@ used to upload firmware to devices flashed with the CanBoot bootloader.
|
||||
|
||||
The can2040 directory contains code from:
|
||||
https://github.com/KevinOConnor/can2040
|
||||
revision d1190afcaa6245c20da28199d06e453d2e743099.
|
||||
version v1.6.0 (af3d21e5d61b8408c63fbdfb0aceb21d69d91693)
|
||||
|
||||
The Huada HC32F460 directory contains code from:
|
||||
https://www.hdsc.com.cn/Category83-1490
|
||||
|
||||
+72
-25
@@ -1,6 +1,6 @@
|
||||
// Software CANbus implementation for rp2040
|
||||
//
|
||||
// Copyright (C) 2022 Kevin O'Connor <kevin@koconnor.net>
|
||||
// Copyright (C) 2022,2023 Kevin O'Connor <kevin@koconnor.net>
|
||||
//
|
||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
@@ -318,6 +318,14 @@ pio_irq_set(struct can2040 *cd, uint32_t sm_irqs)
|
||||
pio_hw->inte0 = sm_irqs | SI_RX_DATA;
|
||||
}
|
||||
|
||||
// Completely disable host irqs
|
||||
static void
|
||||
pio_irq_disable(struct can2040 *cd)
|
||||
{
|
||||
pio_hw_t *pio_hw = cd->pio_hw;
|
||||
pio_hw->inte0 = 0;
|
||||
}
|
||||
|
||||
// Return current host irq mask
|
||||
static uint32_t
|
||||
pio_irq_get(struct can2040 *cd)
|
||||
@@ -662,6 +670,7 @@ tx_schedule_transmit(struct can2040 *cd)
|
||||
pio_signal_set_txpending(cd);
|
||||
}
|
||||
cd->tx_state = TS_QUEUED;
|
||||
cd->stats.tx_attempt++;
|
||||
struct can2040_transmit *qt = &cd->tx_queue[tx_qpos(cd, tx_pull_pos)];
|
||||
pio_tx_send(cd, qt->stuffed_data, qt->stuffed_words);
|
||||
return 0;
|
||||
@@ -721,6 +730,7 @@ report_callback_error(struct can2040 *cd, uint32_t error_code)
|
||||
static void
|
||||
report_callback_rx_msg(struct can2040 *cd)
|
||||
{
|
||||
cd->stats.rx_total++;
|
||||
cd->rx_cb(cd, CAN2040_NOTIFY_RX, &cd->parse_msg);
|
||||
}
|
||||
|
||||
@@ -729,6 +739,7 @@ static void
|
||||
report_callback_tx_msg(struct can2040 *cd)
|
||||
{
|
||||
writel(&cd->tx_pull_pos, cd->tx_pull_pos + 1);
|
||||
cd->stats.tx_total++;
|
||||
cd->rx_cb(cd, CAN2040_NOTIFY_TX, &cd->parse_msg);
|
||||
}
|
||||
|
||||
@@ -748,11 +759,11 @@ report_handle_eof(struct can2040 *cd)
|
||||
pio_match_clear(cd);
|
||||
}
|
||||
|
||||
// Check if in an rx message is being processed
|
||||
// Check if message being processed is an rx message (not self feedback from tx)
|
||||
static int
|
||||
report_is_rx_eof_pending(struct can2040 *cd)
|
||||
report_is_not_in_tx(struct can2040 *cd)
|
||||
{
|
||||
return cd->report_state == RS_NEED_RX_EOF;
|
||||
return !(cd->report_state & RS_NEED_TX_ACK);
|
||||
}
|
||||
|
||||
// Parser found a new message start
|
||||
@@ -817,7 +828,7 @@ report_note_eof_success(struct can2040 *cd)
|
||||
|
||||
// Parser found unexpected data on input
|
||||
static void
|
||||
report_note_parse_error(struct can2040 *cd)
|
||||
report_note_discarding(struct can2040 *cd)
|
||||
{
|
||||
if (cd->report_state != RS_IDLE) {
|
||||
cd->report_state = RS_IDLE;
|
||||
@@ -880,7 +891,7 @@ report_line_txpending(struct can2040 *cd)
|
||||
return;
|
||||
}
|
||||
// Tx request from can2040_transmit(), report_note_eof_success(),
|
||||
// or report_note_parse_error().
|
||||
// or report_note_discarding().
|
||||
uint32_t check_txpending = tx_schedule_transmit(cd);
|
||||
pio_irq_set(cd, (pio_irqs & ~SI_TXPENDING) | check_txpending);
|
||||
}
|
||||
@@ -896,6 +907,13 @@ enum {
|
||||
MS_CRC, MS_ACK, MS_EOF0, MS_EOF1, MS_DISCARD
|
||||
};
|
||||
|
||||
// Reset any bits in the incoming parsing state
|
||||
static void
|
||||
data_state_clear_bits(struct can2040 *cd)
|
||||
{
|
||||
cd->raw_bit_count = cd->unstuf.stuffed_bits = cd->unstuf.count_stuff = 0;
|
||||
}
|
||||
|
||||
// Transition to the next parsing state
|
||||
static void
|
||||
data_state_go_next(struct can2040 *cd, uint32_t state, uint32_t num_bits)
|
||||
@@ -908,23 +926,35 @@ data_state_go_next(struct can2040 *cd, uint32_t state, uint32_t num_bits)
|
||||
static void
|
||||
data_state_go_discard(struct can2040 *cd)
|
||||
{
|
||||
report_note_parse_error(cd);
|
||||
|
||||
if (pio_rx_check_stall(cd)) {
|
||||
// CPU couldn't keep up for some read data - must reset pio state
|
||||
cd->raw_bit_count = cd->unstuf.count_stuff = 0;
|
||||
data_state_clear_bits(cd);
|
||||
pio_sm_setup(cd);
|
||||
report_callback_error(cd, 0);
|
||||
}
|
||||
|
||||
data_state_go_next(cd, MS_DISCARD, 32);
|
||||
|
||||
// Clear report state and update hw irqs after transition to MS_DISCARD
|
||||
report_note_discarding(cd);
|
||||
}
|
||||
|
||||
// Note a data parse error and transition to discard state
|
||||
static void
|
||||
data_state_go_error(struct can2040 *cd)
|
||||
{
|
||||
cd->stats.parse_error++;
|
||||
data_state_go_discard(cd);
|
||||
}
|
||||
|
||||
// Received six dominant bits on the line
|
||||
static void
|
||||
data_state_line_error(struct can2040 *cd)
|
||||
{
|
||||
data_state_go_discard(cd);
|
||||
if (cd->parse_state == MS_DISCARD)
|
||||
data_state_go_discard(cd);
|
||||
else
|
||||
data_state_go_error(cd);
|
||||
}
|
||||
|
||||
// Received six unexpected passive bits on the line
|
||||
@@ -933,7 +963,7 @@ data_state_line_passive(struct can2040 *cd)
|
||||
{
|
||||
if (cd->parse_state != MS_DISCARD && cd->parse_state != MS_START) {
|
||||
// Bitstuff error
|
||||
data_state_go_discard(cd);
|
||||
data_state_go_error(cd);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -941,8 +971,7 @@ data_state_line_passive(struct can2040 *cd)
|
||||
uint32_t dom_bits = ~stuffed_bits;
|
||||
if (!dom_bits) {
|
||||
// Counter overflow in "sync" state machine - reset it
|
||||
cd->unstuf.stuffed_bits = 0;
|
||||
cd->raw_bit_count = cd->unstuf.count_stuff = 0;
|
||||
data_state_clear_bits(cd);
|
||||
pio_sm_setup(cd);
|
||||
data_state_go_discard(cd);
|
||||
return;
|
||||
@@ -972,7 +1001,7 @@ data_state_go_crc(struct can2040 *cd)
|
||||
|
||||
int ret = report_note_crc_start(cd);
|
||||
if (ret) {
|
||||
data_state_go_discard(cd);
|
||||
data_state_go_error(cd);
|
||||
return;
|
||||
}
|
||||
data_state_go_next(cd, MS_CRC, 16);
|
||||
@@ -1065,7 +1094,7 @@ static void
|
||||
data_state_update_crc(struct can2040 *cd, uint32_t data)
|
||||
{
|
||||
if (((cd->parse_crc << 1) | 1) != data) {
|
||||
data_state_go_discard(cd);
|
||||
data_state_go_error(cd);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1083,7 +1112,7 @@ data_state_update_ack(struct can2040 *cd, uint32_t data)
|
||||
// data_state_line_passive()
|
||||
unstuf_restore_state(&cd->unstuf, (cd->parse_crc_bits << 2) | data);
|
||||
|
||||
data_state_go_discard(cd);
|
||||
data_state_go_error(cd);
|
||||
return;
|
||||
}
|
||||
report_note_ack_success(cd);
|
||||
@@ -1095,7 +1124,7 @@ static void
|
||||
data_state_update_eof0(struct can2040 *cd, uint32_t data)
|
||||
{
|
||||
if (data != 0x0f || pio_rx_check_stall(cd)) {
|
||||
data_state_go_discard(cd);
|
||||
data_state_go_error(cd);
|
||||
return;
|
||||
}
|
||||
unstuf_clear_state(&cd->unstuf);
|
||||
@@ -1106,14 +1135,17 @@ data_state_update_eof0(struct can2040 *cd, uint32_t data)
|
||||
static void
|
||||
data_state_update_eof1(struct can2040 *cd, uint32_t data)
|
||||
{
|
||||
if (data >= 0x1c || (data >= 0x18 && report_is_rx_eof_pending(cd)))
|
||||
// Message is considered fully transmitted
|
||||
if (data == 0x1f) {
|
||||
// Success
|
||||
report_note_eof_success(cd);
|
||||
|
||||
if (data == 0x1f)
|
||||
data_state_go_next(cd, MS_START, 1);
|
||||
else
|
||||
} else if (data >= 0x1c || (data >= 0x18 && report_is_not_in_tx(cd))) {
|
||||
// Message fully transmitted - followed by "overload frame"
|
||||
report_note_eof_success(cd);
|
||||
data_state_go_discard(cd);
|
||||
} else {
|
||||
data_state_go_error(cd);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle data received while in MS_DISCARD state
|
||||
@@ -1310,13 +1342,28 @@ can2040_start(struct can2040 *cd, uint32_t sys_clock, uint32_t bitrate
|
||||
{
|
||||
cd->gpio_rx = gpio_rx;
|
||||
cd->gpio_tx = gpio_tx;
|
||||
data_state_clear_bits(cd);
|
||||
pio_setup(cd, sys_clock, bitrate);
|
||||
data_state_go_discard(cd);
|
||||
}
|
||||
|
||||
// API function to stop and uninitialize can2040 code
|
||||
// API function to stop can2040 code
|
||||
void
|
||||
can2040_shutdown(struct can2040 *cd)
|
||||
can2040_stop(struct can2040 *cd)
|
||||
{
|
||||
// XXX
|
||||
pio_irq_disable(cd);
|
||||
pio_sm_setup(cd);
|
||||
}
|
||||
|
||||
// API function to access can2040 statistics
|
||||
void
|
||||
can2040_get_statistics(struct can2040 *cd, struct can2040_stats *stats)
|
||||
{
|
||||
for (;;) {
|
||||
memcpy(stats, &cd->stats, sizeof(*stats));
|
||||
if (memcmp(stats, &cd->stats, sizeof(*stats)) == 0)
|
||||
// Successfully copied data
|
||||
return;
|
||||
// Raced with irq handler update - retry copy
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,18 @@ struct can2040;
|
||||
typedef void (*can2040_rx_cb)(struct can2040 *cd, uint32_t notify
|
||||
, struct can2040_msg *msg);
|
||||
|
||||
struct can2040_stats {
|
||||
uint32_t rx_total, tx_total;
|
||||
uint32_t tx_attempt;
|
||||
uint32_t parse_error;
|
||||
};
|
||||
|
||||
void can2040_setup(struct can2040 *cd, uint32_t pio_num);
|
||||
void can2040_callback_config(struct can2040 *cd, can2040_rx_cb rx_cb);
|
||||
void can2040_start(struct can2040 *cd, uint32_t sys_clock, uint32_t bitrate
|
||||
, uint32_t gpio_rx, uint32_t gpio_tx);
|
||||
void can2040_shutdown(struct can2040 *cd);
|
||||
void can2040_stop(struct can2040 *cd);
|
||||
void can2040_get_statistics(struct can2040 *cd, struct can2040_stats *stats);
|
||||
void can2040_pio_irq_handler(struct can2040 *cd);
|
||||
int can2040_check_transmit(struct can2040 *cd);
|
||||
int can2040_transmit(struct can2040 *cd, struct can2040_msg *msg);
|
||||
@@ -56,6 +63,7 @@ struct can2040 {
|
||||
void *pio_hw;
|
||||
uint32_t gpio_rx, gpio_tx;
|
||||
can2040_rx_cb rx_cb;
|
||||
struct can2040_stats stats;
|
||||
|
||||
// Bit unstuffing
|
||||
struct can2040_bitunstuffer unstuf;
|
||||
|
||||
@@ -344,8 +344,8 @@ MCUTYPES = {
|
||||
'samd': flash_atsamd, 'same5': flash_atsamd,
|
||||
'lpc176': flash_lpc176x, 'stm32f103': flash_stm32f1,
|
||||
'stm32f4': flash_stm32f4, 'stm32f042': flash_stm32f4,
|
||||
'stm32f072': flash_stm32f4, 'stm32g0b1': flash_stm32f4,
|
||||
'stm32f7': flash_stm32f4,
|
||||
'stm32f070': flash_stm32f4, 'stm32f072': flash_stm32f4,
|
||||
'stm32g0b1': flash_stm32f4, 'stm32f7': flash_stm32f4,
|
||||
'stm32h7': flash_stm32f4, 'stm32l4': flash_stm32f4,
|
||||
'stm32g4': flash_stm32f4, 'rp2040': flash_rp2040,
|
||||
}
|
||||
|
||||
@@ -166,6 +166,7 @@ BOARD_ALIASES = {
|
||||
'btt-octopus-f446-v1.1': BOARD_DEFS['btt-octopus-f446-v1'],
|
||||
'btt-octopus-pro-f429-v1.0': BOARD_DEFS['btt-octopus-f429-v1'],
|
||||
'btt-octopus-pro-f446-v1.0': BOARD_DEFS['btt-octopus-f446-v1'],
|
||||
'btt-octopus-pro-h723-v1.1': BOARD_DEFS['btt-skr-3-h723'],
|
||||
'btt-skr-pro-v1.1': BOARD_DEFS['btt-skr-pro'],
|
||||
'btt-skr-pro-v1.2': BOARD_DEFS['btt-skr-pro'],
|
||||
'btt-gtr-v1': BOARD_DEFS['btt-gtr'],
|
||||
|
||||
@@ -100,6 +100,10 @@ config WANT_SENSORS
|
||||
bool
|
||||
depends on HAVE_GPIO_I2C || HAVE_GPIO_SPI
|
||||
default y
|
||||
config WANT_LIS2DW
|
||||
bool
|
||||
depends on HAVE_GPIO_SPI
|
||||
default y
|
||||
config WANT_SOFTWARE_I2C
|
||||
bool
|
||||
depends on HAVE_GPIO && HAVE_GPIO_I2C
|
||||
@@ -119,6 +123,9 @@ config WANT_DISPLAYS
|
||||
config WANT_SENSORS
|
||||
bool "Support external sensor devices"
|
||||
depends on HAVE_GPIO_I2C || HAVE_GPIO_SPI
|
||||
config WANT_LIS2DW
|
||||
bool "Support lis2dw 3-axis accelerometer"
|
||||
depends on HAVE_GPIO_SPI
|
||||
config WANT_SOFTWARE_I2C
|
||||
bool "Support software based I2C \"bit-banging\""
|
||||
depends on HAVE_GPIO && HAVE_GPIO_I2C
|
||||
|
||||
@@ -16,5 +16,6 @@ src-$(CONFIG_WANT_SOFTWARE_SPI) += spi_software.c
|
||||
src-$(CONFIG_WANT_SOFTWARE_I2C) += i2c_software.c
|
||||
sensors-src-$(CONFIG_HAVE_GPIO_SPI) := thermocouple.c sensor_adxl345.c \
|
||||
sensor_angle.c
|
||||
src-$(CONFIG_WANT_LIS2DW) += sensor_lis2dw.c
|
||||
sensors-src-$(CONFIG_HAVE_GPIO_I2C) += sensor_mpu9250.c
|
||||
src-$(CONFIG_WANT_SENSORS) += $(sensors-src-y)
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef __SAM3_USB_CDC_EP_H
|
||||
#define __SAM3_USB_CDC_EP_H
|
||||
|
||||
enum {
|
||||
USB_CDC_EP_ACM = 3,
|
||||
USB_CDC_EP_BULK_OUT = 1,
|
||||
USB_CDC_EP_BULK_IN = 2,
|
||||
};
|
||||
|
||||
#endif // usb_cdc_ep.h
|
||||
+56
-31
@@ -104,20 +104,18 @@ struct gs_host_frame {
|
||||
static struct usbcan_data {
|
||||
struct task_wake wake;
|
||||
|
||||
// Canbus data from host
|
||||
union {
|
||||
struct gs_host_frame host_frame;
|
||||
uint8_t rx_frame_pad[USB_CDC_EP_BULK_OUT_SIZE];
|
||||
};
|
||||
uint8_t host_status;
|
||||
|
||||
// Canbus data routed locally
|
||||
uint8_t notify_local, usb_send_busy;
|
||||
uint32_t assigned_id;
|
||||
|
||||
// Canbus data from host
|
||||
uint8_t host_status;
|
||||
uint32_t host_pull_pos, host_push_pos;
|
||||
struct gs_host_frame host_frames[16];
|
||||
|
||||
// Data from physical canbus interface
|
||||
uint32_t pull_pos, push_pos;
|
||||
struct canbus_msg queue[32];
|
||||
uint32_t canhw_pull_pos, canhw_push_pos;
|
||||
struct canbus_msg canhw_queue[32];
|
||||
} UsbCan;
|
||||
|
||||
enum {
|
||||
@@ -139,16 +137,16 @@ void
|
||||
canbus_process_data(struct canbus_msg *msg)
|
||||
{
|
||||
// Add to admin command queue
|
||||
uint32_t pushp = UsbCan.push_pos;
|
||||
if (pushp - UsbCan.pull_pos >= ARRAY_SIZE(UsbCan.queue))
|
||||
uint32_t pushp = UsbCan.canhw_push_pos;
|
||||
if (pushp - UsbCan.canhw_pull_pos >= ARRAY_SIZE(UsbCan.canhw_queue))
|
||||
// No space - drop message
|
||||
return;
|
||||
if (UsbCan.assigned_id && (msg->id & ~1) == UsbCan.assigned_id)
|
||||
// Id reserved for local
|
||||
return;
|
||||
uint32_t pos = pushp % ARRAY_SIZE(UsbCan.queue);
|
||||
memcpy(&UsbCan.queue[pos], msg, sizeof(*msg));
|
||||
UsbCan.push_pos = pushp + 1;
|
||||
uint32_t pos = pushp % ARRAY_SIZE(UsbCan.canhw_queue);
|
||||
memcpy(&UsbCan.canhw_queue[pos], msg, sizeof(*msg));
|
||||
UsbCan.canhw_push_pos = pushp + 1;
|
||||
usb_notify_bulk_out();
|
||||
}
|
||||
|
||||
@@ -167,24 +165,43 @@ send_frame(struct canbus_msg *msg)
|
||||
|
||||
// Send any pending hw frames to host
|
||||
static void
|
||||
drain_hw_queue(void)
|
||||
drain_canhw_queue(void)
|
||||
{
|
||||
uint32_t pull_pos = UsbCan.pull_pos;
|
||||
uint32_t pull_pos = UsbCan.canhw_pull_pos;
|
||||
for (;;) {
|
||||
uint32_t push_pos = readl(&UsbCan.push_pos);
|
||||
uint32_t push_pos = readl(&UsbCan.canhw_push_pos);
|
||||
if (push_pos == pull_pos) {
|
||||
// No more data to send
|
||||
UsbCan.usb_send_busy = 0;
|
||||
return;
|
||||
}
|
||||
uint32_t pos = pull_pos % ARRAY_SIZE(UsbCan.queue);
|
||||
int ret = send_frame(&UsbCan.queue[pos]);
|
||||
uint32_t pos = pull_pos % ARRAY_SIZE(UsbCan.canhw_queue);
|
||||
int ret = send_frame(&UsbCan.canhw_queue[pos]);
|
||||
if (ret < 0) {
|
||||
// USB is busy - retry later
|
||||
UsbCan.usb_send_busy = 1;
|
||||
return;
|
||||
}
|
||||
UsbCan.pull_pos = pull_pos = pull_pos + 1;
|
||||
UsbCan.canhw_pull_pos = pull_pos = pull_pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Fill local queue with any USB messages sent from host
|
||||
static void
|
||||
fill_usb_host_queue(void)
|
||||
{
|
||||
uint32_t pull_pos = UsbCan.host_pull_pos, push_pos = UsbCan.host_push_pos;
|
||||
for (;;) {
|
||||
if (push_pos - pull_pos >= ARRAY_SIZE(UsbCan.host_frames))
|
||||
// No more space in queue
|
||||
break;
|
||||
uint32_t pushp = push_pos % ARRAY_SIZE(UsbCan.host_frames);
|
||||
struct gs_host_frame *gs = &UsbCan.host_frames[pushp];
|
||||
int ret = usb_read_bulk_out(gs, sizeof(*gs));
|
||||
if (ret <= 0)
|
||||
// No more messages ready
|
||||
break;
|
||||
UsbCan.host_push_pos = push_pos = push_pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,13 +212,19 @@ usbcan_task(void)
|
||||
return;
|
||||
|
||||
// Send any pending hw frames to host
|
||||
drain_hw_queue();
|
||||
drain_canhw_queue();
|
||||
|
||||
// Fill local queue with any USB messages arriving from host
|
||||
fill_usb_host_queue();
|
||||
|
||||
// Route messages received from host
|
||||
uint32_t pull_pos = UsbCan.host_pull_pos, push_pos = UsbCan.host_push_pos;
|
||||
uint32_t pullp = pull_pos % ARRAY_SIZE(UsbCan.host_frames);
|
||||
struct gs_host_frame *gs = &UsbCan.host_frames[pullp];
|
||||
for (;;) {
|
||||
// See if previous host frame needs to be transmitted
|
||||
uint_fast8_t host_status = UsbCan.host_status;
|
||||
if (host_status & (HS_TX_HW | HS_TX_LOCAL)) {
|
||||
struct gs_host_frame *gs = &UsbCan.host_frame;
|
||||
struct canbus_msg msg;
|
||||
msg.id = gs->can_id;
|
||||
msg.dlc = gs->can_dlc;
|
||||
@@ -221,23 +244,22 @@ usbcan_task(void)
|
||||
|
||||
// Send any previous echo frames
|
||||
if (host_status) {
|
||||
if (UsbCan.usb_send_busy)
|
||||
if (UsbCan.notify_local || UsbCan.usb_send_busy)
|
||||
// Don't send echo frame until other traffic is sent
|
||||
return;
|
||||
int ret = usb_send_bulk_in(&UsbCan.host_frame
|
||||
, sizeof(UsbCan.host_frame));
|
||||
break;
|
||||
int ret = usb_send_bulk_in(gs, sizeof(*gs));
|
||||
if (ret < 0)
|
||||
return;
|
||||
UsbCan.host_status = 0;
|
||||
UsbCan.host_pull_pos = pull_pos = pull_pos + 1;
|
||||
}
|
||||
|
||||
// Read next frame from host
|
||||
int ret = usb_read_bulk_out(&UsbCan.host_frame
|
||||
, USB_CDC_EP_BULK_OUT_SIZE);
|
||||
if (ret <= 0)
|
||||
// Process next frame from host
|
||||
if (pull_pos == push_pos)
|
||||
// No frame available - no more work to be done
|
||||
break;
|
||||
uint32_t id = UsbCan.host_frame.can_id;
|
||||
gs = &UsbCan.host_frames[pull_pos % ARRAY_SIZE(UsbCan.host_frames)];
|
||||
uint32_t id = gs->can_id;
|
||||
UsbCan.host_status = HS_TX_ECHO | HS_TX_HW;
|
||||
if (id == CANBUS_ID_ADMIN)
|
||||
UsbCan.host_status = HS_TX_ECHO | HS_TX_HW | HS_TX_LOCAL;
|
||||
@@ -245,6 +267,7 @@ usbcan_task(void)
|
||||
UsbCan.host_status = HS_TX_ECHO | HS_TX_LOCAL;
|
||||
}
|
||||
|
||||
// Wake up local message response handling (if usb is not busy)
|
||||
if (UsbCan.notify_local && !UsbCan.usb_send_busy)
|
||||
canserial_notify_tx();
|
||||
}
|
||||
@@ -258,6 +281,8 @@ canbus_send(struct canbus_msg *msg)
|
||||
int ret = send_frame(msg);
|
||||
if (ret < 0)
|
||||
goto retry_later;
|
||||
if (UsbCan.notify_local && UsbCan.host_status)
|
||||
canbus_notify_tx();
|
||||
UsbCan.notify_local = 0;
|
||||
return msg->dlc;
|
||||
retry_later:
|
||||
|
||||
@@ -51,16 +51,19 @@ config FLASH_SIZE
|
||||
|
||||
choice "Application Address"
|
||||
prompt "Application Address"
|
||||
config HC32F460_FLASH_APPLICATION_ADDRESS_0x8000
|
||||
bool "0x8000"
|
||||
config HC32F460_FLASH_APPLICATION_ADDRESS_0xC000
|
||||
bool "0xC000"
|
||||
config HC32F460_FLASH_APPLICATION_ADDRESS_0x008000
|
||||
bool "0x008000"
|
||||
config HC32F460_FLASH_APPLICATION_ADDRESS_0x00C000
|
||||
bool "0x00C000"
|
||||
config HC32F460_FLASH_APPLICATION_ADDRESS_0x010000
|
||||
bool "0x010000"
|
||||
endchoice
|
||||
|
||||
config FLASH_APPLICATION_ADDRESS
|
||||
hex
|
||||
default 0x8000 if HC32F460_FLASH_APPLICATION_ADDRESS_0x8000
|
||||
default 0xC000 if HC32F460_FLASH_APPLICATION_ADDRESS_0xC000
|
||||
default 0x008000 if HC32F460_FLASH_APPLICATION_ADDRESS_0x008000
|
||||
default 0x00C000 if HC32F460_FLASH_APPLICATION_ADDRESS_0x00C000
|
||||
default 0x010000 if HC32F460_FLASH_APPLICATION_ADDRESS_0x010000
|
||||
|
||||
config FLASH_BOOT_ADDRESS
|
||||
hex
|
||||
|
||||
+114
-41
@@ -1,6 +1,6 @@
|
||||
// Hardware interface to USB on rp2040
|
||||
//
|
||||
// Copyright (C) 2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
// Copyright (C) 2021-2023 Kevin O'Connor <kevin@koconnor.net>
|
||||
//
|
||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
@@ -26,52 +26,46 @@
|
||||
|
||||
#define DPBUF_SIZE 64
|
||||
|
||||
// Get the offset of a given endpoint's base buffer
|
||||
static uint32_t
|
||||
usb_buf_offset(uint32_t ep)
|
||||
{
|
||||
return 0x100 + ep * DPBUF_SIZE * 2;
|
||||
}
|
||||
|
||||
static int_fast8_t
|
||||
usb_write_packet(uint32_t ep, const void *data, uint_fast8_t len)
|
||||
// Obtain a pointer to an endpoint buffer
|
||||
static void*
|
||||
usb_buf_addr(uint32_t ep, int bufnum)
|
||||
{
|
||||
// Check if there is room for this packet
|
||||
uint32_t epb = usb_dpram->ep_buf_ctrl[ep].in;
|
||||
if (epb & (USB_BUF_CTRL_AVAIL|USB_BUF_CTRL_FULL))
|
||||
return -1;
|
||||
uint32_t pid = (epb ^ USB_BUF_CTRL_DATA1_PID) & USB_BUF_CTRL_DATA1_PID;
|
||||
uint32_t new_epb = USB_BUF_CTRL_FULL | USB_BUF_CTRL_LAST | pid | len;
|
||||
usb_dpram->ep_buf_ctrl[ep].in = new_epb;
|
||||
// Copy the packet to the hw buffer
|
||||
void *addr = (void*)usb_dpram + usb_buf_offset(ep);
|
||||
barrier();
|
||||
memcpy(addr, data, len);
|
||||
barrier();
|
||||
// Inform the USB hardware of the available packet
|
||||
usb_dpram->ep_buf_ctrl[ep].in = new_epb | USB_BUF_CTRL_AVAIL;
|
||||
return len;
|
||||
return (void*)usb_dpram + usb_buf_offset(ep) + bufnum * DPBUF_SIZE;
|
||||
}
|
||||
|
||||
static int_fast8_t
|
||||
usb_read_packet(uint32_t ep, void *data, uint_fast8_t max_len)
|
||||
// Return a pointer to the ep_buf_ctrl register for an endpoint
|
||||
static volatile uint16_t *
|
||||
lookup_epbufctrl(uint32_t ep, int is_rx, int bufnum)
|
||||
{
|
||||
volatile uint16_t *epbp;
|
||||
if (is_rx)
|
||||
epbp = (void*)&usb_dpram->ep_buf_ctrl[ep].out;
|
||||
else
|
||||
epbp = (void*)&usb_dpram->ep_buf_ctrl[ep].in;
|
||||
return &epbp[bufnum];
|
||||
}
|
||||
|
||||
// Determine the next transfer PID id from the last PID
|
||||
static uint32_t
|
||||
next_data_pid(uint32_t epb)
|
||||
{
|
||||
return (epb ^ USB_BUF_CTRL_DATA1_PID) & USB_BUF_CTRL_DATA1_PID;
|
||||
}
|
||||
|
||||
// Extract the number of bytes in an rx buffer
|
||||
static uint32_t
|
||||
get_rx_count(uint32_t epb, uint32_t max_len)
|
||||
{
|
||||
// Check if there is a packet ready
|
||||
uint32_t epb = usb_dpram->ep_buf_ctrl[ep].out;
|
||||
if ((epb & (USB_BUF_CTRL_AVAIL|USB_BUF_CTRL_FULL)) != USB_BUF_CTRL_FULL)
|
||||
return -1;
|
||||
// Copy the packet to the given buffer
|
||||
uint32_t pid = (epb ^ USB_BUF_CTRL_DATA1_PID) & USB_BUF_CTRL_DATA1_PID;
|
||||
uint32_t new_epb = USB_BUF_CTRL_LAST | pid | DPBUF_SIZE;
|
||||
usb_dpram->ep_buf_ctrl[ep].out = new_epb;
|
||||
uint32_t c = epb & USB_BUF_CTRL_LEN_MASK;
|
||||
if (c > max_len)
|
||||
c = max_len;
|
||||
void *addr = (void*)usb_dpram + usb_buf_offset(ep);
|
||||
barrier();
|
||||
memcpy(data, addr, c);
|
||||
barrier();
|
||||
// Notify the USB hardware that the space is now available
|
||||
usb_dpram->ep_buf_ctrl[ep].out = new_epb | USB_BUF_CTRL_AVAIL;
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -80,16 +74,57 @@ usb_read_packet(uint32_t ep, void *data, uint_fast8_t max_len)
|
||||
* Interface
|
||||
****************************************************************/
|
||||
|
||||
static uint32_t bulk_out_push_count;
|
||||
|
||||
int_fast8_t
|
||||
usb_read_bulk_out(void *data, uint_fast8_t max_len)
|
||||
{
|
||||
return usb_read_packet(USB_CDC_EP_BULK_OUT, data, max_len);
|
||||
// Check if there is a packet ready
|
||||
uint32_t bopc = bulk_out_push_count, bufnum = bopc & 1;
|
||||
uint32_t ep = USB_CDC_EP_BULK_OUT;
|
||||
volatile uint16_t *epbp = lookup_epbufctrl(ep, 1, bufnum);
|
||||
uint32_t epb = *epbp;
|
||||
if ((epb & (USB_BUF_CTRL_AVAIL|USB_BUF_CTRL_FULL)) != USB_BUF_CTRL_FULL)
|
||||
return -1;
|
||||
// Determine the next packet header
|
||||
bulk_out_push_count = bopc + 1;
|
||||
uint32_t pid = bufnum ? USB_BUF_CTRL_DATA1_PID : 0;
|
||||
uint32_t new_epb = USB_BUF_CTRL_LAST | pid | DPBUF_SIZE;
|
||||
*epbp = new_epb;
|
||||
barrier();
|
||||
// Copy the packet to the given buffer
|
||||
uint32_t c = get_rx_count(epb, max_len);
|
||||
memcpy(data, usb_buf_addr(ep, bufnum), c);
|
||||
// Notify the USB hardware that the space is now available
|
||||
barrier();
|
||||
*epbp = new_epb | USB_BUF_CTRL_AVAIL;
|
||||
return c;
|
||||
}
|
||||
|
||||
static uint32_t bulk_in_pop_count;
|
||||
|
||||
int_fast8_t
|
||||
usb_send_bulk_in(void *data, uint_fast8_t len)
|
||||
{
|
||||
return usb_write_packet(USB_CDC_EP_BULK_IN, data, len);
|
||||
// Check if there is room for this packet
|
||||
uint32_t bipc = bulk_in_pop_count, bufnum = bipc & 1;
|
||||
uint32_t ep = USB_CDC_EP_BULK_IN;
|
||||
volatile uint16_t *epbp = lookup_epbufctrl(ep, 0, bufnum);
|
||||
uint32_t epb = *epbp;
|
||||
if (epb & (USB_BUF_CTRL_AVAIL|USB_BUF_CTRL_FULL))
|
||||
return -1;
|
||||
// Determine the next packet header
|
||||
bulk_in_pop_count = bipc + 1;
|
||||
uint32_t pid = bufnum ? USB_BUF_CTRL_DATA1_PID : 0;
|
||||
uint32_t new_epb = USB_BUF_CTRL_FULL | USB_BUF_CTRL_LAST | pid | len;
|
||||
*epbp = new_epb;
|
||||
barrier();
|
||||
// Copy the packet to the hw buffer
|
||||
memcpy(usb_buf_addr(ep, bufnum), data, len);
|
||||
// Inform the USB hardware of the available packet
|
||||
barrier();
|
||||
*epbp = new_epb | USB_BUF_CTRL_AVAIL;
|
||||
return len;
|
||||
}
|
||||
|
||||
int_fast8_t
|
||||
@@ -118,19 +153,51 @@ usb_read_ep0_setup(void *data, uint_fast8_t max_len)
|
||||
int_fast8_t
|
||||
usb_read_ep0(void *data, uint_fast8_t max_len)
|
||||
{
|
||||
// Check if there is a packet ready
|
||||
uint32_t ep = 0;
|
||||
if (usb_hw->intr & USB_INTR_SETUP_REQ_BITS)
|
||||
// Early end of transmission
|
||||
return -2;
|
||||
return usb_read_packet(0, data, max_len);
|
||||
volatile uint16_t *epbp = lookup_epbufctrl(ep, 1, 0);
|
||||
uint32_t epb = *epbp;
|
||||
if ((epb & (USB_BUF_CTRL_AVAIL|USB_BUF_CTRL_FULL)) != USB_BUF_CTRL_FULL)
|
||||
return -1;
|
||||
// Determine the next packet header
|
||||
uint32_t new_epb = USB_BUF_CTRL_LAST | next_data_pid(epb) | DPBUF_SIZE;
|
||||
*epbp = new_epb;
|
||||
barrier();
|
||||
// Copy the packet to the given buffer
|
||||
uint32_t c = get_rx_count(epb, max_len);
|
||||
memcpy(data, usb_buf_addr(ep, 0), c);
|
||||
// Notify the USB hardware that the space is now available
|
||||
barrier();
|
||||
*epbp = new_epb | USB_BUF_CTRL_AVAIL;
|
||||
return c;
|
||||
}
|
||||
|
||||
int_fast8_t
|
||||
usb_send_ep0(const void *data, uint_fast8_t len)
|
||||
{
|
||||
// Check if there is room for this packet
|
||||
uint32_t ep = 0;
|
||||
if (usb_hw->intr & USB_INTR_SETUP_REQ_BITS || usb_hw->buf_status & 2)
|
||||
// Early end of transmission
|
||||
return -2;
|
||||
return usb_write_packet(0, data, len);
|
||||
volatile uint16_t *epbp = lookup_epbufctrl(ep, 0, 0);
|
||||
uint32_t epb = *epbp;
|
||||
if (epb & (USB_BUF_CTRL_AVAIL|USB_BUF_CTRL_FULL))
|
||||
return -1;
|
||||
// Determine the next packet header
|
||||
uint32_t pid = next_data_pid(epb);
|
||||
uint32_t new_epb = USB_BUF_CTRL_FULL | USB_BUF_CTRL_LAST | pid | len;
|
||||
*epbp = new_epb;
|
||||
barrier();
|
||||
// Copy the packet to the hw buffer
|
||||
memcpy(usb_buf_addr(ep, 0), data, len);
|
||||
// Inform the USB hardware of the available packet
|
||||
barrier();
|
||||
*epbp = new_epb | USB_BUF_CTRL_AVAIL;
|
||||
return len;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -156,9 +223,13 @@ usb_set_address(uint_fast8_t addr)
|
||||
void
|
||||
usb_set_configure(void)
|
||||
{
|
||||
usb_dpram->ep_buf_ctrl[USB_CDC_EP_BULK_IN].in = USB_BUF_CTRL_DATA1_PID;
|
||||
usb_dpram->ep_buf_ctrl[USB_CDC_EP_BULK_OUT].out = (
|
||||
USB_BUF_CTRL_AVAIL | USB_BUF_CTRL_LAST | DPBUF_SIZE);
|
||||
bulk_in_pop_count = 0;
|
||||
usb_dpram->ep_buf_ctrl[USB_CDC_EP_BULK_IN].in = 0;
|
||||
|
||||
bulk_out_push_count = 0;
|
||||
uint32_t epb0 = USB_BUF_CTRL_AVAIL | USB_BUF_CTRL_LAST | DPBUF_SIZE;
|
||||
uint32_t epb1 = epb0 | USB_BUF_CTRL_DATA1_PID;
|
||||
usb_dpram->ep_buf_ctrl[USB_CDC_EP_BULK_OUT].out = epb0 | (epb1 << 16);
|
||||
}
|
||||
|
||||
|
||||
@@ -290,10 +361,12 @@ endpoint_setup(void)
|
||||
usb_dpram->ep_ctrl[USB_CDC_EP_ACM-1].in = ep_acm;
|
||||
// BULK
|
||||
uint32_t ep_out = (EP_CTRL_ENABLE_BITS | usb_buf_offset(USB_CDC_EP_BULK_OUT)
|
||||
| EP_CTRL_DOUBLE_BUFFERED_BITS
|
||||
| EP_CTRL_INTERRUPT_PER_BUFFER
|
||||
| (USB_ENDPOINT_XFER_BULK << EP_CTRL_BUFFER_TYPE_LSB));
|
||||
usb_dpram->ep_ctrl[USB_CDC_EP_BULK_OUT-1].out = ep_out;
|
||||
uint32_t ep_in = (EP_CTRL_ENABLE_BITS | usb_buf_offset(USB_CDC_EP_BULK_IN)
|
||||
| EP_CTRL_DOUBLE_BUFFERED_BITS
|
||||
| EP_CTRL_INTERRUPT_PER_BUFFER
|
||||
| (USB_ENDPOINT_XFER_BULK << EP_CTRL_BUFFER_TYPE_LSB));
|
||||
usb_dpram->ep_ctrl[USB_CDC_EP_BULK_IN-1].in = ep_in;
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
// Support for gathering acceleration data from LIS2DW chip
|
||||
//
|
||||
// Copyright (C) 2023 Zhou.XianMing <zhouxm@biqu3d.com>
|
||||
// Copyright (C) 2020 Kevin O'Connor <kevin@koconnor.net>
|
||||
//
|
||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
#include <string.h> // memcpy
|
||||
#include "board/irq.h" // irq_disable
|
||||
#include "board/misc.h" // timer_read_time
|
||||
#include "basecmd.h" // oid_alloc
|
||||
#include "command.h" // DECL_COMMAND
|
||||
#include "sched.h" // DECL_TASK
|
||||
#include "spicmds.h" // spidev_transfer
|
||||
|
||||
#define LIS_AR_DATAX0 0x28
|
||||
#define LIS_AM_READ 0x80
|
||||
#define LIS_FIFO_CTRL 0x2E
|
||||
#define LIS_FIFO_SAMPLES 0x2F
|
||||
|
||||
struct lis2dw {
|
||||
struct timer timer;
|
||||
uint32_t rest_ticks;
|
||||
struct spidev_s *spi;
|
||||
uint16_t sequence, limit_count;
|
||||
uint8_t flags, data_count, fifo_disable;
|
||||
uint8_t data[48];
|
||||
};
|
||||
|
||||
enum {
|
||||
LIS_HAVE_START = 1<<0, LIS_RUNNING = 1<<1, LIS_PENDING = 1<<2,
|
||||
};
|
||||
|
||||
static struct task_wake lis2dw_wake;
|
||||
|
||||
// Event handler that wakes lis2dw_task() periodically
|
||||
static uint_fast8_t
|
||||
lis2dw_event(struct timer *timer)
|
||||
{
|
||||
struct lis2dw *ax = container_of(timer, struct lis2dw, timer);
|
||||
ax->flags |= LIS_PENDING;
|
||||
sched_wake_task(&lis2dw_wake);
|
||||
return SF_DONE;
|
||||
}
|
||||
|
||||
void
|
||||
command_config_lis2dw(uint32_t *args)
|
||||
{
|
||||
struct lis2dw *ax = oid_alloc(args[0], command_config_lis2dw
|
||||
, sizeof(*ax));
|
||||
ax->timer.func = lis2dw_event;
|
||||
ax->spi = spidev_oid_lookup(args[1]);
|
||||
}
|
||||
DECL_COMMAND(command_config_lis2dw, "config_lis2dw oid=%c spi_oid=%c");
|
||||
|
||||
// Report local measurement buffer
|
||||
static void
|
||||
lis2dw_report(struct lis2dw *ax, uint8_t oid)
|
||||
{
|
||||
sendf("lis2dw_data oid=%c sequence=%hu data=%*s"
|
||||
, oid, ax->sequence, ax->data_count, ax->data);
|
||||
ax->data_count = 0;
|
||||
ax->sequence++;
|
||||
}
|
||||
|
||||
// Report buffer and fifo status
|
||||
static void
|
||||
lis2dw_status(struct lis2dw *ax, uint_fast8_t oid
|
||||
, uint32_t time1, uint32_t time2, uint_fast8_t fifo)
|
||||
{
|
||||
sendf("lis2dw_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
|
||||
" buffered=%c fifo=%c limit_count=%hu"
|
||||
, oid, time1, time2-time1, ax->sequence
|
||||
, ax->data_count, fifo, ax->limit_count);
|
||||
}
|
||||
|
||||
// Helper code to reschedule the lis2dw_event() timer
|
||||
static void
|
||||
lis2dw_reschedule_timer(struct lis2dw *ax)
|
||||
{
|
||||
irq_disable();
|
||||
ax->timer.waketime = timer_read_time() + ax->rest_ticks;
|
||||
sched_add_timer(&ax->timer);
|
||||
irq_enable();
|
||||
}
|
||||
|
||||
// Query accelerometer data
|
||||
static void
|
||||
lis2dw_query(struct lis2dw *ax, uint8_t oid)
|
||||
{
|
||||
uint8_t msg[7] = {0};
|
||||
uint8_t fifo[2] = {LIS_FIFO_SAMPLES| LIS_AM_READ , 0};
|
||||
uint8_t fifo_empty,fifo_ovrn = 0;
|
||||
|
||||
msg[0] = LIS_AR_DATAX0 | LIS_AM_READ ;
|
||||
uint8_t *d = &ax->data[ax->data_count];
|
||||
|
||||
spidev_transfer(ax->spi, 1, sizeof(msg), msg);
|
||||
|
||||
spidev_transfer(ax->spi, 1, sizeof(fifo), fifo);
|
||||
fifo_empty = fifo[1]&0x3F;
|
||||
fifo_ovrn = fifo[1]&0x40;
|
||||
|
||||
d[0] = msg[1]; // x low bits
|
||||
d[1] = msg[2]; // x high bits
|
||||
d[2] = msg[3]; // y low bits
|
||||
d[3] = msg[4]; // y high bits
|
||||
d[4] = msg[5]; // z low bits
|
||||
d[5] = msg[6]; // z high bits
|
||||
|
||||
ax->data_count += 6;
|
||||
if (ax->data_count + 6 > ARRAY_SIZE(ax->data))
|
||||
lis2dw_report(ax, oid);
|
||||
|
||||
// Check fifo status
|
||||
if (fifo_ovrn)
|
||||
ax->limit_count++;
|
||||
|
||||
// check if we need to run the task again (more packets in fifo?)
|
||||
if (!fifo_empty&&!(ax->fifo_disable)) {
|
||||
// More data in fifo - wake this task again
|
||||
sched_wake_task(&lis2dw_wake);
|
||||
} else if (ax->flags & LIS_RUNNING) {
|
||||
// Sleep until next check time
|
||||
sched_del_timer(&ax->timer);
|
||||
ax->flags &= ~LIS_PENDING;
|
||||
lis2dw_reschedule_timer(ax);
|
||||
}
|
||||
}
|
||||
|
||||
// Startup measurements
|
||||
static void
|
||||
lis2dw_start(struct lis2dw *ax, uint8_t oid)
|
||||
{
|
||||
sched_del_timer(&ax->timer);
|
||||
ax->flags = LIS_RUNNING;
|
||||
ax->fifo_disable = 0;
|
||||
uint8_t ctrl[2] = {LIS_FIFO_CTRL , 0xC0};
|
||||
spidev_transfer(ax->spi, 0, sizeof(ctrl), ctrl);
|
||||
lis2dw_reschedule_timer(ax);
|
||||
}
|
||||
|
||||
// End measurements
|
||||
static void
|
||||
lis2dw_stop(struct lis2dw *ax, uint8_t oid)
|
||||
{
|
||||
// Disable measurements
|
||||
sched_del_timer(&ax->timer);
|
||||
ax->flags = 0;
|
||||
// Drain any measurements still in fifo
|
||||
ax->fifo_disable = 1;
|
||||
lis2dw_query(ax, oid);
|
||||
|
||||
uint8_t ctrl[2] = {LIS_FIFO_CTRL , 0};
|
||||
uint32_t end1_time = timer_read_time();
|
||||
spidev_transfer(ax->spi, 0, sizeof(ctrl), ctrl);
|
||||
uint32_t end2_time = timer_read_time();
|
||||
|
||||
uint8_t msg[2] = { LIS_FIFO_SAMPLES | LIS_AM_READ , 0};
|
||||
spidev_transfer(ax->spi, 1, sizeof(msg), msg);
|
||||
uint8_t fifo_status = msg[1]&0x1f;
|
||||
|
||||
//Report final data
|
||||
if (ax->data_count)
|
||||
lis2dw_report(ax, oid);
|
||||
lis2dw_status(ax, oid, end1_time, end2_time, fifo_status);
|
||||
}
|
||||
|
||||
void
|
||||
command_query_lis2dw(uint32_t *args)
|
||||
{
|
||||
struct lis2dw *ax = oid_lookup(args[0], command_config_lis2dw);
|
||||
|
||||
if (!args[2]) {
|
||||
// End measurements
|
||||
lis2dw_stop(ax, args[0]);
|
||||
return;
|
||||
}
|
||||
// Start new measurements query
|
||||
sched_del_timer(&ax->timer);
|
||||
ax->timer.waketime = args[1];
|
||||
ax->rest_ticks = args[2];
|
||||
ax->flags = LIS_HAVE_START;
|
||||
ax->sequence = ax->limit_count = 0;
|
||||
ax->data_count = 0;
|
||||
ax->fifo_disable = 0;
|
||||
sched_add_timer(&ax->timer);
|
||||
}
|
||||
DECL_COMMAND(command_query_lis2dw,
|
||||
"query_lis2dw oid=%c clock=%u rest_ticks=%u");
|
||||
|
||||
void
|
||||
command_query_lis2dw_status(uint32_t *args)
|
||||
{
|
||||
struct lis2dw *ax = oid_lookup(args[0], command_config_lis2dw);
|
||||
uint8_t msg[2] = { LIS_FIFO_SAMPLES | LIS_AM_READ, 0x00 };
|
||||
uint32_t time1 = timer_read_time();
|
||||
spidev_transfer(ax->spi, 1, sizeof(msg), msg);
|
||||
uint32_t time2 = timer_read_time();
|
||||
lis2dw_status(ax, args[0], time1, time2, msg[1]&0x1f);
|
||||
}
|
||||
DECL_COMMAND(command_query_lis2dw_status, "query_lis2dw_status oid=%c");
|
||||
|
||||
void
|
||||
lis2dw_task(void)
|
||||
{
|
||||
if (!sched_check_wake(&lis2dw_wake))
|
||||
return;
|
||||
uint8_t oid;
|
||||
struct lis2dw *ax;
|
||||
foreach_oid(oid, ax, command_config_lis2dw) {
|
||||
uint_fast8_t flags = ax->flags;
|
||||
if (!(flags & LIS_PENDING))
|
||||
continue;
|
||||
if (flags & LIS_HAVE_START)
|
||||
lis2dw_start(ax, oid);
|
||||
else
|
||||
lis2dw_query(ax, oid);
|
||||
}
|
||||
}
|
||||
DECL_TASK(lis2dw_task);
|
||||
+144
-75
@@ -1,6 +1,6 @@
|
||||
// Hardware interface to "fullspeed USB controller"
|
||||
//
|
||||
// Copyright (C) 2018-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
// Copyright (C) 2018-2023 Kevin O'Connor <kevin@koconnor.net>
|
||||
//
|
||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
@@ -48,6 +48,12 @@
|
||||
#define USB_CNTR_FRES USB_CNTR_USBRST
|
||||
#endif
|
||||
|
||||
// Some chip variants do not define these fields
|
||||
#ifndef USB_EP_DTOG_TX_Pos
|
||||
#define USB_EP_DTOG_TX_Pos 6
|
||||
#define USB_EP_DTOG_RX_Pos 14
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* USB transfer memory
|
||||
@@ -55,52 +61,50 @@
|
||||
|
||||
// Layout of the USB transfer memory
|
||||
#define EPM ((epmword_t*)USB_PMAADDR)
|
||||
#define EPM_EP_DESC(ep) (&EPM[(ep) * (8 / WSIZE)])
|
||||
#define EPM_EP_DESC(ep, bufnum) (&EPM[((ep)*2 + (bufnum)) * (4 / WSIZE)])
|
||||
#define EPM_BUF_OFFSET 0x10
|
||||
#define EPM_EP_BUF_SIZE (64 / WSIZE + 1)
|
||||
#define EPM_EP_TX_BUF(ep) (&EPM[EPM_BUF_OFFSET + (ep)*2*EPM_EP_BUF_SIZE])
|
||||
#define EPM_EP_RX_BUF(ep) (&EPM[EPM_BUF_OFFSET + (1+(ep)*2)*EPM_EP_BUF_SIZE])
|
||||
#define EPM_EP_BUF(ep, bufnum) \
|
||||
(&EPM[EPM_BUF_OFFSET + ((ep)*2 + (bufnum)) * EPM_EP_BUF_SIZE])
|
||||
#define BUFTX 0
|
||||
#define BUFRX 1
|
||||
|
||||
// Configure the usb descriptor for an endpoint
|
||||
static void
|
||||
epm_ep_desc_setup(int ep, int rx_size)
|
||||
epm_ep_desc_setup(int ep, int bufnum, int rx_size)
|
||||
{
|
||||
uint32_t addr_tx = (EPM_EP_TX_BUF(ep) - EPM) * WSIZE, count_tx = 0;
|
||||
uint32_t addr_rx = (EPM_EP_RX_BUF(ep) - EPM) * WSIZE;
|
||||
uint32_t addr = (EPM_EP_BUF(ep, bufnum) - EPM) * WSIZE;
|
||||
uint32_t count_rx = (rx_size <= 30 ? DIV_ROUND_UP(rx_size, 2) << 10
|
||||
: ((DIV_ROUND_UP(rx_size, 32) - 1) << 10) | 0x8000);
|
||||
epmword_t *desc = EPM_EP_DESC(ep);
|
||||
epmword_t *desc = EPM_EP_DESC(ep, bufnum);
|
||||
if (WSIZE == 2) {
|
||||
desc[0] = addr_tx;
|
||||
desc[1] = count_tx;
|
||||
desc[2] = addr_rx;
|
||||
desc[3] = count_rx;
|
||||
desc[0] = addr;
|
||||
desc[1] = count_rx;
|
||||
} else {
|
||||
desc[0] = addr_tx | (count_tx << 16);
|
||||
desc[1] = addr_rx | (count_rx << 16);
|
||||
*desc = addr | (count_rx << 16);
|
||||
}
|
||||
}
|
||||
|
||||
// Return number of read bytes on an rx endpoint
|
||||
static uint32_t
|
||||
epm_get_ep_count_rx(int ep)
|
||||
epm_get_ep_count_rx(int ep, int bufnum)
|
||||
{
|
||||
epmword_t *desc = EPM_EP_DESC(ep);
|
||||
epmword_t *desc = EPM_EP_DESC(ep, bufnum);
|
||||
if (WSIZE == 2)
|
||||
return desc[3] & 0x3ff;
|
||||
return (desc[1] >> 16) & 0x3ff;
|
||||
return desc[1] & 0x3ff;
|
||||
return (*desc >> 16) & 0x3ff;
|
||||
}
|
||||
|
||||
// Set number of bytes ready to be transmitted on a tx endpoint
|
||||
static void
|
||||
epm_set_ep_count_tx(int ep, uint32_t count)
|
||||
epm_set_ep_count_tx(int ep, int bufnum, uint32_t count)
|
||||
{
|
||||
epmword_t *desc = EPM_EP_DESC(ep);
|
||||
epmword_t *desc = EPM_EP_DESC(ep, bufnum);
|
||||
if (WSIZE == 2) {
|
||||
desc[1] = count;
|
||||
} else {
|
||||
uint32_t addr_tx = (EPM_EP_TX_BUF(ep) - EPM) * WSIZE;
|
||||
desc[0] = addr_tx | (count << 16);
|
||||
uint32_t addr_tx = (EPM_EP_BUF(ep, bufnum) - EPM) * WSIZE;
|
||||
*desc = addr_tx | (count << 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,18 +112,22 @@ epm_set_ep_count_tx(int ep, uint32_t count)
|
||||
static void
|
||||
btable_configure(void)
|
||||
{
|
||||
epm_ep_desc_setup(0, USB_CDC_EP0_SIZE);
|
||||
epm_ep_desc_setup(USB_CDC_EP_ACM, 0);
|
||||
epm_ep_desc_setup(USB_CDC_EP_BULK_OUT, USB_CDC_EP_BULK_OUT_SIZE);
|
||||
epm_ep_desc_setup(USB_CDC_EP_BULK_IN, 0);
|
||||
epm_ep_desc_setup(0, BUFTX, 0);
|
||||
epm_ep_desc_setup(0, BUFRX, USB_CDC_EP0_SIZE);
|
||||
epm_ep_desc_setup(USB_CDC_EP_ACM, BUFTX, 0);
|
||||
epm_ep_desc_setup(USB_CDC_EP_ACM, BUFRX, 0);
|
||||
epm_ep_desc_setup(USB_CDC_EP_BULK_OUT, 0, USB_CDC_EP_BULK_OUT_SIZE);
|
||||
epm_ep_desc_setup(USB_CDC_EP_BULK_OUT, 1, USB_CDC_EP_BULK_OUT_SIZE);
|
||||
epm_ep_desc_setup(USB_CDC_EP_BULK_IN, 0, 0);
|
||||
epm_ep_desc_setup(USB_CDC_EP_BULK_IN, 1, 0);
|
||||
}
|
||||
|
||||
// Read a packet stored in dedicated usb memory
|
||||
static uint32_t
|
||||
btable_read_packet(int ep, uint8_t *dest, int max_len)
|
||||
btable_read_packet(int ep, int bufnum, uint8_t *dest, int max_len)
|
||||
{
|
||||
epmword_t *src = EPM_EP_RX_BUF(ep);
|
||||
uint32_t count = epm_get_ep_count_rx(ep);
|
||||
epmword_t *src = EPM_EP_BUF(ep, bufnum);
|
||||
uint32_t count = epm_get_ep_count_rx(ep, bufnum);
|
||||
if (count > max_len)
|
||||
count = max_len;
|
||||
int i;
|
||||
@@ -145,9 +153,9 @@ btable_read_packet(int ep, uint8_t *dest, int max_len)
|
||||
|
||||
// Write a packet to dedicated usb memory
|
||||
static void
|
||||
btable_write_packet(int ep, const uint8_t *src, int count)
|
||||
btable_write_packet(int ep, int bufnum, const uint8_t *src, int count)
|
||||
{
|
||||
epmword_t *dest = EPM_EP_TX_BUF(ep);
|
||||
epmword_t *dest = EPM_EP_BUF(ep, bufnum);
|
||||
int i;
|
||||
for (i=0; i<count/WSIZE; i++) {
|
||||
uint8_t b1 = *src++, b2 = *src++, b3 = 0, b4 = 0;
|
||||
@@ -165,7 +173,7 @@ btable_write_packet(int ep, const uint8_t *src, int count)
|
||||
d |= *src++ << 16;
|
||||
*dest = d;
|
||||
}
|
||||
epm_set_ep_count_tx(ep, count);
|
||||
epm_set_ep_count_tx(ep, bufnum, count);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,26 +183,27 @@ btable_write_packet(int ep, const uint8_t *src, int count)
|
||||
|
||||
#define USB_EPR ((volatile uint32_t *)USB_BASE)
|
||||
|
||||
#define EPR_TBITS (USB_EP_DTOG_RX | USB_EPRX_STAT \
|
||||
| USB_EP_DTOG_TX | USB_EPTX_STAT)
|
||||
#define EPR_RWBITS (USB_EPADDR_FIELD | USB_EP_KIND | USB_EP_TYPE_MASK)
|
||||
#define EPR_RWCBITS (USB_EP_CTR_RX | USB_EP_CTR_TX)
|
||||
|
||||
// Calculate the memory update needed to set the epr register
|
||||
static uint32_t
|
||||
set_stat_rx_bits(uint32_t epr, uint32_t bits)
|
||||
calc_epr_bits(uint32_t epr, uint32_t mask, uint32_t value)
|
||||
{
|
||||
return ((epr & (EPR_RWBITS | USB_EPRX_STAT)) ^ bits) | EPR_RWCBITS;
|
||||
uint32_t tmask = mask & EPR_TBITS, tvalue = value & tmask;
|
||||
uint32_t rwmask = mask & EPR_RWBITS, rwbits = value & rwmask;
|
||||
uint32_t cbits = EPR_RWCBITS & ~mask;
|
||||
return (((epr & (EPR_RWBITS | tmask)) ^ tvalue) & ~rwmask) | rwbits | cbits;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
set_stat_tx_bits(uint32_t epr, uint32_t bits)
|
||||
// Check if double buffering endpoint hardware can no longer send/receive
|
||||
static int
|
||||
epr_is_dbuf_blocking(uint32_t epr)
|
||||
{
|
||||
return ((epr & (EPR_RWBITS | USB_EPTX_STAT)) ^ bits) | EPR_RWCBITS;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
set_stat_rxtx_bits(uint32_t epr, uint32_t bits)
|
||||
{
|
||||
uint32_t mask = EPR_RWBITS | USB_EPRX_STAT | USB_EPTX_STAT;
|
||||
return ((epr & mask) ^ bits) | EPR_RWCBITS;
|
||||
return !(((epr >> (USB_EP_DTOG_RX_Pos - USB_EP_DTOG_TX_Pos)) ^ epr)
|
||||
& USB_EP_DTOG_TX);
|
||||
}
|
||||
|
||||
|
||||
@@ -202,39 +211,77 @@ set_stat_rxtx_bits(uint32_t epr, uint32_t bits)
|
||||
* USB interface
|
||||
****************************************************************/
|
||||
|
||||
static uint32_t bulk_out_pop_count, bulk_out_push_flag;
|
||||
|
||||
int_fast8_t
|
||||
usb_read_bulk_out(void *data, uint_fast8_t max_len)
|
||||
{
|
||||
uint32_t epr = USB_EPR[USB_CDC_EP_BULK_OUT];
|
||||
if ((epr & USB_EPRX_STAT) == USB_EP_RX_VALID)
|
||||
if (readl(&bulk_out_push_flag))
|
||||
// No data ready
|
||||
return -1;
|
||||
uint32_t count = btable_read_packet(USB_CDC_EP_BULK_OUT, data, max_len);
|
||||
USB_EPR[USB_CDC_EP_BULK_OUT] = set_stat_rx_bits(epr, USB_EP_RX_VALID);
|
||||
uint32_t ep = USB_CDC_EP_BULK_OUT;
|
||||
int bufnum = bulk_out_pop_count & 1;
|
||||
bulk_out_pop_count++;
|
||||
uint32_t count = btable_read_packet(ep, bufnum, data, max_len);
|
||||
writel(&bulk_out_push_flag, USB_EP_DTOG_TX);
|
||||
|
||||
// Check if irq handler pulled another packet before push flag update
|
||||
uint32_t epr = USB_EPR[ep];
|
||||
if (epr_is_dbuf_blocking(epr) && readl(&bulk_out_push_flag)) {
|
||||
// Second packet was already read - must notify hardware
|
||||
writel(&bulk_out_push_flag, 0);
|
||||
USB_EPR[ep] = calc_epr_bits(epr, 0, 0) | USB_EP_DTOG_TX;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static uint32_t bulk_in_push_pos, bulk_in_pop_flag;
|
||||
#define BI_START 2
|
||||
|
||||
int_fast8_t
|
||||
usb_send_bulk_in(void *data, uint_fast8_t len)
|
||||
{
|
||||
uint32_t epr = USB_EPR[USB_CDC_EP_BULK_IN];
|
||||
if ((epr & USB_EPTX_STAT) != USB_EP_TX_NAK)
|
||||
if (readl(&bulk_in_pop_flag))
|
||||
// No buffer space available
|
||||
return -1;
|
||||
btable_write_packet(USB_CDC_EP_BULK_IN, data, len);
|
||||
USB_EPR[USB_CDC_EP_BULK_IN] = set_stat_tx_bits(epr, USB_EP_TX_VALID);
|
||||
uint32_t ep = USB_CDC_EP_BULK_IN;
|
||||
uint32_t bipp = bulk_in_push_pos, bufnum = bipp & 1;
|
||||
bulk_in_push_pos = bipp ^ 1;
|
||||
btable_write_packet(ep, bufnum, data, len);
|
||||
writel(&bulk_in_pop_flag, USB_EP_DTOG_RX);
|
||||
|
||||
// Check if hardware needs to be notified
|
||||
uint32_t epr = USB_EPR[ep];
|
||||
if (epr_is_dbuf_blocking(epr) && readl(&bulk_in_pop_flag)) {
|
||||
writel(&bulk_in_pop_flag, 0);
|
||||
if (unlikely(bipp & BI_START)) {
|
||||
// Two packets are always sent when starting in double
|
||||
// buffering mode, so wait for second packet before starting.
|
||||
if (bipp == (BI_START | 1)) {
|
||||
bulk_in_push_pos = 0;
|
||||
writel(&bulk_in_pop_flag, USB_EP_KIND); // Dummy flag
|
||||
USB_EPR[ep] = calc_epr_bits(epr, USB_EPTX_STAT
|
||||
, USB_EP_TX_VALID);
|
||||
}
|
||||
} else {
|
||||
USB_EPR[ep] = calc_epr_bits(epr, 0, 0) | USB_EP_DTOG_RX;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int_fast8_t
|
||||
usb_read_ep0(void *data, uint_fast8_t max_len)
|
||||
{
|
||||
uint32_t epr = USB_EPR[0];
|
||||
uint32_t ep = 0, epr = USB_EPR[ep];
|
||||
if ((epr & USB_EPRX_STAT) != USB_EP_RX_NAK)
|
||||
// No data ready
|
||||
return -1;
|
||||
uint32_t count = btable_read_packet(0, data, max_len);
|
||||
USB_EPR[0] = set_stat_rxtx_bits(epr, USB_EP_RX_VALID | USB_EP_TX_NAK);
|
||||
uint32_t count = btable_read_packet(ep, BUFRX, data, max_len);
|
||||
USB_EPR[ep] = calc_epr_bits(epr, USB_EPRX_STAT | USB_EPTX_STAT
|
||||
, USB_EP_RX_VALID | USB_EP_TX_NAK);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -247,23 +294,24 @@ usb_read_ep0_setup(void *data, uint_fast8_t max_len)
|
||||
int_fast8_t
|
||||
usb_send_ep0(const void *data, uint_fast8_t len)
|
||||
{
|
||||
uint32_t epr = USB_EPR[0];
|
||||
uint32_t ep = 0, epr = USB_EPR[ep];
|
||||
if ((epr & USB_EPRX_STAT) != USB_EP_RX_VALID)
|
||||
// Transfer interrupted
|
||||
return -2;
|
||||
if ((epr & USB_EPTX_STAT) != USB_EP_TX_NAK)
|
||||
// No buffer space available
|
||||
return -1;
|
||||
btable_write_packet(0, data, len);
|
||||
USB_EPR[0] = set_stat_tx_bits(epr, USB_EP_TX_VALID);
|
||||
btable_write_packet(ep, BUFTX, data, len);
|
||||
USB_EPR[ep] = calc_epr_bits(epr, USB_EPTX_STAT, USB_EP_TX_VALID);
|
||||
return len;
|
||||
}
|
||||
|
||||
void
|
||||
usb_stall_ep0(void)
|
||||
{
|
||||
USB_EPR[0] = set_stat_rxtx_bits(USB_EPR[0]
|
||||
, USB_EP_RX_STALL | USB_EP_TX_STALL);
|
||||
uint32_t ep = 0, epr = USB_EPR[ep];
|
||||
USB_EPR[ep] = calc_epr_bits(epr, USB_EPRX_STAT | USB_EPTX_STAT
|
||||
, USB_EP_RX_STALL | USB_EP_TX_STALL);
|
||||
}
|
||||
|
||||
static uint8_t set_address;
|
||||
@@ -278,6 +326,13 @@ usb_set_address(uint_fast8_t addr)
|
||||
void
|
||||
usb_set_configure(void)
|
||||
{
|
||||
uint32_t ep = USB_CDC_EP_BULK_OUT;
|
||||
bulk_out_pop_count = 0;
|
||||
USB_EPR[ep] = calc_epr_bits(USB_EPR[ep], USB_EPRX_STAT, USB_EP_RX_VALID);
|
||||
|
||||
ep = USB_CDC_EP_BULK_IN;
|
||||
bulk_in_push_pos = BI_START;
|
||||
writel(&bulk_in_pop_flag, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -289,13 +344,22 @@ usb_set_configure(void)
|
||||
static void
|
||||
usb_reset(void)
|
||||
{
|
||||
USB_EPR[0] = 0 | USB_EP_CONTROL | USB_EP_RX_VALID | USB_EP_TX_NAK;
|
||||
USB_EPR[USB_CDC_EP_ACM] = (USB_CDC_EP_ACM | USB_EP_INTERRUPT
|
||||
| USB_EP_RX_NAK | USB_EP_TX_NAK);
|
||||
USB_EPR[USB_CDC_EP_BULK_OUT] = (USB_CDC_EP_BULK_OUT | USB_EP_BULK
|
||||
| USB_EP_RX_VALID | USB_EP_TX_NAK);
|
||||
USB_EPR[USB_CDC_EP_BULK_IN] = (USB_CDC_EP_BULK_IN | USB_EP_BULK
|
||||
| USB_EP_RX_NAK | USB_EP_TX_NAK);
|
||||
uint32_t ep = 0;
|
||||
USB_EPR[ep] = 0 | USB_EP_CONTROL | USB_EP_RX_VALID | USB_EP_TX_NAK;
|
||||
|
||||
ep = USB_CDC_EP_ACM;
|
||||
USB_EPR[ep] = (USB_CDC_EP_ACM | USB_EP_INTERRUPT
|
||||
| USB_EP_RX_NAK | USB_EP_TX_NAK);
|
||||
|
||||
ep = USB_CDC_EP_BULK_OUT;
|
||||
USB_EPR[ep] = (USB_CDC_EP_BULK_OUT | USB_EP_BULK | USB_EP_KIND
|
||||
| USB_EP_RX_NAK | USB_EP_DTOG_TX);
|
||||
bulk_out_push_flag = USB_EP_DTOG_TX;
|
||||
|
||||
ep = USB_CDC_EP_BULK_IN;
|
||||
USB_EPR[ep] = (USB_CDC_EP_BULK_IN | USB_EP_BULK | USB_EP_KIND
|
||||
| USB_EP_TX_NAK);
|
||||
bulk_in_pop_flag = USB_EP_DTOG_RX;
|
||||
|
||||
USB->CNTR = USB_CNTR_CTRM | USB_CNTR_RESETM;
|
||||
USB->DADDR = USB_DADDR_EF;
|
||||
@@ -308,20 +372,25 @@ USB_IRQHandler(void)
|
||||
uint32_t istr = USB->ISTR;
|
||||
if (istr & USB_ISTR_CTR) {
|
||||
// Endpoint activity
|
||||
uint32_t ep = istr & USB_ISTR_EP_ID;
|
||||
uint32_t epr = USB_EPR[ep];
|
||||
USB_EPR[ep] = epr & EPR_RWBITS;
|
||||
if (ep == 0) {
|
||||
uint32_t ep = istr & USB_ISTR_EP_ID, epr = USB_EPR[ep];
|
||||
if (ep == USB_CDC_EP_BULK_OUT) {
|
||||
USB_EPR[ep] = (calc_epr_bits(epr, USB_EP_CTR_RX | USB_EP_CTR_TX, 0)
|
||||
| bulk_out_push_flag);
|
||||
bulk_out_push_flag = 0;
|
||||
usb_notify_bulk_out();
|
||||
} else if (ep == USB_CDC_EP_BULK_IN) {
|
||||
USB_EPR[ep] = (calc_epr_bits(epr, USB_EP_CTR_RX | USB_EP_CTR_TX, 0)
|
||||
| bulk_in_pop_flag);
|
||||
bulk_in_pop_flag = 0;
|
||||
usb_notify_bulk_in();
|
||||
} else if (ep == 0) {
|
||||
USB_EPR[ep] = calc_epr_bits(epr, USB_EP_CTR_RX | USB_EP_CTR_TX, 0);
|
||||
usb_notify_ep0();
|
||||
if (epr & USB_EP_CTR_TX && set_address) {
|
||||
// Apply address after last "in" message transmitted
|
||||
USB->DADDR = set_address;
|
||||
set_address = 0;
|
||||
}
|
||||
} else if (ep == USB_CDC_EP_BULK_OUT) {
|
||||
usb_notify_bulk_out();
|
||||
} else if (ep == USB_CDC_EP_BULK_IN) {
|
||||
usb_notify_bulk_in();
|
||||
}
|
||||
}
|
||||
if (istr & USB_ISTR_RESET) {
|
||||
|
||||
@@ -3,3 +3,4 @@ CONFIG_MACH_AR100=y
|
||||
CONFIG_WANT_DISPLAYS=n
|
||||
CONFIG_WANT_SOFTWARE_I2C=n
|
||||
CONFIG_WANT_SOFTWARE_SPI=n
|
||||
CONFIG_WANT_LIS2DW=n
|
||||
@@ -0,0 +1,3 @@
|
||||
# Base config file for boards using HC32F460
|
||||
CONFIG_MACH_HC32F460=y
|
||||
CONFIG_HC32F460_SERIAL_PA7_PA8=y
|
||||
@@ -2,3 +2,4 @@
|
||||
CONFIG_MACH_STM32=y
|
||||
CONFIG_MACH_STM32F042=y
|
||||
CONFIG_WANT_SOFTWARE_I2C=n
|
||||
CONFIG_WANT_LIS2DW=n
|
||||
@@ -34,6 +34,7 @@ CONFIG ../../config/printer-bq-hephestos-2014.cfg
|
||||
CONFIG ../../config/printer-creality-cr5pro-ht-2022.cfg
|
||||
CONFIG ../../config/printer-creality-cr10-v3-2020.cfg
|
||||
CONFIG ../../config/printer-creality-cr10s-2017.cfg
|
||||
CONFIG ../../config/printer-creality-cr10s-pro-v2-2020.cfg
|
||||
CONFIG ../../config/printer-creality-cr20-2018.cfg
|
||||
CONFIG ../../config/printer-creality-cr20-pro-2019.cfg
|
||||
CONFIG ../../config/printer-creality-ender5plus-2019.cfg
|
||||
@@ -219,6 +220,7 @@ CONFIG ../../config/generic-bigtreetech-skr-2.cfg
|
||||
CONFIG ../../config/generic-flyboard.cfg
|
||||
CONFIG ../../config/generic-mellow-fly-cdy-v3.cfg
|
||||
CONFIG ../../config/generic-mellow-super-infinty-hv.cfg
|
||||
CONFIG ../../config/generic-mks-monster8.cfg
|
||||
CONFIG ../../config/generic-mks-robin-nano-v3.cfg
|
||||
CONFIG ../../config/generic-prusa-buddy.cfg
|
||||
CONFIG ../../config/generic-th3d-ezboard-v2.0.cfg
|
||||
@@ -256,11 +258,15 @@ CONFIG ../../config/generic-bigtreetech-skr-mini-e3-v3.0.cfg
|
||||
DICTIONARY rp2040.dict
|
||||
CONFIG ../../config/generic-bigtreetech-skr-pico-v1.0.cfg
|
||||
|
||||
# Anycubic Printers using trigorilla board with the hc32f460
|
||||
# Printers using the hc32f460 with serial on PA3 PA2
|
||||
DICTIONARY hc32f460-serial-PA3PA2.dict
|
||||
CONFIG ../../config/printer-anycubic-kobra-go-2022.cfg
|
||||
CONFIG ../../config/printer-anycubic-kobra-plus-2022.cfg
|
||||
|
||||
# Printers using the hc32f460 with serial on PA7 PA8
|
||||
DICTIONARY hc32f460-serial-PA7PA8.dict
|
||||
CONFIG ../../config/printer-creality-ender2pro-hc32-2022.cfg
|
||||
|
||||
# Printers using the PRU
|
||||
DICTIONARY pru.dict host=linuxprocess.dict
|
||||
CONFIG ../../config/generic-cramps.cfg
|
||||
|
||||
@@ -13,6 +13,12 @@ value: 0
|
||||
shutdown_value: 0
|
||||
cycle_time: 0.01
|
||||
|
||||
[pwm_tool test_pwm_tool]
|
||||
pin: PH4
|
||||
value: 0
|
||||
shutdown_value: 0
|
||||
cycle_time: 0.01
|
||||
|
||||
[mcu]
|
||||
serial: /dev/ttyACM0
|
||||
|
||||
|
||||
@@ -28,3 +28,11 @@ SET_PIN PIN=soft_pwm_pin VALUE=0.5 CYCLE_TIME=0.5
|
||||
SET_PIN PIN=soft_pwm_pin VALUE=0.5 CYCLE_TIME=0.5
|
||||
SET_PIN PIN=soft_pwm_pin VALUE=0.75 CYCLE_TIME=0.5
|
||||
SET_PIN PIN=soft_pwm_pin VALUE=0.75 CYCLE_TIME=0.75
|
||||
|
||||
# PWM tool
|
||||
# Basic test
|
||||
SET_PIN PIN=test_pwm_tool VALUE=0
|
||||
SET_PIN PIN=test_pwm_tool VALUE=0.5
|
||||
SET_PIN PIN=test_pwm_tool VALUE=0.5
|
||||
SET_PIN PIN=test_pwm_tool VALUE=0.25
|
||||
SET_PIN PIN=test_pwm_tool VALUE=1
|
||||
Reference in new issue
Block a user