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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
Some devices can return a read NACK on host retries.
When the MCU receives the I2C CMD, reads out data,
but fails to deliver a response to the host.
The host retries, the device returns NACK,
and the MCU goes into the shutdown state.
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
The more.musl.cc site is blocking downloads from all github actions,
which makes it difficult to use that site for the ar100 cross build
toolchain. Convert to the openrisc or1k-elf toolchain as a
replacement.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The rp2040 uses a pll vco divider of 6. Prefer setting postdiv1=6 and
postdiv2=1 (instead of the previous postdiv1=3 and postdiv2=2).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Completely filling the spi transmit fifo could lead to a situation
where the rx fifo overflows. Make sure not to write past the rx fifo
size.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Completely filling the spi transmit fifo could lead to a situation
where the rx fifo overflows. Make sure not to write past the rx fifo
size.
Also, be sure to wait for the transmission to fully complete before
exiting spi_transfer().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Avoid unnecessary (HAVE_STM32_CANBUS && MACH_STM32xx) checks in
Kconfig. The HAVE_STM32_CANBUS is a helper symbol for all the chips
that support canbus, there's no need to mix it with a check for a chip
that is already known to have canbus.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Validate host provided index prior to accessing memory using that
index.
Also, consistently use a uint8_t for max_sections (to account for
integer overflow issues).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>