I am trying to understand the host<->MCU communication and operation and I am confused about something that I am seeing.
Right after the configuration phase, host issues a ADC query cycle to start querying one of the temperature sensors. However, the start time of the request is based on a clock value that is queried before the entire configuration phase started.
I modified the serialqueue.c code to dump request and response packets, no other modifications to any of the Klipper code. The log is in the form:
[<timestamp>] <msg type>: <msg content>
What I get is this:
[250266027803227] request: [7 24 2 20 114 66 126]
[250266027822714] request: [8 25 38 12 83 76 54 126]
[250266027843672] request: [14 26 26 13 3 0 0 156 206 142 0 38 114 126]
[250266027852691] request: [10 27 27 13 201 159 0 129 127 126]
[250266027875498] request: [10 28 31 0 128 111 0 221 81 126]
[250266027895330] request: [7 29 21 1 212 74 126]
[250266027946184] request: [11 30 14 2 55 37 0 24 122 190 126]
[250266027958382] request: [11 31 26 14 54 0 0 0 122 179 126]
[250266027978920] request: [9 16 31 3 34 1 6 117 126]
[250266028000812] request: [7 17 21 4 38 68 126]
[250266028057593] request: [13 18 14 5 128 96 128 97 0 24 135 242 126]
[250266028066745] request: [11 19 26 15 95 0 0 0 160 234 126]
[250266028087446] request: [9 20 31 6 35 1 11 0 126]
[250266028292303] request: [60 21 21 7 14 8 19 18 0 24 26 16 5 0 0 0 31 9 36 1 21 10 38 17 84 26 18 2 0 0 156 206 142 0 27 18 201 159 0 14 11 66 67 0 24 26 19 52 0 0 0 5 142 144 251 140 111 92 90 126]
[250266528749898] request: [59 22 39 12 185 244 142 0 221 96 8 129 219 221 0 128 243 57 129 252 13 4 28 13 182 248 231 102 0 39 17 186 152 221 64 221 96 8 129 219 221 0 136 91 129 249 111 4 28 18 182 249 142 24 0 3 245 33 126]
The decoded stream is:
[112748328] request[24]: allocate_oids {'count': 20}
[112748912] request[25]: config_analog_in {'oid': 12, 'pin': 'PF3'}
[112750960] request[26]: config_digital_out {'oid': 13, 'pin': 'PA3', 'value': 0, 'default_value': 0, 'max_duration': 60000000}
[118759176] request[27]: set_digital_out_pwm_cycle {'oid': 13, 'cycle_ticks': 1200000}
[118759648] request[28]: config_endstop {'oid': 0, 'pin': 'PG15', 'pull_up': 0}
[118762536] request[29]: config_trsync {'oid': 1}
[118763064] request[30]: config_stepper {'oid': 2, 'step_pin': 'PD7', 'dir_pin': 'PC5', 'invert_step': 0, 'step_pulse_ticks': 24}
[124768296] request[31]: config_digital_out {'oid': 14, 'pin': 'PD6', 'value': 0, 'default_value': 0, 'max_duration': 0}
[124772160] request[16]: config_endstop {'oid': 3, 'pin': 'PC2', 'pull_up': 1}
[124774120] request[17]: config_trsync {'oid': 4}
[124774968] request[18]: config_stepper {'oid': 5, 'step_pin': 'PG0', 'dir_pin': 'PG1', 'invert_step': 0, 'step_pulse_ticks': 24}
[130779912] request[19]: config_digital_out {'oid': 15, 'pin': 'PF15', 'value': 0, 'default_value': 0, 'max_duration': 0}
[130783024] request[20]: config_endstop {'oid': 6, 'pin': 'PC3', 'pull_up': 1}
[130785224] request[21]: config_trsync {'oid': 7}
[130785568] request[21]: config_stepper {'oid': 8, 'step_pin': 'PB3', 'dir_pin': 'PB2', 'invert_step': 0, 'step_pulse_ticks': 24}
[136789968] request[21]: config_digital_out {'oid': 16, 'pin': 'PA5', 'value': 0, 'default_value': 0, 'max_duration': 0}
[136792800] request[21]: config_endstop {'oid': 9, 'pin': 'PC4', 'pull_up': 1}
[136794544] request[21]: config_trsync {'oid': 10}
[136794832] request[21]: config_analog_in {'oid': 17, 'pin': 'PF4'}
[136795904] request[21]: config_digital_out {'oid': 18, 'pin': 'PA2', 'value': 0, 'default_value': 0, 'max_duration': 60000000}
[142802464] request[21]: set_digital_out_pwm_cycle {'oid': 18, 'cycle_ticks': 1200000}
[142802752] request[21]: config_stepper {'oid': 11, 'step_pin': 'PE2', 'dir_pin': 'PE3', 'invert_step': 0, 'step_pulse_ticks': 24}
[148807440] request[21]: config_digital_out {'oid': 19, 'pin': 'PD4', 'value': 0, 'default_value': 0, 'max_duration': 0}
[148810336] request[21]: finalize_config {'crc': 3793667695}
[148817408] request[22]: query_analog_in {'oid': 12, 'clock': 121440000, 'sample_ticks': 12000, 'sample_count': 8, 'rest_ticks': 3600000, 'min_value': 14777, 'max_value': 32269, 'range_check_count': 4}
In the raw stream the timestamp is wall clock time in nanoseconds. In the decoded stream, the timestamp is controller cycle count. The string request[X]
in the decoded stream shows the block sequence number.
According to the wall clock time, there are 250266528749898 - 250266027822714 = 500927184
nanoseconds between host configuring the sensor and requesting the start of the poll cycle. At 12Mhz, that is 6035267
controller clock cycles.
According to the Klipper log file, the last controller clock that was received was last_clock=112738400
and the query cycle start time is 121440000
.
So, Klipper somehow thinks that the controller cannot possible take more than 121440000 - 112738400 = 8701600
cycles to finish the entire configuration phase.
I don’t see how that is OK. It may work on currently supported controllers but if there ever is one that takes more cycles to do the same work, then this would result in an error.
Shouldn’t Klipper query the controller clock after the configuration has been finalized and ack’ed by the controller before issuing any commands?