Commit graph

1318 commits

Author SHA1 Message Date
Kevin O'Connor
1fe9fb3ad4 trigger_analog: Don't report trigger time as the peak time
Some checks failed
Build test / build (push) Waiting to run
klipper3d deploy / deploy (push) Has been cancelled
There are some rare corner cases where reporting the peak time could
cause hard to debug issues (for example, the peak time could
theoretically be a significant time prior to the actual trigger time,
which could possibly cause unexpected clock rollover issues).  Now
that the host code does not utilize the peak time for "tap" detection,
it can be removed from the mcu code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-29 20:57:55 -05:00
Kevin O'Connor
c9d904aa9d trigger_analog: Add initial support for detecting "tap" events
Some checks failed
Build test / build (push) Has been cancelled
klipper3d deploy / deploy (push) Has been cancelled
Add a new "diff_peak_gt" trigger type.  This will be useful with
detecting ldc1612 "tap" events.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:55:39 -05:00
Kevin O'Connor
9a97ade74f sos_filter: Implement auto_offset feature
Add a setting that will enable the mcu sos_filter code to
automatically set an offset using the first read measurement.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:55:39 -05:00
Kevin O'Connor
58cc059e31 sensor_ldc1612: Convert homing code to use trigger_analog system
Remove the homing code from sensor_ldc1612.c and utilize the generic
homing support found in trigger_analog.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
147022dee2 trigger_analog: Update to support generic trigger types
Rework the trigger_analog code to support different "trigger"
conditions.  This merges in features of ldc1612.c into
trigger_analog.c, such as error code reporting in the MCU.  This is in
preparation for using trigger_analog with ldc1612.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
73a6184407 trigger_analog: Check if trigger_analog is allocated in trigger_analog_update()
Check if the trigger_analog struct has been allocated in
trigger_analog_update() itself.  This makes the code easier to use in
the sensor code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
7ec82baca3 sos_filter: Move offset/scale support from trigger_analog.c to sos_filter.c
Support offsetting and scaling the initial raw value prior to
processing in the sos_filter.

Remove that support from trigger_analog.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
109f13c797 sos_filter: Consistently use "frac_bits" instead of "int_bits"
Internally describe the Qx.y format using the number of fractional
bits.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
40242b2e33 sos_filter: Propagate overflow errors instead of a shutdown
Pass an overflow error back to the caller instead of invoking a
shutdown().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
fd195ff4ce sos_filter: Remove unnecessary "const" declarations
A "const" declaration on a local integer does not do anything in C
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
667c57e444 sos_filter: Remove unnecessary is_active flag
It's reasonable to deactivate the filter by setting n_sections=0, and
this makes the code a little easier to use when the host doesn't
actually need any filtering.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor
ec08ff5a1e trigger_analog: Rename load_cell_probe.c to trigger_analog.c
Rename the mcu based load_cell_probe code to trigger_analog.  This is
a rename of the C code files, struct names, and command names.  There
is no change in behavior (other than naming) with this change.

This is in preparation for using the load_cell_probe functionality
with other sensors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Timofey Titovets
2e0d746172 ldc1612: trigger error on high frequency
If the sensor coil is disconnected, the frequency is equal to the reference.
If the sensor is misconfigured or damaged, the coil frequency is
greater than 1/4 of the reference frequency.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-01-08 12:00:45 -05:00
Timofey Titovets
c6c7614972 ldc1612: ignore amplitude errors during homing
Amplitude errors are useful but often too aggressive.
On some sensors, it is not possible to avoid them completely.
Make them non-critical for homing.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-01-08 12:00:45 -05:00
Timofey Titovets
f7ddb40037 ldc1612: handle i2c errors
I2C error means we don't know the sensor status.
Force data output to the host and cancel homing.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-08 12:00:45 -05:00
Kevin O'Connor
e605fd1856 stm32: Improve accuracy of hardware pwm cycle time
Some checks failed
Build test / build (push) Has been cancelled
Use a different method of setting the hardware pwm registers so that
the actual cycle_time is much closer to the requested cycle_time.

Also, remove the now unused stm32_timer_output command, as the main
hardware pwm interface provides the same accuracy.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-06 21:53:29 -05:00
Kevin O'Connor
e60fe3d99b stm32: Fix off-by-one error in the prescaler calculation in hard_pwm.c
Some checks failed
Build test / build (push) Has been cancelled
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-02 14:35:08 -05:00
Kevin O'Connor
74a15f4834 stm32: Minor comment and code organization changes to hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-02 14:35:08 -05:00
Timofey Titovets
05ce956456 stm32: fix static clock output for faster chips
Some checks are pending
Build test / build (push) Waiting to run
If pcycle_time is scaled, the value should be scaled as well

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-12-31 12:03:54 -05:00
Kevin O'Connor
ae3eb30f28 stm32: Enable MOE bit in hard_pwm.c for all stm32 chips
Always enable the MOE bit.  Reported by @tt33415366.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-31 11:34:15 -05:00
Kyoungkyu Park
dd625933f7 avr: add lgt8f328p support
Some checks are pending
Build test / build (push) Waiting to run
Signed-off-by: Kyoungkyu Park <choryu.park@choryu.space>
2025-12-30 21:51:15 -05:00
Kevin O'Connor
7377da63b7 stm32: Declare gpio_timer_setup() as static in hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-30 18:16:40 -05:00
Timofey Titovets
ec0eb4a8bf stm32: hard pwm allow scale PWM frequency
To support the cartographer, it is required to output 24 MHz.
With current defaults max output frequency is:
48 MHz/256 = 187.5 KHz
Adjusting the PWM scale allows for ramping up the frequency.

To not mess up with existing PWM users,
define the STM32-specific command.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-12-30 18:14:37 -05:00
Timofey Titovets
12cc944fa0 stm32: F042 define PB4 HW PWM
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-12-30 18:14:37 -05:00
Kevin O'Connor
dc622f4ac3 stm32: Allow disabling double buffering transmit in usbfs.c
Some checks failed
Build test / build (push) Has been cancelled
Only enable double buffering transmit if
CONFIG_STM32_USB_DOUBLE_BUFFER_TX is set.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:57:50 -05:00
Kevin O'Connor
c3b660dfbe stm32: Simplify USBx_IRQn per-chip definitions in usbfs.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:57:50 -05:00
Kevin O'Connor
59a754c48c stm32: Implement manual double buffering tx for usbotg
It is possible for USB host controllers to send back-to-back IN tokens
which only gives the MCU ~3us to queue the next USB packet in the
hardware.  That can be difficult to do if the MCU has to wake up the
task code.  The stm32 "usbotg" hardware does not support a builtin
generic double buffering transmit capability, but it is possible to
load the next packet directly from the irq handler code.  This change
adds support for queuing the next packet destined for the host so that
the USB irq handler can directly load it into the hardware.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:57:50 -05:00
Kevin O'Connor
a3e24d2172 rp2040: Add support for ADC on rp2350b chips
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:56:13 -05:00
Kevin O'Connor
3a3e9fa2f1 rp2040: Support rp2350b extra gpios
Add support for gpio31 through gpio47 on rp2350, as these pins are
available on the rp2350b chips.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-18 20:56:13 -05:00
Kevin O'Connor
3f72e519ed atsamd: Fix possible buffer overflow in usbserial.c
The USB buffer size register PCKSIZE.SIZE was not being assigned
correctly.  As a result, it was possible for an incoming USB
transmission to write past the allocated buffer space, which could
corrupt memory of other storage.  In particular, in some cases gcc may
layout ram in such a way that the trailing bytes of an incoming
message might overlap the buffer for an outgoing message.  This could
cause sporadic transmit errors and unstable connections.

Fix by correctly configuring the PCKSIZE.SIZE register.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-17 10:18:39 -05:00
Kevin O'Connor
d92dda439e lib: Update pico-sdk to v2.2.0
The new rp2350 chips with A4 stepping require pico-sdk v2.2.0 .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-17 10:12:52 -05:00
Kevin O'Connor
a6a6b21e4d armcm_timer: Use a static instruction count for TIMER_MIN_TRY_TICKS
Change TIMER_MIN_TRY_TICKS from 2us to 90 instructions.

On newer chips 2us is a large amount of time - for example on the
520Mhz stm32h723 it would be 1040 instructions.  Using a large time
can result in "busy waiting" in the irq handler when the cpu may be
better spent running tasks.

The armcm_timer.c code is used on most ARM cortex-M chips and on all
of these chips the SysTick timer should be tied directly to the
instruction counter.  This change should be safe because it should not
take more than 90 instructions to reschedule the timer on any of these
chips.  Also, all of these chips should be able to exit the irq
handler and reenter it in less than 90 instructions allowing more time
for tasks to run if the next timer is more than 90 timer ticks in the
future.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-03 17:47:50 -05:00
Kevin O'Connor
3a700a5f62 timer_irq: Remove TIMER_IDLE_REPEAT_TICKS special case
The TIMER_IDLE_REPEAT_TICKS was intended to reduce the number of cases
where timers would defer to tasks when tasks are mostly idle.
However, with commit ea546c78 this became less important because
timers now only defer to tasks if tasks are consistently busy for two
consecutive calls to sched_check_set_tasks_busy().

The TIMER_IDLE_REPEAT_TICKS mechanism could result in extended task
delays if timers do become busy.  Timers can become busy in normal
operation if timers are scheduled to run more than 500,000 times a
second (every 2us or faster).  This can occur on stepper movement when
using high microstep settings.  If timers become busy, it could take
up to 1ms for tasks to next be given an opportunity to run (two calls
to sched_check_set_tasks_busy() at 500us per call).  This wouldn't
typically be an issue if tasks are also busy, but in some loads tasks
may need to run periodically in such a way that the task status
alternates between idle and busy.  In this case, the
TIMER_IDLE_REPEAT_TICKS mechanism could effectively limit the number
of task wakeups to only ~1000 per second.

The "USB to canbus bridge" code uses tasks to transfer data to/from
USB and canbus.  If timers become busy, the limiting of task wakeups
could lead to a situation where the effective bandwidth becomes
severely constrained.  In particular, this can be an issue on USB
implementations that do not support "double buffering" (such as the
stm32 usbotg code).  There are reports of "Timer too close" errors on
"USB to canbus bridge" mode as a result of this issue.

Fix by removing the TIMER_IDLE_REPEAT_TICKS check.  Check for busy
tasks every TIMER_REPEAT_TICKS instead (100us).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-12-03 17:47:50 -05:00
Timofey Titovets
938300f3c3 stm32: f0 i2c clean nackcf interrupt on handle
Some checks failed
Build test / build (push) Has been cancelled
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-11-26 14:31:54 -05:00
Alistair Buxton
39ac48339a neopixel: Increase PULSE_LONG_TICKS to 800 for compatibility
This timing is also known as T1H in various datasheets. Increasing it
should improve compatibility with various revisions and clones of the
WS2812 LED.

The short version is that 800 is the timing used by Adafruit's popular
NeoPixel Arduino library, and it has no problem driving my BTT RGBW kit
LEDs, while Klipper cannot drive them properly without this patch. The
real upper limit to this value is something like 5000ns so increasing
it should not cause new compatibility problems for LEDs that currently
work.

Signed-off-by: Alistair Buxton <a.j.buxton@gmail.com>
2025-11-13 15:15:28 -05:00
Kevin O'Connor
99c0bfca4f stm32: Fix RTR and EFF canbus tx requests in can.c
Some checks failed
Build test / build (push) Has been cancelled
Commit 3f7d05dd attempted to add support for transmitting RTR and EFF
frames to stm32/can.c , but the change was incomplete.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-27 12:22:38 -04:00
Kevin O'Connor
3fe594ef20 sensor_lis2dw: Read 8 samples at a time from sensor fifo
Some checks failed
Build test / build (push) Has been cancelled
Batch reading of 8 samples (48 bytes) at a time from the sensor.  This
reduces the number of transactions - which can notably improve
performance on i2c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-13 20:36:11 -04:00
Kevin O'Connor
6269dda56b sensor_lis2dw: Fix fifo_empty check on lis2dw chips
Some checks are pending
Build test / build (push) Waiting to run
Fix inverted check for fifo empty.  The fifo is empty when the number
of entries in the fifo is zero.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-09 19:06:44 -04:00
bigtreetech
366fb423c5 stm32: Add spi2_PB6_PB7_PB8 and spi3_PC11_PC12_PC10 for stm32g0
Signed-off-by: Alan.Ma from BigTreeTech tech@biqu3d.com
2025-09-28 22:00:58 -04:00
Kevin O'Connor
af17c8c238 stm32: No need to special case GPIOI in spi.c
Some checks failed
Build test / build (push) Has been cancelled
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-26 12:28:19 -04:00
Kevin O'Connor
6e73181c47 stm32: No need to special case GPIOI in stm32h7_spi.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-26 12:28:19 -04:00
Kevin O'Connor
870c0437e9 stm32: Verify pin is valid in gpio_peripheral()
Convert direct lookup of digital_regs[] to a new gpio_pin_to_regs()
function that first validates the pin.  This should help prevent
invalid memory accesses if an invalid pin is provided.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-26 12:28:19 -04:00
bigtreetech
1be6c0fce0 stm32: change GPIO_FUNCTION_ALL to SPI_FUNCTION
Some checks failed
Build test / build (push) Has been cancelled
Signed-off-by: Alan.Ma from BigTreeTech tech@biqu3d.com
2025-09-19 12:19:15 -04:00
bigtreetech
61252819e3 stm32: Clean up SPI code on spi.c
Signed-off-by: Alan.Ma from BigTreeTech tech@biqu3d.com
2025-09-19 12:19:15 -04:00
bigtreetech
e8e88415ea stm32: Clean up SPI code on stm32h7_spi.c
Signed-off-by: Alan.Ma from BigTreeTech tech@biqu3d.com
2025-09-19 12:19:15 -04:00
minicx
b817848567 stm32: enable 64KiB bootloader for n32g45x, clarify Makefile output
Some checks are pending
Build test / build (push) Waiting to run
- Allow selection of 64KiB bootloader offset for MACH_N32G45x in Kconfig

Signed-off-by: Lev Voronov <minicx@disroot.org>
Co-authored-by: Alexander Simonov <me@darksimpson.com>
2025-08-21 15:24:46 -04:00
minicx
3a11645afe
stm32: Fix N32G45x ADC pin mapping (#7016)
Fixes PA0 (GPIO 0) incorrectly mapping to ADC1_IN0 due to
collision with placeholder zeros.

Signed-off-by: Lev Voronov <minicx@disroot.org>
Co-authored-by: Alexander Simonov <me@darksimpson.com>
2025-08-21 11:41:07 -04:00
BIGTREETECH
d34d3b05b8
stm32: Add i2c2_PA7_PA6 and i2c3_PA7_PA6 for stm32g0 (#7007)
Some checks failed
Build test / build (push) Has been cancelled
klipper3d deploy / deploy (push) Has been cancelled
Signed-off-by: Alan.Ma from BigTreeTech <tech@biqu3d.com>
2025-08-15 13:43:43 -04:00
Kevin O'Connor
116b304541 avr: Switch to input state prior to enabling pullup in gpio_in_reset()
If switching a pin from output low to input with pullup, there is an
intermediate state of either driven high or high impedance without a
pullup.  Similarly, when switching from output high to input without a
pullup, there is an intermediate state of either driven low or high
impedence with a pullup.  In both cases it is preferable for the
latter transition.

Also, calculate the final setting prior to making any changes to
reduce the time in that intermediate state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-07-22 14:11:17 -04:00
Kevin O'Connor
3219712c17 i2c_software: Place wires in high impedance state after setup
Don't leave the wires in a high output state during setup - leave them
in a high-impedance with pullup state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-07-22 14:04:50 -04:00