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>
It appears the usbotg controller can get confused if the usb irq
handler runs while processing a usb request. Disable usb irqs during
usb processing to avoid this.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use the XFRC interrupt instead of TXFE. Don't mask/unmask the tx
interrupts during runtime. This fixes some race conditions where a tx
notification may have previously gotten lost.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The ADC pins (on at least the sam3x8e) need to be configured in input
mode with the internal pullups disabled in order to get accurate ADC
readings.
Reported by @bryanboettcher.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rename the linker script so the build does not have any conflicts with
the armcm_boot.d dependency file.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Replace the custom encoding with a hex encoding. This makes it a
little easier to inspect the CTR conversions.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Store the CTR requests in compile_time_request.txt with the null
characters removed. This makes it slightly easier to inspect the CTR
conversions.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add basic ARM Cortex-M C init code and build linker scripts to
src/generic/ code. This can be used to simplify the various ARM board
code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a general build rule to precompile *.lds.S files to *.ld files.
Remove the custom rules in src/atsamd/Makefile and src/stm32/Makefile.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
On fast MCUs (like the SAMD51) it is possible for the gpio to toggle
faster than the st7920 can accept. Add a small delay around the clock
rise signal.
Signed-off-by: Lars R. Hansen <popshansen@hotmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rework the spi_config commands so that bus configuration and shutdown
message configuration is done separately from the main "config_spi"
command. This makes the spi configuration more flexible. It's now
possible to use software spi without a CS pin. It's now possible to
define multiple SPI messages to send on a shutdown event.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Now that the stm32f1 code has been merged into the stm32 code, there
is no longer a need to keep the stm32f1/ directory.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rename the clock.c file to stm32f4.c to make it more clear that the
code is specific to the stm32f4 chips.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Now that the code in stm32f4/ can handle both stm32f1 and stm32f4
chips, rename the directory to just "stm32".
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update the stm32f1 code to the latest from ST. Merge the
lib/cmsis-stm32f1/ and lib/hal-stm32f1/ into a single lib/stm32f1/
directory. Document all the differences from the pristine upstream
code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rename the commands.
The main reason for this change is to force a micro-controller code
updated (due to important bugfix in 7fefe52d).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If the move is not added to the move queue, then the SF_LAST_DIR
setting must not be changed. Otherwise, it could result in an
incorrect direction being set on the stepper after a homing operation.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The popular "LPC17xx-DFU-Bootloader" alters the LPC_UART0->FDR
register, so be sure to reset it back to its default when using serial
in Klipper.
Reported by @b-vs.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 1096075d changed CONFIG_CLOCK_FREQ to the actual cpu frequency,
but that commit failed to update adc.c accordingly. That made the adc
run 4 times slower. Make the corresponding change to adc.c.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Improve the precision of soft pwm pulses by allowing the host to
directly specify the clock duration of the pulse. This improvement in
precision may be noticeable when controller servos (and bltouch).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The replicape servo pins (P9_14/P9_16) are muxed to the SOCs hardware
PWM unit driven by a 13MHz GP timer. They have to be driven by the
linux host mcu. This commits adds hardware PWM support using the linux
sysfs user space interface.
Signed-off-by: Janne Grunau <janne-3d@jannau.net>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The sampling time of the ADC was too slow (239 ADC clock cycles), causing the reading of the next ADC channel to have cross talk as per issue #1261. Sampling time updated to 41 ADC clock cycles.
Signed-off-by: Marco D'Alessio <marco@wrecklab.com>
It appears the PRU timer will not trigger on a match of exactly zero.
If the next timer happened to be set to exactly zero, it could cause
software timers to get stuck and result in "move queue empty" errors.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It appears some host machines may not recognize that the USB device
has disconnected upon start of bootloader mode. Explicitly disable
USB and add a 5ms delay to help signal the host of the upcoming
change.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>