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>
When initializing the ADC, explicitly clear the registers (instead of
logically or'ing them with their previous values).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It appears the most common type of avrdude protocol for devices other
than the atmega2560 is the "arduino" protocol. Update the build to
select a different protocol based on the avr processor type.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
On the AVR platform (and possibly others) the longjmp() call will
restore the interrupt state saved during the setjmp() call. So, the
setjmp() call must be invoked with interrupts disabled to ensure that
shutdown handling is run with interrupts disabled. This fixes
potential corruption of the shutdown processing on AVR.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Properly handle the (unlikely) case that a schedule_soft_pwm_out
command is received before a previous command is fully processed,
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Only open the watchdog device after the console has been opened. The
machine should not reboot in the unlikely event the console can't be
opened.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow the start value to be different from the default/shutdown value
for the pin. This will be useful for "heater fans" that should
startup in the off state, and transition to full on in a shutdown
state.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Continue to sample the ADC input pins even if the MCU goes into a
shutdown state. This enables the printer to continue reporting
temperatures even on an mcu error.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Pass the sample_ticks and sample_count parameters directly in the
end_stop_home command instead. This simplifies the code.
Also, simplify calculation of next wakeup time in
end_stop_oversample_event().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>