Commit Graph

703 Commits

Author SHA1 Message Date
Eugene Krashtan b822f38923 stm32f0: New target STM32F0 added.
Signed-off-by: Eugene Krashtan <Eugene.Krashtan@opensynergy.com>
2019-03-24 12:10:11 -04:00
Kevin O'Connor d76658756e stepper: Fix reset_step_clock corruption due to bitset typo
Commit b9b03dd0 had a typo in the flag updating.  The typo could
result in corruption of the stepper state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-19 20:57:17 -04:00
Kevin O'Connor 746a378c18 endstop: Use "pin_value" instead of "pin" when querying endstop state
Now that enumerations are available, any variable named "pin" can only
be used to describe a gpio pin.  Rename the end_stop_state "pin"
parameter to "pin_value".  Also, rename "end_stop_query" command to
"end_stop_query_state" to notify users to upgrade both host and mcu
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-19 10:48:33 -04:00
Kevin O'Connor 4a35f927fc initial_pins: Add ability to configure output pins at mcu startup
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 20:56:25 -04:00
Kevin O'Connor 0af89e4766 thermocouple: Define thermocouple types using enumerations
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor df6136802a linux: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor ae24baf99a pru: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 91cf497656 stm32f1: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 8aa8feedb8 lpc176x: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 7e2c0ffa91 atsamd: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 8b0195f896 atsam: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 8f541d090e avr: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor db6e2d4c9e msgproto: Convert static strings to a more generic enumeration system
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 7d73a35805 command: Support evaluating C expressions in DECL_CONSTANT()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor b28e95ca1a command: Always pass a string to the DECL_CONSTANT() macro
Make it clear that the name of the constant being defined is a string.
When the value being defined is also a string, use a new
DECL_CONSTANT_STR() macro.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor b9b03dd082 stepper: Require an explicit reset_step_clock after stepper_stop()
If the stepper is stopped by the endstop code, then ignore any further
stepper moves until a reset_step_clock command is received.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 4718f39b2f flash_usb: Run dfu-util via sudo
Default to running dfu-util via sudo as most machines will not have
the user setup with permissions to access the raw usb device.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-11 22:33:24 -04:00
Kevin O'Connor a5aede52cb flash_usb: Try to make the bossac atsam reboot logic more stable
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-10 15:06:41 -04:00
Kevin O'Connor 34d32c7823 stepper: Support an optimized step/unstep function on ARM
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-10 10:27:02 -04:00
Kevin O'Connor 9466c2d66c stm32f1: Add support for entering the bootloader via USB
Add support for entering the "stm32duino" bootloader via the arduino
1200 baud USB request.  Add supprot for flashing over USB via the
"make flash" command.

Rename the existing "make flash" command to "make serialflash".

Default to using a bootloader in Kconfig.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-08 22:22:41 -05:00
Kevin O'Connor 6a16e1f4c5 atsamd: Add support to "make flash" to automatically enter the bootloader
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-08 22:22:41 -05:00
Kevin O'Connor 079fdf8807 atsam: Improve support for flashing over USB
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-08 22:22:41 -05:00
Kevin O'Connor f5b10f0c13 lpc176x: Add support for flashing via "make flash"
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-08 22:22:41 -05:00
Kevin O'Connor 399d539969 Makefile: Reduce use of $^ in build rules
It's rare to use all of a target's prerequisites in a recipe - replace
most cases with $< (the target's first prerequisite).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-02 12:01:44 -05:00
Kevin O'Connor 9430fea2c5 Makefile: Fix lpc176x and stm32f1 builds
Commit e18501d0 broke the build for targets that added objects to
klipper.elf via adding dependencies.  Rework the build so that it is
possible to add objects to klipper.elf via a new OBJS_klipper.elf
makefile variable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-02 11:26:14 -05:00
Kevin O'Connor 309a47c781 atsamd: Reduce memory for have_run_init in spi/i2c
Some of the samd21 chips have limited memory - change the code to
reduce the size of global variables.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-01 19:31:18 -05:00
Kevin O'Connor 946eb6b7ae atsamd: Add definitions for SAMD21E18 chip
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-01 19:05:00 -05:00
Kevin O'Connor 0b33e0b427 atsamd: Implement custom memory allocation functions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-01 19:05:00 -05:00
Kevin O'Connor fbef144e7b atsamd: Use CONFIG_MCU in Makefile
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-01 19:03:34 -05:00
Kevin O'Connor d57bc79513 atsamd: Use the full micro-controller name for CONFIG_MCU
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-01 19:03:34 -05:00
Kevin O'Connor d33c4820bd atsamd: Use local linker script
Use a local linker script instead of the linker script provided by
Atmel.  This will allow Klipper to use dynamic memory allocation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-01 19:03:34 -05:00
Kevin O'Connor c8d7e28a35 atsamd: Add support for programming SERCOM pins
Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-01 00:40:44 -05:00
Kevin O'Connor 7c50bd89cf pru: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor c3eb976119 stm32f1: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor 796b7ac738 avr: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor 2a64dfc242 spicmds: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor f1be6a3969 pwmcmds: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor 69247d87fb stepper: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor 03348fab47 buttons: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor 7b3331ff52 atsamd: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor c07371a2f0 simulator: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor 5a74549ef6 atsam: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor dddfb681c7 pins: Add support for pull down resistors
Add initial support for selecting pull down resistors (for
micro-controllers that support it).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 11:13:21 -05:00
Kevin O'Connor 9e8077009e atsamd: Default to using an external 32Khz crystal
Most samd boards have the crystal and it does improve the clock
accuracy, so default to enabling it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-24 00:37:03 -05:00
Kevin O'Connor da68da7a63 atsamd: Add support for reference clock selection to SAMD21
Add support for using the internal clocks (with USB clock recovery
mode if available) on the SAMD21.  Don't use the internal clock if the
external crystal is requested (instead use the PLL synced to the
external 32Khz signal).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-22 09:07:26 -05:00
Kevin O'Connor d452a1de48 atsamd: Update SAMD51 clock configuration
Add support for USB clock recovery mode if an external 32Khz crystal
is not in use.  If using an external crystal, then don't use the
internal 48Mhz DFLL48Mhz clock (just use the PLLs synced to the
external 32Khz signal).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-22 09:02:04 -05:00
Kevin O'Connor 7a32860455 atsamd: Increase ADC frequency on SAMD51
The SAMD51 ADC is only clocked on rising edges (vs both rising and
falling edges on the SAMD21) and it has a greater minimum frequency
than the SAMD21.  So, increase the ADC clock.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-22 08:56:44 -05:00
Kevin O'Connor ebc80ecea4 atsamd: Only support 8KiB bootloader on SAMD21
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-22 08:51:46 -05:00
Kevin O'Connor 37797c8128 atsamd: Add a GET_FUSE() helper macro
Add a helper macro for accessing the non-volatile factory-calibrated
"fuse" values.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-22 08:51:46 -05:00
Kevin O'Connor a285668b46 avr: Only prompt for cpu speed and uart port on LOW_LEVEL_OPTIONS
The cpu is almost always 16Mhz and the serial port is almost always
UART0, so no need to prompt in the normal case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-16 08:23:00 -05:00
Kevin O'Connor a090b31713 atsamd: Fix samd51 get_clock() sync bit check
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-16 08:03:28 -05:00
Kevin O'Connor 52eef84228 atsamd: Fix typo in Makefile
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-16 07:57:30 -05:00
Kevin O'Connor b33ad59e25 atsamd: Do not generate 200M/100M interal clocks
Now that the internal DWT timer is used for software timers, there is
no need to clock the peripherals at a higher clock speed.  Clock all
peripherals at 48Mhz and simplify the clock generation code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-16 07:57:24 -05:00
Kevin O'Connor a00657d2ae atsamd: Don't clear the watchdog if a clear is still in progress
Clearing the watchdog while it is in progress can cause bus stalls on
the SAMD21.  It appears that clearing the watchdog on the SAMD51 can
cause lockups of the watchdog device.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-15 22:13:28 -05:00
Kevin O'Connor 00e0a70a94 atsamd: Move watchdog code to its own files
Move the watchdog code from main.c to watchdog.c and
samd51_watchdog.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-15 22:10:41 -05:00
Kevin O'Connor 0da65bf6b0 atsam: Fix hard pwm cycle divider calculation
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-13 18:18:12 -05:00
Kevin O'Connor 98ed462865 spi_software: Implementation of software spi
Signed-off-by: Matt Janus <FragginRight@variabl.es>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-13 11:52:20 -05:00
Kevin O'Connor 090cd930d9 atsam: Add support for hard pwm via PWM controller
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-13 11:15:24 -05:00
Kevin O'Connor d1d19d03f3 atsamd: Fix typo in header guard
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-13 09:32:06 -05:00
Florian Heilmann af0d292e23 atsamd: Enable ADC support for samd51 devices (#1204)
* adc: Enable ADC support for samd51 devices

Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
2019-02-08 12:02:32 -05:00
Kevin O'Connor 74c216543c atsam: Configure the atsam sram matrix register
The sram matrix configuration is, bizarrely, configured with a slow
default.  It will typically add an extra wait state to every memory
access.  Set the matrix sram controller to improve the performance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-07 13:12:35 -05:00
Kevin O'Connor af8376e203 debugcmds: Add support for reading/writing 32bit values
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-07 11:50:14 -05:00
Kevin O'Connor 9f3517fdc7 stm32f1: Convert code to use armcm_timer
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-06 22:03:09 -05:00
Kevin O'Connor eb8db46ca3 stm32f1: Use internal functions for early USB gpio toggle
Avoid using the "low-level" library timing utilities.  This is in
preparation for using SysTick as part of the timer implementation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-06 22:03:09 -05:00
Kevin O'Connor 1096075d9b lpc176x: Convert code to use armcm_timer
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-06 22:03:09 -05:00
Kevin O'Connor 77db1aa379 atsam: Convert code to use armcm_timer
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-06 22:03:09 -05:00
Kevin O'Connor 26fb421d59 atsamd: Convert SAMD51 to use armcm_timer
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-06 22:03:09 -05:00
Kevin O'Connor 55df8bf55f armcm_timer: Add a generic timer mechanism for ARM CortexM3/M4 chips
The ARM CortexM3 (and later) chips almost always have a 32bit timer in
the "Debug and Watch Trace" (DWT) unit which resides within the cpu
core itself.  This timer is generally faster to access than timers
located on the chip's peripheral bus.  When combined with the standard
ARM SysTick timer it provides a (generally) portable mechanism to
implement Klipper's software timer mechanism.  It's generally also
faster than using the vendor specific timers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-06 22:03:09 -05:00
Kevin O'Connor 8cd83b4c2d atsamd: Initial support for SAMD51
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-28 20:02:16 -05:00
Kevin O'Connor c5fc264a07 atsamd: Add a get_pclock_frequency() helper function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-28 20:02:16 -05:00
Kevin O'Connor 8f763d80b7 atsamd: Select the 8K bootloader by default
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-28 20:02:16 -05:00
Kevin O'Connor 40b5de1680 atsamd: Pass the power management id to enable_pclock()
Pass the power management id instead of the APBCMASK bit to the
enable_pclock() function.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-28 20:02:16 -05:00
Kevin O'Connor ed1334c24b atsamd: Clarify clock generation code
Implement gen_clock() and route_pclock() helpers in an effort to make
the code more readable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-28 20:02:16 -05:00
Kevin O'Connor 932acd3048 usbserial: Allow USB ids to be specified via Kconfig
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 19:04:14 -05:00
Kevin O'Connor 1ad1ed573a simulator: Fix simulator build
Commit b6ccd268 inadvertently broke the simulator build - fix it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 18:23:27 -05:00
Kevin O'Connor ee86463ed2 avr: Only prompt for CLEAR_PRESCALER and SIMULAVR with LOW_LEVEL_OPTIONS
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 18:07:31 -05:00
Kevin O'Connor b6ccd2682c Kconfig: Move SERIAL_BAUD to src/Kconfig and show with LOW_LEVEL_OPTIONS
Move the definition of SERIAL_BAUD to the main src/Kconfig file.  Only
show this as an option if the user selects the ability to configure
low-level options.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 18:02:03 -05:00
Kevin O'Connor 4fec225115 avr: Rename AVR_SERIAL and AVR_USBSERIAL to SERIAL and USBSERIAL
Rename the config options to be more consistent with other
architectures.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 17:52:09 -05:00
Kevin O'Connor eb7842c221 atsam: Add support for the SAM3X8C micro-controller
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-22 09:07:12 -05:00
Kevin O'Connor efd1bf5e04 atsam: Add support for USB on SAM3X
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-19 22:32:28 -05:00
Kevin O'Connor d4790356da atsam: Add MACH_SAM3X, MACH_SAM4, MACH_SAM4E, MACH_SAM4S definitions
Add additional Kconfig definitions to make it easier to select the
correct code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-18 09:56:24 -05:00
Kevin O'Connor d3ec103816 lpc176x: Implement a median filter on ADC readings
The lpc176x ADC is extremely noisy.  Implement a 5 order median filter
on each ADC read to weed out obviously incorrect readings.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-14 13:08:45 -05:00
Kevin O'Connor 078a03dc21 lpc176x: Add mechanism for entering the bootloader from a USB signal
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-13 12:25:58 -05:00
Kevin O'Connor 093512b971 adccmds: Run gpio_adc_setup() before oid_alloc()
Order the adc config code so that a shutdown from gpio_adc_setup()
doesn't result in analog_in_shutdown() running on a 'struct analog_in'
that hasn't yet been configured.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-13 11:03:30 -05:00
Florian Heilmann 6256599a6d src: Rename source folders for atsam and atsamd architectures
Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
2019-01-12 20:14:50 -05:00
Kevin O'Connor 8a6125c81c stepper: Fix bug when using a non-zero CONFIG_STEP_DELAY on AVR
Make sure to explicitly cast to 32bit integers when doing math on
16bit integers that require the extra precision as the AVR uses a
16bit int.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-11 12:04:03 -05:00
Kevin O'Connor 2ea7c97bbd stepper: Support configuring the stepper pulse length from Kconfig
Allow the stepper pulse length to be configured at compile time from
the Kconfig menu system.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-09 13:16:42 -05:00
Kevin O'Connor e26d1a3567 i2ccmds: Pass the i2c address as a 7-bit number (0-127)
The sam3 i2c code and the linux code use a 7-bit i2c address, while
the avr, lpc176x, and samd21 i2c code uses an 8-bit address with the
least significant bit always zero.  A similar issue occurred in the
host code (sx1509.py and replicape.py use 7-bit addresses while
uc1701.py and mcp4451.py use 8-bit addresses).

Consistently use 7-bit addresses in all the code.  This breaks
compatibility between host and mcu software, so make a change to the
config_i2c command to force users to synchronize software updates.
This also breaks common Smoothieboard configs, so update the mcp4451
code to validate the i2c_address.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 20:00:44 -05:00
Kevin O'Connor 8e0eb0d574 sam3: Implement board reset via SAM RSTC hardware
Use the RSTC hardware block to perform a full reset on a "reset"
command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:34:31 -05:00
Kevin O'Connor 02c558652f sam3: Add USB support for the SAM4 "UDP" hardware
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:34:31 -05:00
Kevin O'Connor 75ad16ea1a sam3: Add support for sam4s8c chips
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:34:31 -05:00
Kevin O'Connor bf196c3028 sam3: Add additional SPI and USART buses to spi.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:34:04 -05:00
Kevin O'Connor 212813906a sam3: Merge sam4e_spi.c into spi.c
Determine at runtime if the SPI or USART devices should be used.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:33:26 -05:00
Kevin O'Connor 4683036f98 sam3: Add enable_pclock() helper function
Add a helper function to enable peripheral clocks.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:33:26 -05:00
Kevin O'Connor b4baabe408 sam3: Enable i2c on sam3x8e
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:33:26 -05:00
Kevin O'Connor 94c86d6c6c sam3: Merge sam4e8e support into sam3 code
Most of the peripherals on the sam4e8e are similar to the ones on the
sam3x8e mcu.  Merge the code together and use just one code directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:33:26 -05:00
Kevin O'Connor e278552d44 lib: Rename lib/cmsis-sam4e/ to lib/sam4e/
This is in preparation for merging the sam3 and sam4 code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:33:26 -05:00
Kevin O'Connor 70bbdf9334 sam3: Rename src/sam3x8e to src/sam3
This is in preparation for merging sam3 and sam4 code into one
directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:33:26 -05:00
Kevin O'Connor e70b70fb75 sam4e8e: Move the sam4 cache setup to its own sam4_cache.c file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor a978167e39 sam4e8e: Use just a single 'chan' member in 'struct gpio_adc'
Remove the 'pin' and 'afec' variables from 'struct gpio_adc'.  This is
in preparation to merge the sam3x8e and sam4e8e code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor 8e2c1a4ab2 sam4e8e: Move ADC code to new file afec.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor 7707d5a74e sam4e8e: Rename gpio_set_peripheral() to gpio_peripheral()
Use the same definition for gpio_peripheral() that the sam3x8e code
uses.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor f0715de004 sam4e8e: Move gpio_set_peripheral() definition from gpio.h to internal.h
Use internal.h in a similar way to the internal.h in sam3x8e.  Also,
move the twi pin definitions from internal.h to i2c.c (as they are only
used there).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor 9a2160f660 sam3x8e: Move adc support to a new adc.c file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor 5b91c7a68d sam3x8e: Pass the gpio id directly to gpio_peripheral()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor ecba3e9a19 sam3x8e: Add an internal.h header file with local definitions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor c3a2fc981d lib: Remove sam4e sam.h and component-version.h files
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>
2019-01-07 19:30:17 -05:00
Kevin O'Connor 22da8ca39c usb_cdc: Notify both the bulk_in and bulk_out tasks on a configure
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:30:17 -05:00
Kevin O'Connor 6e18af7057 stm32f1: It's only necessary to program the CR1 register during SPI init
Only set the CR1 register during spi_prepare().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 19:22:14 -05:00
Kevin O'Connor 277a8185e1 lpc176x: Pass gpio id to gpio_peripheral()
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>
2019-01-04 11:07:22 -05:00
Kevin O'Connor a40df4b6f7 lpc176x: Move enable_peripheral_clock to main.c
Move and rename function to enable_pclock() - in keeping with other
ARM ports.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-04 11:00:09 -05:00
Kevin O'Connor 8f7fc4e6a9 lpc176x: Move ADC code to new adc.c file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-04 10:42:36 -05:00
Kevin O'Connor 62fc5dc288 samd21: Add support for entering Arduino bootloader via USB
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-12-24 11:43:11 -05:00
Kevin O'Connor b84ecebf8f usb_cdc: Add support for detecting a USB level Arduino bootloader request
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-12-24 11:42:19 -05:00
Kevin O'Connor 2a74ffdb95 samd21: Add support for ADC
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-12-22 10:58:04 -05:00
Yannic Schroeder f100d75c19 stm32f1: Always read SPI receive buffer
Otherwise the first byte read via SPI may be the last byte
of the previous transfer

Signed-off-by: Yannic Schroeder <schroeder@ibr.cs.tu-bs.de>
2018-12-14 12:25:35 -05:00
Kevin O'Connor 6df7356baa samd21: Fix gpio in support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 23:10:23 -05:00
Kevin O'Connor e505ab0df1 samd21: Add support for flashing an application via the bossac tool
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 22:22:42 -05:00
Kevin O'Connor f2179da8ad samd21: Add support for hardware pwm
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 20:00:59 -05:00
Kevin O'Connor 0fd2dd7c11 samd21: Minor simplification to timer init code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:50 -05:00
Kevin O'Connor d6f3f6b664 samd21: Add support for SPI
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:50 -05:00
Kevin O'Connor 58d61c7887 samd21: Add support for basic i2c support (write only)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:50 -05:00
Kevin O'Connor 6d90ebe6f8 samd21: Use GPIO() macro when calling gpio_peripheral()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:50 -05:00
Kevin O'Connor 0af0bc946e samd21: Enable watchdog
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:50 -05:00
Kevin O'Connor afa58de014 samd21: Try to clarify the "generic clock generator" configuration
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:50 -05:00
Kevin O'Connor 3a47d972db i2ccmds: Validate the i2c address
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:50 -05:00
Kevin O'Connor db4f0c24cd spicmds: Check for an incorrect mode in spicmds.c
Check the mode parameter in spicmds.c so that the mcu code does not
need to check it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:48 -05:00
Kevin O'Connor 6b108aa885 stm32f1: Move ADC and SPI code from gpio.c to spi.c and adc.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:42:54 -05:00
Kevin O'Connor 729a2e8306 avr: Add support for sending I2C messages
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-23 23:49:26 -05:00
Kevin O'Connor 043170265b i2ccmds: Minor whitespace changes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-23 21:36:44 -05:00
Kevin O'Connor cbbc6801a0 lpc176x: Enable full speed peripheral clocks on SPI and I2C
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>
2018-11-21 20:44:39 -05:00
Kevin O'Connor 4bbd631086 lpc176x: Add an enable_peripheral_clock() helper function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-21 20:44:18 -05:00
Kevin O'Connor 7bb9ce8436 avr: Minor comment update in hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-20 13:14:53 -05:00
Kevin O'Connor 7c65e76ad0 avr: Rework hardware pwm pin definitions
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>
2018-11-20 12:58:33 -05:00
Kevin O'Connor bf92ffb5bf avr: Split gpio.c into gpio.c, adc.c, hard_pwm.c, and spi.c
Split up gpio.c into multiple files in an effort to make the code a
little more understandable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-20 12:58:33 -05:00
Kevin O'Connor 2cc0313b72 avr: Add initial support for atmega32u4 chips
Signed-off-by: Trevor Jones <trevorjones141@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-20 12:58:33 -05:00
Kevin O'Connor 31687bc009 avr: Minor update to help text in Kconfig
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-19 22:05:26 -05:00
Kevin O'Connor b161a69e98 timer_irq: Increase maximum busy wait time to 2us
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>
2018-11-16 17:16:50 -05:00
Kevin O'Connor f3c4deb1ab lpc176x: Convert i2c code to use standard i2ccmds.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-14 10:23:56 -05:00
Kevin O'Connor 8432f6f40c avr: Add support for atmega328p
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>
2018-10-29 11:55:15 -04:00
Florian.Heilmann 99989a668f Implement I2C support in the SAM4E8E port
Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
2018-10-27 10:34:28 -04:00
Florian.Heilmann 5a919c892a Add generic i2c interface
Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
2018-10-27 10:34:28 -04:00
Kevin O'Connor 1a437c1fd1 sam3x8e: Don't report an error if bossac errors during device restart
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>
2018-10-22 17:41:29 -04:00
Kevin O'Connor 34c3cb5c01 sam4e8e: Enable SAM4 cache at startup
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-22 11:16:18 -04:00
Kevin O'Connor 8fca908445 lpc176x: Divide system clock within timer; not on system bus
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>
2018-10-18 09:37:47 -04:00
Kevin O'Connor 67278a6d8a sam3x8e: Align loops to a 16 byte boundary
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>
2018-10-13 11:52:24 -04:00
Kevin O'Connor fb798e3cba sched: Force sched_try_shutdown to be inlined
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>
2018-10-13 11:47:00 -04:00
Kevin O'Connor 7a265f159a armcm_irq: Fix jump target alignment
The jump target needs to be 4 byte aligned (not 2^4 bytes).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-13 11:47:00 -04:00
Kevin O'Connor 0225d17343 stm32f1: Use __always_inline on timer_read_time
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>
2018-10-11 22:20:02 -04:00
Kevin O'Connor 7cbc44b8d3 stm32f1: Use -O2 optimization and inline timer_read_time()
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>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 102ec4938d stm32f1: Use the main lib/cmsis-core directory for cmsis includes
Use the main cmsis header files with stm32f1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 75fa74313c stm32f1: Add support for building with bootloader support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 215b4c5a1e stm32f1: Move assembler build rules together
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor b8745bc973 stm32f1: Pull the USB D+ line low briefly to signal a device connect
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor bc5e961d73 stm32f1: Initial support for serial over USB
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 1302514ea8 stm32f1: Serial should have a higher irq priority than timers
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>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 978b321f80 avr: Disable usb serial interrupts while processing data
There's no need to keep taking interrupts if the high-level code is
busy processing messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 22:17:39 -04:00
Kevin O'Connor 7c7573f69f avr: No need to reset ep0 interrupts on a shutdown
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>
2018-10-02 21:41:36 -04:00
Kevin O'Connor efd9e7a6df usb_cdc: Try to read new data before processing data blocks
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>
2018-10-02 21:38:58 -04:00
Kevin O'Connor fe98dd3585 usb_cdc: Wake usb_bulk_out_task() on a shutdown
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 21:33:46 -04:00
Kevin O'Connor d348f0da87 avr: Allow the serial port to be selected on the atmega2560/1280
Allow the serial port to be selected on the atmega2560 and atmega1280
chips in Kconfig.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-01 22:30:58 -04:00
Kevin O'Connor 357b2f477c buttons: Clear pressed/last_pressed state on new buttons_query command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-01 12:40:28 -04:00
Kevin O'Connor c68c0c6526 avr: Increase stack size to 256 for all AVR targets
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>
2018-10-01 10:33:18 -04:00
Kevin O'Connor b3a6fbed74 usbstd: Force usb_string_descriptor data field to match unicode string
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>
2018-09-30 23:50:51 -04:00
Kevin O'Connor d05aa81927 avr: Use generic usb_cdc code for usb serial support
Use the generic usb_cdc driver code instead of the "pjrc" usb driver
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:55:21 -04:00
Kevin O'Connor c0311bee33 usb_cdc: Perform basic request validation
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 93e4897044 usb_cdc: Add usb_read_ep0_setup() interface function
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>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 731236cf20 usb_cdc: Add support for usb_send_ep0_progmem()
Add support for explicitly sending to the ep0 pipe from constant
"progmem" memory on the AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 92aea93500 usb_cdc: Fix handling of zero-length-packets
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>
2018-09-30 22:32:19 -04:00
Kevin O'Connor be1effebc3 usb_cdc: Rework transfer state tracking code
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>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 6ab16d2407 usb_cdc: Rename interface functions to avoid the term "setup"
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>
2018-09-30 14:09:55 -04:00
Kevin O'Connor ca7a80a946 tmc2208: Initial support for configuring TMC2208 drivers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:51:27 -04:00
Kevin O'Connor e5d95fdd00 stm32f1: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor 983c84b12f pru: Add wrappers for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor 75de9cb4c0 simulator: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor fa3d2b97bd samd21: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor eec58b99fe sam4e8e: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:44:59 -04:00
Kevin O'Connor 109eff0191 sam3x8e: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 5a993b743e lpc176x: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 1ae67441c3 avr: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 34fe4cce14 sched: Don't require 2ms pad in sched_add_timer()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 0bce44e1bb avr: Disable HAVE_GPIO_BITBANGING on atmega168
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>
2018-08-27 11:20:29 -04:00
Kevin O'Connor a20d9d3bd5 samd21: Enable HAVE_GPIO_BITBANGING
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 11:11:28 -04:00
Kevin O'Connor 82a542faed Kconfig: Rename HAVE_USER_INTERFACE to HAVE_GPIO_BITBANGING
Rename the HAVE_USER_INTERFACE definition in preparation for other
"bit banging" interfaces.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 11:09:47 -04:00
Kevin O'Connor 051e8724a0 sam4e8e: Use local copy of bossac for flashing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 08:54:43 -04:00
Kevin O'Connor 22f0db06a1 sam3x8e: Use local copy of bossac for flashing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 08:54:43 -04:00
Florian Heilmann b065f51454 sam4e8e: Fix bug in sam4e gpio.c (#563)
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>
2018-08-24 13:17:53 -04:00
Kevin O'Connor 5fb1c76c0e samd21: Fix description of bootloader offset
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-08 19:56:43 -04:00
Florian Heilmann 64e6d85898 sam4e8e: Add the SAM4e8e port
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>
2018-08-08 10:44:49 -04:00
Kevin O'Connor f067d0cc78 samd21: Minor fixes to usbserial
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-08 10:43:57 -04:00
Kevin O'Connor 0daf19c003 samd21: Add support for USB
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-07 00:03:41 -04:00
Kevin O'Connor cf2393efc8 samd21: Add support for gpio pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-07 00:03:21 -04:00
Kevin O'Connor 74cf4dc9e0 samd21: Initial support for SAMD21 micro-controllers
Add initial support for the Atmel SAMD21 micro-controllers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-07 00:03:18 -04:00
Kevin O'Connor 50142cc1b3 armcm_irq: Enhance clear_active_irq() so it works on cortex-m0
Minor rework of the assembler so that it does not require thumb-2
instructions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-06 23:36:05 -04:00
Kevin O'Connor 635a199a47 usb_cdc: Allow USB endpoint ids to be board specific
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>
2018-08-06 23:36:05 -04:00
Kevin O'Connor f4910e119a lpc176x: Use common cmsis-core files
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>
2018-08-06 23:36:05 -04:00
Kevin O'Connor e1146c04fd sam3x8e: Use SAM3X CMSIS files instead of arduino CMSIS files
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>
2018-08-06 23:36:05 -04:00
Kevin O'Connor 7a9553b38a thermocouple: Minor fixes
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>
2018-07-25 09:06:50 -04:00
Ricardo Amezquita 756514adef thermocouple: Add support for MAX6675 chip
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>
2018-07-24 11:16:05 -04:00
Kevin O'Connor eba252d3fd thermocouple: Add initial support for common SPI temperature sensing chips
Signed-off-by: Petri Honkala <cruwaller@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-24 11:16:05 -04:00
Ricardo Amezquita 940db6bd70 linux: Add support for bi-directional SPI communication
Signed-off-by: Ricardo Amézquita <ramezquitao@cihologramas.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-24 11:16:05 -04:00
Kevin O'Connor e2b4b1616f lpc176x: Add support for SPI
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-18 10:11:29 -04:00
Pascal Albert 244d0aa65b atmega1284p: Add choice between UART0 or UART1 to Kconfig
Signed-off-by: Pascal Albert <lucky@foxserver.org>
2018-07-13 19:58:04 -04:00
Kevin O'Connor 32a85edb16 spidev: Minor rework to spidev_transfer()
Gcc does a better job of inlining code if spidev_transfer() is
reworked slightly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 19:43:20 -04:00
Kevin O'Connor 733506dfb2 sam3x8e: Configure spi transfer in spi_prepare()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 19:40:51 -04:00
Kevin O'Connor d9f960fb0c avr: Configure spi transfer in spi_prepare()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 19:40:21 -04:00
Kevin O'Connor 5294b3cd2d simulator: Rework dummy simulator code to user timer_irq / serial_irq
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>
2018-07-11 14:35:24 -04:00
Grigori Goronzy 2991c7a831 stm32f1: implement spi_prepare
Implement spi_prepare to fix the undefined behavior on SPI transaction
start.

Tested with the following command sequence:

allocate_oids count=2
config_spi oid=0 bus=0 pin=PA8 mode=3 rate=1000000 shutdown_msg=
config_spi oid=1 bus=0 pin=PA8 mode=1 rate=1000000 shutdown_msg=
spi_send oid=0 data=30313233343536373839
spi_transfer oid=1 data=3031

Discussion about this here:
https://github.com/KevinOConnor/klipper/pull/453#issuecomment-403131149

Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
2018-07-08 09:25:11 -04:00
Grigori Goronzy ebd9035325 SPI: introduce spi_prepare function
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>
2018-07-08 09:25:11 -04:00
Grigori Goronzy 5c7c8c984b stm32f1: add SPI support
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>
2018-07-07 11:05:33 -04:00
Kevin O'Connor 1eb416002b sam3x8e: Read from the SPI_RDR on SPI send even if no data needed
Be sure to read the SPI_RDR as that clears the RDRF flag.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-05 10:29:52 -04:00
Kevin O'Connor 0dbfa915de adccmds: Add support for min/max temperature check filtering
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>
2018-07-02 13:56:34 -04:00
Kevin O'Connor 38d7b9ada0 buttons: Add initial support for detecting button presses
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>
2018-06-30 14:28:51 -04:00
Kevin O'Connor d725160706 mcp4451: Add initial support for programming the mcp4451 on lpc176x
Add support for programming smoothieboard current.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-29 21:20:12 -04:00
Kevin O'Connor efb27f095c build: Cleanup whitespace errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-28 13:00:20 -04:00
Grigori Goronzy 6078145dcd stm32f1: fix ADC pin list
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>
2018-06-27 18:22:06 -04:00
Kevin O'Connor 06ef60011e gpiocmds: Add update_digital_out command
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>
2018-06-27 12:10:39 -04:00
Kevin O'Connor 7aec52dfb3 avr: Don't set SS high on spi_init()
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>
2018-06-27 12:10:25 -04:00
Kevin O'Connor d651851567 pru: Disable ADC reading directly from the PRU
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>
2018-06-27 12:10:25 -04:00
Kevin O'Connor f08a0c5e93 lcd_st7920: Use a longer delay at the start of each command/data
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>
2018-06-22 23:47:09 -04:00
Kevin O'Connor 4fbecfa1fc lpc176x: Build with LCD support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-18 12:46:08 -04:00
Kevin O'Connor b93fd5b1b5 basecmd: Rename get_status to get_clock
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>
2018-05-29 10:57:29 -04:00
Kevin O'Connor 879c45db19 mcu: Do not automatically restart MCU with new config if it is shutdown
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>
2018-05-29 10:57:29 -04:00
Kevin O'Connor d798fae20b serialqueue: Limit message transmission to available receive buffer size
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>
2018-05-28 11:12:30 -04:00
Kevin O'Connor 75f8709947 command: Wait to send ack until after processing commands
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>
2018-05-28 10:43:40 -04:00
Kevin O'Connor 528f9f7604 command: Add command_find_and_dispatch() helper
Add a helper function that calls command_find_block() followed by
command_dispatch().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor c8af3feee6 command: Add a command_encode_and_frame() helper
Add a helper function that calls command_encodef() followed by
command_add_frame().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor cb4e165071 command: Prefer uint8_t* for buffers; prefer uint8_fast_t for lengths
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>
2018-05-28 10:43:39 -04:00
Kevin O'Connor 2994638380 lpc176x: Add a dummy "make flash" command to advise users on how to flash
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:58:23 -04:00
Kevin O'Connor 4344f7fc10 lpc176x: Add build rules for smoothieware bootloader support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c381d03aad lpc176x: Initial support for serial over usb
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c812a40a37 lpc176x: Add ADC support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor 65613aeddf lpc176x: Enable watchdog
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c78b90767f lpc176x: Add support for GPIO pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor 970831ee0d lpc176x: Add initial support for LPC176x processors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c2d48aba87 byteorder: Add a header file defining common byteswap functions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-21 09:44:40 -04:00
Kevin O'Connor 70068985a7 stepper: Introduce and use gpio_out_toggle_noirq()
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>
2018-05-15 17:09:11 -04:00
Kevin O'Connor f70fefa06f linux: Convert linux SPI code to use the generic spicmds.c code
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>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 31ae74c56c sam3x8e: Add SPI support
Signed-off-by: Petri Honkala <cruwaller@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 22487d95e9 spicmds: Rework SPI message transmission
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>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 9c52ad4310 stm32f1: Enable lcd chip support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 01:03:25 -04:00
Kevin O'Connor 018c5daa94 sam3x8e: Enable lcd chip support
Testing shows the hd44780 and st7920 chips do work on the Due.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 01:03:01 -04:00
Kevin O'Connor 4a8f9407b8 avr: Do not use Idle mode
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>
2018-04-28 21:26:42 -04:00
Kevin O'Connor 46cf3ef145 avr: Explicitly set ADCSRA on each conversion start
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>
2018-04-25 19:13:44 -04:00
Kevin O'Connor cf475a9a39 avr: Clean up serial port register aliases
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>
2018-04-25 10:55:18 -04:00
Kevin O'Connor 6793970198 serial_irq: Add new generic/serial_irq.c code
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>
2018-04-20 11:19:37 -04:00
Kevin O'Connor add370230f stm32f1: Use generic timer_irq.c dispatch code
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>
2018-04-20 11:19:37 -04:00
Kevin O'Connor 2bf9e27b9e stm32f1: Use different method for handling 16bit -> 32bit timer conversion
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>
2018-04-20 11:19:37 -04:00
Kevin O'Connor 06a4753f73 stm32f1: Prefer uint32_t over uint16_t in timer.c
The ARM architecture handles 32bit values faster than 16bit values -
use uint32_t where possible.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-20 11:19:37 -04:00
Grigori Goronzy 75d5737211 Add STM32F103 port
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>
2018-04-09 18:08:29 -04:00
Kevin O'Connor afc9bcf27b lcd_hd44780: Add micro-controller code for the HD44780 LCD chip
Add support for passing messages to an HD44780 chip via a 4-bit
bit-banging interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:34 -05:00
Kevin O'Connor 9140f36d99 lcd_st7920: Add micro-controller code for the ST7920 LCD chip
Add support for passing messages to an ST7920 chip via a SPI
bit-banging interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:30 -05:00
Douglas Hammond d139389267 avr: Add at90usb646 support
Signed-off-by: Douglas Hammond wizhippo@gmail.com
2018-02-25 10:23:00 -05:00
Kevin O'Connor b7b216af7f avr: Round hardware pwm clock ticks to nearest divisor
Instead of rounding down to the nearest supported pwm divisor, round
to the nearest divisor.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-29 11:54:15 -05:00
Kevin O'Connor d891baa860 avr: Clear the TCNT1 register on timer startup
Just to be safe, clear the TCNT1 register during init.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-07 22:22:08 -05:00
Kevin O'Connor f6cd51bfb7 avr: Clear the ADCSRA/ADCSRB registers on ADC init
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>
2018-01-07 22:13:39 -05:00
Kevin O'Connor 5a86391f78 avr: Only use the avrdude "wiring" protocol on atmega2560 devices
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>
2018-01-05 10:02:15 -05:00
Kevin O'Connor d303e556ad sched: Interrupts must be disabled during setjmp() call
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>
2017-12-21 12:54:33 -05:00
Kevin O'Connor 57c27f75ae gpiocmds: Clear SPF_NEXT_* flags on new schedule_soft_pwm_out
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>
2017-12-16 20:21:38 -05:00
Kevin O'Connor 319221ee23 docs: Provide additional information on "make flash" failures
Add some additional information on "make flash" problems.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-11 17:33:29 -05:00
Kevin O'Connor 03e97c2d95 linux: Remove unneeded includes from timer.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-23 22:20:53 -04:00
Kevin O'Connor 75ba375b8a pru: Don't reset the ADC reset complete flag if a shutdown occurs
Only set the have_done_reset flag if the reset completes successfully.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-18 13:05:36 -04:00
Kevin O'Connor cbd06f1433 linux: Fix typo causing config_reset to not fully restart
A typo in the code caused the wrong config_reset code to be run.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-15 21:05:08 -04:00
Kevin O'Connor 1c59a0d30a linux: Open watchdog device after console
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>
2017-10-15 21:05:08 -04:00
Kevin O'Connor d222ec1024 linux: Make sure to close fd on analog/pca9685 init failure
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-14 00:22:21 -04:00
Kevin O'Connor 674f584190 pca9685: Fix missing devices_count increment
The devices_count was not being incremented on each device add.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-13 22:05:19 -04:00
Kevin O'Connor 3c4d14bfa9 pca9685: Support default values
Allow the pwm pin to have a non-zero default value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor db97f36631 gpiocmds: Allow the start value for a pin to differ from the default_value
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>
2017-10-12 11:59:27 -04:00
Kevin O'Connor d03cf2b83f adccmds: Continue to query analog inputs after a shutdown
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>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 744c6d114e sched: Don't shutdown on a "timer in the past" if already shutdown
A shutdown will not help if the mcu is already in a shutdown state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 3b9b4e4d6f endstop: Eliminate end_stop_set_oversample command
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>
2017-10-12 11:59:27 -04:00
Kevin O'Connor fb0f344346 avr: Add support for atmega1284p
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-05 13:51:05 -04:00
Kevin O'Connor eaeb831107 endstop: Fix typo in comment
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-02 11:00:23 -04:00
Kevin O'Connor ece1f71c64 endstop: Support oversampling of the endstop
Some printers can show occasional noise on the endstop pin.  Support
sampling the endstop pin multiple times to attempt to filter out this
noise.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-01 19:15:55 -04:00
Kevin O'Connor 5a85c1667a pru: Update installation and flash scripts
Update the scripts used to install and "flash" the pru
micro-controller code.  Also, add a "flash" script for the linux
micro-controller code.  This makes it easier to install Klipper on a
Beaglebone board that uses a Replicape.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 16d2ec3a90 linux: Add support for analog IIO devices
Add support for reading analog values via the standard Linux IIO
interface.  This can be used on Replicape boards to sample analog
input pins.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 4d60567bc6 linux: Add support for spidev devices
Add support for sending SPI messages to devices via the standard Linux
SPI interface.  This can be used to configure the shift registers on
Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 73a1c9d249 linux: Add support for pca9685 i2c pwm devices
Add support for controlling pca9685 PWM drivers using the standard
Linux I2C interface.  The pca9685 device is found on Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor d851882278 linux: Initial support for running Klipper in a Linux real-time process
Add support for compiling the Klipper micro-controller code as a
real-time process capable of running on standard Linux systems.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 2a6a9eb52f pru: Avoid calling "slp" instruction on pru0
If pru0 waits in sleep mode then a full beaglebone reboot is needed to
reprogram the pru0 firmware.  For now, avoid using the "slp"
instruction as a workaround.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-11 13:12:18 -04:00
Kevin O'Connor d618affd63 pru: Batch outgoing writes
Allow pru0 to gather multiple outgoing message blocks into a single
rpmsg.  This can reduce communication overhead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 11:50:21 -04:00
Kevin O'Connor 121c747cc8 pru: Fix race condition in clearing of irq flags
Each irq flag must only be cleared after it has been serviced.  This
fixes a race condition that could cause incoming commands to be
delayed for extended period.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 11:50:21 -04:00
Kevin O'Connor 09e32d1b84 mcu: Provide some further help on common MCU shutdown errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor 68fc6abf74 avr: Check that FLASH_DEVICE is set on "make flash" command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor 7083a33ecd pru: Support config_reset command to manually reset mcu
Add support for resetting the MCU via a software only mechanism.  This
is useful on the PRU.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 23:16:38 -04:00
Kevin O'Connor 7b7f57e01c pru: Only sleep the pru0 if the incoming queue is fully empty
It's possible for multiple blocks to be pending on the incoming
"rpmsg" stream.  Don't sleep unless the input is confirmed to be
empty.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 23:15:49 -04:00
Kevin O'Connor 0adea120cd pru: Compile the irq_poll() function with -O2 optimization
Compile the PRU binary with -Os optimization, but request that the
timer dispatch code be compiled with -O2 optimization.  This improves
the performance of timers slightly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-15 11:05:30 -04:00
Kevin O'Connor 71bb7acb8e pru: Compile with -Os instead of -O2
The gcc -Os option significantly reduces the size of the PRU binary
and it has little impact on performance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 21:08:28 -04:00
Kevin O'Connor f8bd8b97be command: Don't pass max_size to command_encodef()
The command_encodef() can read the max_size parameter directly from
the 'struct command_encoder' passed into it.  Also, there is no need
to check that a message will fit in a buffer if the buffer is declared
to be MESSAGE_MAX in size.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 18:32:15 -04:00
Kevin O'Connor f3da473285 docs: Update Code_Overview.md with PRU and command_dispatch() changes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 12:06:19 -04:00
Kevin O'Connor d8225642fa stepper: Revert f8b0c884
Go back to scheduling the unstep time instead of busy waiting in the
timer dispatch.  With the unstep time increased to 2us, it no longer
makes sense to spin while waiting for the unstep.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 10:36:02 -04:00
Kevin O'Connor 8ebba6d27a avr: Make sure timer_high and timer_event() stay in sync
Schedule the next wakeup time of timer_event() using timer_high.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 09:32:06 -04:00
Kevin O'Connor 1051a52755 timer_irq: Rework timer irq handler to check for tasks pending
Allow timer_dispatch_many() to run for extended periods if there are
no tasks pending.  This reduces the amount of lost cpu time spent
entering and exiting the irq handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-09 21:08:40 -04:00
Kevin O'Connor a38082016d sched: Reduce the amount of time irqs are disabled in sleep check
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-09 12:55:44 -04:00
Kevin O'Connor 156e9b7556 sched: Write out a message on startup
Send a "startup" message after completing the mcu init functions.
This may help detect mcu reboots during debugging.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor f886212b44 avr: Rework timer irq handler to check for tasks pending
Allow the timer dispatch irq handler to run for extended periods if
there are no tasks pending.  This reduces the amount of lost cpu time
spent entering and exiting the irq handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor 2c272f99a3 sched: Implement generic sleep mechanism based on tasks pending
Track when tasks are pending and spin in irq_wait() when no tasks are
pending.  This improves the mechanism for sleeping the processor -
it's simpler for the board specific code and it reduces the
possibility of the processor sleeping when tasks are busy.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor a9982beacf sched: Introduce sched_wake_tasks() function to wake up tasks
Add function to indicate when tasks need to be run.  This will allow
the scheduler code to know if there are any tasks that need to be
processed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor e9d2ec7c41 avr: Tune the low-level timer entry and exit heuristics
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor 78982ebb51 avr: Implement internal avr specific timer to handle 16bit overflows
Don't rely on the generic scheduler code to always have a timer no
more than 1ms in the future.  Instead, create an avr specific timer
that will be called every 0x8000 ticks.  This simplifies the generic
code and it reduces the amount of code that needs to be run every
millisecond.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00