These two files from atmel have different licenses than the other
files. Neither files provide any real value, so just remove them to
avoid any confusion.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Pass the gpio id instead of the bank/pin to gpio_peripheral(). This
is in keeping with other ARM ports.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Scale the bus speed within the peripheral instead of on the system bus
as scaling on the system bus slows down general register access to the
peripheral.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Simultaneously define the hardware pin and the timer registers. This
makes the table a little easier to understand.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Increase the amount of time to "busy wait" in the timer dispatch loop
to 2 micro-seconds. This, in practice, causes stepper step and unstep
events to occur within a single hardware interrupt. Doing that helps
stabilize the single active stepper performance benchmarks.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The atmega328p is basically the same as the atmega328 - add explicit
support for it so that avrdude doesn't complain while flashing.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Sometime bossac reports an error during chip restart. It appears this
error is spurious - just suppress it.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Scaling the timer on the system bus has a notable impact on
performance. So, scale the timer within the timer hardware itself.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It appears the sam3x8e has a primitive cache prefetch mechanism (it
prefetches 32 bytes at a time aligned to a 16 byte boundary).
Aligning the main loop in timer_dispatch_many() to a 16 byte boundary
significantly improves performance.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If sched_try_shutdown() is not inlined into timer_dispatch_many() it
can have a significant impact on benchmarks. (Even though the
function isn't called in practice, the call causes gcc to organize the
function differently.)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Some older versions of gcc need the __always_inline directive in order
to inline timer_read_time. Inlining that function is important for
performance on the stm32f1.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
As long as timer_read_time() is inlined, I get better performance with
gcc -O2 optimization. The binary is also dramatically smaller and O2
better matches the other platforms.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's possible for the code to stay in the timer irq for up to 100ms,
so serial irqs should have a higher irq priority to prevent them from
being starved. (The timer code disables irqs during event dispatch,
so serial irqs would only be permitted between events anyway.)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The usb_cdc code will arrange to call usb_read_ep0_setup() after a
shutdown, so no need to have an explicit shutdown handler.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Call usb_read_bulk_out() before calling command_find_and_dispatch() as
this optimizes the common case where each usb packet contains a single
new message block.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Recent code additions have increased the stack usage and it is no
longer clear that everything will fit in 128 bytes. Increase all
targets to 256 bytes (the atmega2560 was already at 256 bytes).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Fix travis-ci build failure by forcing the data field of the struct
usb_string_descriptor to be the same type as a 16bit unicode string.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use new usb_read_ep0_setup() function when reading a setup packet -
this allows the low-level usb hardware code to better handle errors.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
A zero length packet should only be sent at the end of a transmission
if the host is expecting more data.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Maintain the state tracking code entirely within a usb_do_xfer()
method. This simplifies the callers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use "ep0" when referring to endpoint0 - don't use "setup" as that can
be confused with the low-level usb setup token.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The atmega168 doesn't have enough flash space to fit all features -
disable the "bit banging" interfaces to make room.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The bank_id was calculated erroneously. Also unify gpio_in_setup and gpio_out_setup a bit. Also disable make flash for the sam4e8e port as it currently references a version of bossac that is not present on all systems.
Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
This can be flashed to e.g. the duet wifi using bossac. It requires a
later version as is currently included in the klipper repo (1.8
vs. 1.2). Comms are currently via UART0 only, USB serial is still TBD
Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
It's common for boards to have restrictions on the type of each
endpoint. So, make it possible for the board to select the endpoint
ids for each endpoint.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
No need to include separate cmsis files from the mbed project - the
standard CMSIS_5 files work fine.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update the sam3x8e port use the most recent SAM3X CMSIS files from
Atmel. The Atmel files appear to have a more consistent license and
it is unclear if there were Arduino specific changes in the CMSIS
files obtained from the Arduino repo.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Send the temperature before checking for an out of range error (that
makes it easier to debug).
The query_thermocouple clock parameter is unpredictable and a value of
zero can't be used to disable the query - use rest_ticks instead.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The MAX6675 chip has a different read sequence than the MAX31855 chip.
Signed-off-by: Ricardo Amézquita <ramezquitao@cihologramas.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change the simulator to use the generic timer_irq.c and serial_irq.c
code for (dummy) timer and io handling. This is just to make the code
a better example for other developers (most micro-controllers will use
the timer_irq.c and serial_irq.c code).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The SPI interface needs to be enabled and configured to the correct
settings of a given oid before CS is asserted. The new function
spi_prepare() allows ports to do that.
This port only introduces the new function in all ports with no
implementation and adds the call to the Klipper generic firmware code.
That means everything still works as before. Ports need to be changed
to fix the underlying issue.
Discussion about the motivation here:
https://github.com/KevinOConnor/klipper/pull/453#issuecomment-403131149
Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
Add basic SPI support and associated documentation.
v2: remove baud rate check, fix baud rate calculations
v3: finish transaction with BSY check, disable SPI when not in use
Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
Extend the ADC out of range check so that it is possible to sample
multiple times before going into a shutdown state. This reduces the
chance that measurement noise will cause an error. In an actual over
temperature (or under temperature event) it is expected that the
sensor will consistently report the problem, so extra checks for an
additional second or two should not substantially increase risk.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add mcu support for periodically polling for a button press. Add host
code support for registering buttons and invoking callbacks for them.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
For some reason, the upper two pin definitions were missing. Found while
writing the port documentation.
Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
Add a command that can immediately set the value of a digital output
pin created with config_digital_out.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The AVR requires that the SS pin be an output pin for correct SPI
operation. Some boards use the SS pin to control devices separate
from SPI, however. Don't change the output level if the pin is
already an output, and prefer setting it low if it is not already an
output pin.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The PRU code size has grown too close to the maximum - remove the ADC
code to reduce its overall size. (On the beaglebone, the Linux
process can, and typically does, do the ADC reading.)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It appears the st7920 requires a longer delay when switching from
command to data mode (and vice-versa). Slower MCUs don't show a
problem because the klipper command processing time results in a
sufficient delay. However, some of the faster MCUs can process
klipper commands fast enough that the next st7920 transfer is sent too
fast. Add an additional delay to account for this.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change the get_status command to get_clock. Don't report the shutdown
status in the new get_clock command.
The primary purpose of this change is to force the host code to report
a firmware version mismatch with older firmwares as recent changes
(namely the ordering of message block acks) have subtle
incompatibilities if different host/mcu code is used.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Normally, the MCU is restarted on a config change. However, that
should not be done automatically if the MCU is in a shutdown state.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If the mcu is using a traditional serial port, then only send a new
message block if there is space available in the mcu receive buffer.
This should make it significantly less likely that high load on the
mcu will result in retransmits.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Send the ack after processing commands - this gives the host code more
information on serial buffer utilization.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Prefer using 'uint8_t' buffers as it is too easy to run into C sign
extension problems with 'char' buffers. Prefer using 'uint_fast8_t'
for buffer lengths as gcc does a better job compiling them on 32bit
mcus.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The gpio_out_toggle() function in the sam3x8e and stm32f1 code was
only valid if it was called with irqs disabled.
Commits 018c5daa and 9c52ad43 enabled the lcd code which called
gpio_out_toggle() with irqs enabled. This could cause corruption of
the gpio state.
Introduce a gpio_out_toggle_noirq() function that will only be invoked
with irqs disabled, and fix gpio_out_toggle() on sam3x8e and stm32f1
so that it safe to call even if irqs are enabled.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use the generic spi send/receive code on Linux. Update the replicape
code to use the updated command format.
Also, update the replicape code to turn off the stepper motors on a
shutdown event.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Improve the SPI message transmit system. Add support for bus speed
and bus mode. Add support for sending SPI messages on shutdown.
Signed-off-by: Petri Honkala <cruwaller@gmail.com>
Signed-off-by: Douglas Hammond <wizhippo@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The AVR chips (bizarrely) start an ADC conversion when entering Idle
mode. This behavior can cause the ADC to be busy when a sample is
required. Worse, if a series of events cause the cpu to enter and
leave Idle mode with a timing similar to the ADC checking rate then it
can cause the ADC to show as busy for extended periods. This could
cause high MCU load and possibly lead to a "Rescheduled timer in the
past" shutdown.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Don't logically or the ADSC bit on the start of a conversion -
explicitly set the full contents of the register. Also, clear the
ADIF flag on each write.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Define unique register aliases for all of the hardware serial port
definitions. This makes it easier to deal with the AVR chips that use
different register names.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Extract out common code from avr/serial.c, sam3x8e/serial.c, and
stm32f1/serial.c into a new generic/serial_irq.c file.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
With the optimized timer_read_time() it is no longer necessary to
implement custom timer dispatch code - use the generic mechanism in
timer_irq.c. This simplifies the code and provides a small
performance increase.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Implement 32bit timer conversion without disabling interrupts. This
uses the 16th bit of timer_high as a rollover detection flag.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a fully functional STM32F1 port, currently mostly targeting STM32F103
microcontrollers. This requires an 8 MHz XTAL. The maximum possible step rate
is around 282K steps per second.
This uses stm32flash to burn the firmware. The bootloader needs to be started
by setting BOOT0 to 1 and resetting the MCU. There is no automatic bootloader,
unlike on Arduino.
Signed-off-by: Grigori Goronzy <greg@kinoho.net>