Some architectures do better if the global variables accessed from the
timer dispatch code are in a struct.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Some versions of gcc, in some cases, decide that it is OK to move the
read to `INTR` to right after clearing the `SETUP_REC` bit of
`SIE_STATUS`, instead of after the `memcpy`.
The rp2040 datasheet doesn't appear to say anything about how quickly
the `SETUP_REC` bit will be cleared in `INTR`, but regardless the
compiler should not be re-ordering the read like this.
Here we force the correct ordering using a memory barrier.
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
Copy the parameters of calls to console_sendf() on pru1 to pru0 and
then call that function on pru0. Although copying the parameters is a
"hack", the code size reduction is notable.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The F042 and F072 chips are in the same series and the code should be
nearly identical for these chips. Implement the alias and enable USB
for the F072 chips.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The previous OSPEEDR value of 0x2 was copied from the stm32f4.c code,
but the stm32f0 interprets that value the same as 0x0 - which is "low"
speed. Change the OSPEEDR value to "medium" speed so that it matches
the configuration of stm32f1 chips.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This change has been expanded to include all STM32F4 processors, since they share a common TIMER mapping with some processors just not having all of the timers and pins.
Signed-off-by: Jerome Helbert <jerome@helbert.net>
This commit contains a configuration for the Anycubic Vyper printer from 2021.
It uses a clone of the STM32F103 chip named GD32F103.
There are 2 Mainboard versions out there v0.0.5 and v0.0.6, this config has
been tested with the v0.0.6 only. It should probably work for v0.0.5 as well
since there are no different changes in the Anycubic Marlin firmware.
The LCD is not supported yet (might work, but didn't try yet).
Signed-off-by: Marc Neuhaus <marc@neuhaus.nrw>
Signed-off-by: Manuel Fichtner <manuel.fichtner@me.com>
The F405, F407, and F429 chips are in the same series and almost all
code definitions should apply to all chips in that series. Implement
the alias and fix defintions in adc.c and Kconfig that were only
applying to a subset of that series.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Transmit data from mcu to host using 5 bytes per sample and up to 10
samples per message block. This improves bandwidth efficiency.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Query the adxl345 message counter every 100ms so that accurate timing
can be obtained during measurements. This allows the adxl345 data to
be exported with timestamps while captures are running.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This fixes a PWM going to full scale output when a initial value != 0 was
given. The output was on 100% until another update occurred.
This change enables the PWM counter before setting the channel values.
FixesKevinOConnor/klipper#4559
Signed-off-by: Michael Kurz <michi.kurz@gmail.com>
The atmega328pb supports PORTE, but the current avr-libc toolchain
doesn't support the atmega328pb. So, for now, add support for PORTE
to atmega328p.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The atmega328pb has officially named these pins as PE2 and PE3, so use
that naming scheme instead of the previous Klipper invented names.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add support for USART1 on PB7/PB6.
Remove STM32_SERIAL_USART1_ALT_PA15_PA14 option and allow all serial
mappings to be used on stm32f031.
Reported by @Desuuuu.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The Eryone ER-20 is a STM32F103 based 3D printer which ships with a 16KiB bootloader. Their official version of Marlin starts at 0x08004000.
Signed-off-by: Simon Hawkenson <simon@hawkenson.ca>
This implements SPI for the rp2040 target. All output groupings of both
SPI blocks are available for use.
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
This implements hardware PWM support for the rp2040. The maximum
value(100% duty) is set to 255 to match the other controllers. Cycle
time is clamped automatically, and uses the full 8.4 fractional range of
the rp2040 PWM block. This allows a maximum PWM frequency of 490kHz and
a minimum frequency of 1915 Hz.
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
The rp2040 doesn't have a chip ID, but the flash chip connected does. We
can get this ID by asking the flash chip directly, but doing so requires
disengaging the XIP layer, performing the interrogation of the flash
chip, and then re-enabling the XIP layer. This gives us a 64-bit unique
ID that we can use as our USB serial number.
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
In binutils 2.36 and above the -nostartfiles option is no longer
ignored. -nostartfiles is actually a gcc option, and so isn't supported
by ld. Earlier versions of binutils however had less error checking, and
thus just ignored the option.
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
Support the rp2040 (as tested on a Raspberry Pi Pico board). This
adds basic uart, timer, gpio, and watchdog support.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use CONFIG_MACH_AVR instead of CONFIG_CLOCK_FREQ to check for slow
mcus. Some fast MCUs do not export a high clock frequency.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Add menuconfig option for stm32f072
* Add support for internal temp of stm32f072
* Share the temperature calculation logic between stm32f0x2 MCUs
Signed-off-by: Erik Henriksson <erikhenrikssn@gmail.com>
This reverts commit 70ea0806d9.
The above commit breaks software spi on linux hosts. Revert that
commit until an improved error check can be implemented.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 6a3c357a incorrectly disabled support for USART3 on stm32f1 and
stm32f2 - restore that support.
Also, add support for USART3 on PD9/PD8 on stm32f103.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
These commands were never used by the main code and are not
particularly helpful for debugging. Remove them to reduce code size -
in particular on the pru architecture.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit ae89a659 caused a regression in the lpc176x UART handling.
After that commit the UART clock divisor would need to be 6.25 on
lpc1768 or 7.5 on lpc1769, but the code only supports whole numbers.
Set the PCLKSELx registers at startup and return to using full speed
peripheral clocks.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
On architectures that poll for irqs, check for any pending irqs prior
to checking if tasks are idle.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The timer_read_time() call can be expensive - when the next timer is
definitely pending, avoid making that call.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Implement rescheduling math using the simple 32-bit timer instead of
the Unix timespec struct. This makes the code simpler and doesn't
adversely impact the overall performance.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Some bootloaders do not disable peripherals in use before jumping to the application. Reset peripherals to assure correct operation.
SIgned-off-by: Eric Callahan <arksine.code@gmail.com>
This adds hardware PWM support for STM32F1 processors.
This should also work for STM32 F0/F2/F4 processors, but I
don't have one of those to test it.
Signed-off-by: Michael Kurz <michi.kurz@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The lpc176x has an errata that could cause updates to PCLKSELx to not
take effect. Rework the code to use the default peripheral clock
speed (25Mhz or 30Mhz) so that this register does not need to be
updated at runtime.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rework the micro-controller command protocol so that it supports
direct communication with the serialqueue.c code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This adds new config options for fans: 'tachometer_pin' to specify the
GPIO pin, and 'tachometer_ppr' (default 2) to specify the number of
signal pulses per revolution. The rpm is also exposed by get_status for
command templates and the API server. For fast fans (at least 10000
RPM), the polling interval can be shortened using the
'tachometer_poll_interval' option.
There is a new mcu object for a generic edge counter, which repeatedly
polls a GPIO pin and periodically reports the count to the host.
Signed-off-by: Adrian Keet <arkeet@gmail.com>
* Add F429 variant; add CAN on PD0,PD1; add 25Mhx clock; move CAN1_RX from PI8 to correct position (PI9)
* Add test for STM32F429
Signed-off-by: Arkadiusz Raj <arek.raj@gmail.com>
Writes over 496 bytes don't fit in a single "rpmsg" page. Request the
host limit the number of bytes outstanding to avoid getting "write:
(22)Invalid argument" errors.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Separate out the high-level command processing logic from the
low-level transmission code. Place the high-level code in
src/generic/canbus.c .
This also removes the CAN dependency on serial_irq.c .
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Don't perform any heavy tasks in the CAN interrupt handler - just
notify a background task to handle anything pending.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The spec states that the TX fifo is transmitted in chronological order
if the TXFP bit is set, but it's unclear if the software needs to fill
the tx fifo in a particular order to obtain that result. Use the TSR
CODE bit field to fill the TX fifo in the order that the hardware
reports as next.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Prefer explicitly setting the hardware registers and avoid using C
read and modify instructions where possible. This avoids race
conditions where an interrupt or hardware change could cause subtle
corruption of the register state.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Initial commit of code to support 1-wire (Dallas) sensors such
as the DS18B20. Requires Linux kernel drivers to create a file
in /sysfs which is read by this module, and temperature
typically returned to a temperature_fan.
Signed-off-by: Alan Lord <alanslists@gmail.com>
Signed-off-by: Josh Headapohl <joshhead@gmail.com>
The digital output commands implement a subset of the software pwm
commands. Change the host code to just use the software pwm commands
and simplify the micro-controller code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The HSI48 clock on the stm32f042 isn't as accurate as the main HSI
clock. So, only use the HSI48 clock when using USB to synchronize
that clock.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The code isn't actually capable of altering the mux registers due to
hardware checks enforced by the chip. Disable that code to save a few
bytes in the final binary.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If the buffer pointer can't fit in a uint32_t then pass a relative
buffer offset instead. This fixes buffer handling on 64bit linux
mcus.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a helper function to convert from a string buffer passed in the
args[] parameter to an actual pointer. This avoids all the callers
needing to perfrom pointer manipulation.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Restore the default of an 8KiB bootloader for stm32f103 and a 32KiB
bootloader for stm32f207/stm32f407.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Improved CAM bus ID generation, there were issues with ID collisions.
Added a small fast hash library.
Signed-off-by: Pontus Borg <liquidpontus@yahoo.se>
Only write "1" to the "enable" file when a non-zero pwm width is
requested. Write "0" to the "enable" file when a zero pwm width is
requested.
This fixes a problem on the replicape servo lines that prevented them
from being fully disabled.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The lpc176x hardware spi initialization code was swapping the CPOL and
CPHA bits. This caused the MAX31865 and MAX31856 chips to not work
correctly.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Reworked the STM32F0 CAN bus implementation. It's more robust and higher performance.
Added support for function remapping to different pins. API is emulating an STM32F0.
Improved and ported CAN bus to STM32F0, F1 and F4.
Signed-off-by: Pontus Borg <glpontus@gmail.com>
Initial support for stm32f2 in general and STM32F207 in particular.
Boots up and communicates on STM32F207VC.
Signed-off-by: Boleslaw Ciesielski <combolek@users.noreply.github.com>
Use 2us in the linux timer dispatch code to unify linux timer dispatch
logic with the common timer_irq.c code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change the product/vendor id to 0x1d50/0x614e, which has been reserved
for Klipper (thanks to the openmoko project).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
On the Linux mcu, toggling the pin after the time is read is not
valid. Make that optimization dependent on CONFIG_HAVE_STRICT_TIMING.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a new build definition to note micro-controllers that have strict
timing. The Linux mcu code does not have strict timing - all other
targets currently do.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Endpoint 0 OUT needs to NAK everything until the core signals that the
setup stage is complete.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
A setup packet is only valid after receiving the "setup complete"
notification.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The beagleboard TI kernel 4.14 and 4.19 contain a commit which change
the device names ("pwm: Create device class for pwm channels") from
pwmN to pwm-${chip}:N. This commit was never merged into the upstream
kernel.
Decrease the number of pwm channels to a more reasonable 16. Increase
the number of pwm chips to 8 since the replicape servo pwm outputs are
on pwmchip4.
Update replicape code to detect appropriate channel.
Signed-off-by: Janne Grunau <janne-gh@jannau.net>
There are reports that SKR mini boards have more stable ADC results
when running the ADC at a slower frequency.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Explicitly disable the SysTick interrupt and explicitly set the stack
pointer, as some bootloaders aren't handling this correctly.
Signed-off-by: Chris Lombardi <clearchris@hotmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This reverts commit a2c309a2b0.
The above commit is causing crashes on the stm32f103xb chip when spi
is in use. It's unclear what the cause of the regression is, but the
optimization isn't required so revert it until the root cause can be
determined.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit bd6c25c9 introduced a typo that caused the clock divisors to
not be set correctly on stm32f1.
Reported by @brianrjones69.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The host code always issues a get_config command immediately after
finalize_config, so there is no need to send the two config response
messages.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
In addition to spi3, spi1 and spi2 also have alternate pins. Add them as
spi1a and spi2a, similar to spi3.
Signed-off-by: Arne Jansen <arne@die-jansens.de>
The stm32 has a small queue for spi tx/rx. The current code only uses the
spi with a single byte buffer, effectively waiting for each byte to complete
before starting the next transfer.
This patch changes the structure of spi_transfer() to make use of the queue
and achieve back-to-back transfer of bytes on spi.
Signed-off-by: Arne Jansen <arne@die-jansens.de>
The current code accesses the DR as 32 bit. This enabled data packing mode,
effectively adding a 00 byte between each sent byte. The receive side had
similar problems.
To prevent this, all accesses are 8 bit now, even though this is not
necessary on stmf[14].
Signed-off-by: Arne Jansen <arne@die-jansens.de>
A fast micro-controller may update the gpio pins faster than the
hd44780 chip can handle. Add in the appropriate delays.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change the "product id" from the redundant "Klipper firmware" to the
CONFIG_MCU value. For now, only make this change on boards that have
CONFIG_HAVE_CHIPID set.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Derived from stm32/adc.c and stm32f0/adc.c with additional changes.
Tested on Monoprice Mini Delta (malyan) stm32f070xb board.
Signed-off-by: Chris Lombardi <clearchris@hotmail.com>
Move armcm_main() to stm32f0.c, stm32f1.c, and stm32f4.c. This gives
the arch specific code more control on the early boot setup.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The main() function has a special meaning to gcc and using it can
result in different code generation. Use armcm_main() to avoid that.
Also, invoke SystemInit() from the board specific armcm_main() code.
This gives the board code more control over board initialization.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The stm32f0 line uses 16bit packet memory reads/writes (as opposed to
the goofy 32bit accesses required on the stm32f103).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
When enabling "low level options" in Kconfig, selecting a chip that is
20Mhz capable would result in 20Mhz being the default. A 16Mhz speed
is the preferred default, so list that first in the menu.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The FIOSET and FIOCLR registers may not set an initial value if the
pin is not in an output mode. So, use FIOPIN to set the initial
value.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The usbfs receive buffers must also have space for the 2 byte crc at
the end of a transmission. This fixes an error that could lead to
lost messages from mcu to host (resulting in bytes_invalid increasing
in stats) on the stm32f103.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>