75 Commits

Author SHA1 Message Date
Kevin O'Connor
14cbb8dd2d rp2040: Prefer larger postdiv1 on rp2040 chips
The rp2040 uses a pll vco divider of 6.  Prefer setting postdiv1=6 and
postdiv2=1 (instead of the previous postdiv1=3 and postdiv2=2).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-06-02 14:10:42 -04:00
Kevin O'Connor
105ce35e1b stm32: Add comments on PLL frequency requirements to clock setup code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-06-02 13:15:53 -04:00
Kevin O'Connor
8e58f8fb39 rp2040: Fix spi overflow issue
Completely filling the spi transmit fifo could lead to a situation
where the rx fifo overflows.  Make sure not to write past the rx fifo
size.

Also, be sure to wait for the transmission to fully complete before
exiting spi_transfer().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-05-30 16:34:49 -04:00
Timofey Titovets
f4130aa948 rp2040: spi - enable fifo
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-05-30 15:18:07 -04:00
Timofey Titovets
14685bf77f rp2040: add a delay on SCK polarity change
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-05-26 18:44:29 -04:00
Kevin O'Connor
871637d3f2 Kconfig: Note which chips require software divide operations
Add a new HAVE_SOFTWARE_DIVIDE_REQUIRED that indicates which chips
require software divide.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-04-17 12:09:19 -04:00
Kevin O'Connor
04e7eb20fd Kconfig: Add new WANT_I2C option to reduce code size
Make it possible to not compile in support for I2C on chips with small
flash sizes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-04-16 13:54:44 -04:00
Kevin O'Connor
868760f5b1 Kconfig: Add new WANT_SPI option to reduce code size
Make it possible to not compile in support for SPI on chips with small
flash sizes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-04-16 13:54:44 -04:00
Kevin O'Connor
b0fa36e221 Kconfig: Add new WANT_HARD_PWM option to reduce code size
Make it possible to not compile in support for hardware pwm on chips
with small flash sizes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-04-16 13:54:44 -04:00
Timofey Titovets
68dbbc8d41 rp2040: define spi bus on pins 12,11,10
Mellow FLY SHT36 Pro toolboard uses those pins

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-03-25 18:53:46 -04:00
Kevin O'Connor
8faed8d9fe stepper: Support step on both edges with custom minimum pulse duration
Add support for "step on both edges" to the main stepper_event_full()
code.  This makes that mode of operation available even when the
micro-controller is not compiled for "optimized step on both edges".
It also enables the custom pulse duration support (step_pulse_ticks)
when in "step on both edges" mode.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-03-20 19:56:55 -04:00
Kevin O'Connor
14c105b86e rp2040: Fix build of rp2350
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-02-26 20:24:22 -05:00
Timofey Titovets
2f6d240900 rp2040: set clock to 200Mhz
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-02-26 20:11:17 -05:00
Kevin O'Connor
9fd415d3f5 rp2040: Add support for reporting canbus state
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-02-02 18:43:34 -05:00
Jessica Hunt
a18c74be05
rp2040: Add spi0_gpio4_gpio3_gpio2 bus to support fysetc PITB V2 (#6683)
The Fysetc PITB V2 board uses a spi bus config that is supported by the
RP2040 chip, but not klipper, so this adds the relevant config to the file
to allow you to run the tmc5160's on the board via hardware SPI.  This
resolves the issue of software spi not working on this board, which I
was unable to fully understand.

I have also seen other users encounter similar bus config issues with
the rp2040 setting up things like accelerometers and such with this
pin layout.

As requested, this also uses the new convention for spi bus naming, while
maintaining the old bus names for compatibility.

Signed-off-by: Jessica Hunt <hunt.jessica@proton.me>
2024-11-27 22:32:42 -05:00
Kevin O'Connor
9bd0d47576 rp2040: Improve indentation in Kconfig file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-14 13:01:21 -05:00
Kevin O'Connor
f6718291b7 rp2040: Add rp2350 bootrom based chipid and reboot to bootloader code
This adds the bootrom code needed to implement "reboot into
bootloader" and "chipid" capabilities.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-14 11:24:47 -05:00
Kevin O'Connor
8a203cf2cb rp2040: Move chipid reading to bootrom.c
Rewrite chipid.c so that it contains just the USB and canbus id
manipulation code.  Move the low-level chipid reading to bootrom.c.

Also, introduce a new bootrom_reboot_usb_bootloader() function in
bootrom.c so that the main.c code does not need to know the specifics
of rebooting into the bootrom.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-14 11:24:47 -05:00
Kevin O'Connor
06bb49f135 rp2040: Initial rp2350 support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-14 11:17:52 -05:00
Kevin O'Connor
61f81bdb26 rp2040: Use a higher USB PLL internal frequency
The rp2350 chip requires a higher internal frequency, so choose a
value that works for both rp2040 and rp2350.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-14 11:17:52 -05:00
Kevin O'Connor
c28ed06e98 rp2040: Avoid using memcpy() on USB dpram
Some versions of the system memcpy() may make unaligned memory
accesses, which can result in a bus fault when accessing the usb dpram
device memory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-14 11:17:52 -05:00
Kevin O'Connor
405935f918 rp2040: Rename rp2040_link.lds.S to rpxxxx_link.lds.S
This is in preparation for rp2350 support.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-13 14:25:59 -05:00
Kevin O'Connor
906431bb00 rp2040: Rename CONFIG_RP2040_yyy Kconfig symbols to CONFIG_RPXXXX_yyy
Rename the Kconfig symbols.  This is in preparation to adding support
for the rp2350 mcu.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-13 14:25:59 -05:00
Kevin O'Connor
c75eb53c0c lib: Update lib/rp2040 to v2.0.0 SDK release
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-13 14:25:59 -05:00
Kevin O'Connor
9f328cab95 lib: Move lib/rp2040/elf2uf2 to lib/elf2uf2
Recent versions of the rp2040 sdk no longer contain the elf2uf2 tool.
So, move that code to a new dedicated directory.  This is in
preparation for updating the rp2040 sdk version.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-11-13 14:25:59 -05:00
Timofey Titovets
335a0e20c2 rp2040: forward i2c errors to i2ccmd
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2024-10-26 22:06:30 -04:00
Timofey Titovets
a4aa2a9002 i2c: handle errors at i2ccmds
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2024-10-26 22:06:30 -04:00
Timofey Titovets
9426485bb6
rp2040: Check for i2c NACK/Start NACK (#6692)
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2024-09-22 19:28:07 -04:00
Kevin O'Connor
863a463cb2 rp2040_link: Explicitly set klipper.elf output section flags to avoid warning
Avoid pointless "LOAD segment with RWX permissions" linker warnings
during the rp2040 build.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-06-17 12:45:07 -04:00
Kevin O'Connor
ae227d485c armcm_link: Fix build on recent arm gcc/newlibc versions
It seems recent arm gcc versions no longer build correctly using the
"--specs=nano.specs --specs=nosys.specs" linker flags.  Replace those
linker flags with "-nostdlib -lgcc -lc_nano".

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-06-17 12:45:07 -04:00
Amken USA
0b329c5d28
rp2040: Add kconfig options for rp2040 uart (#6549)
Modified serial.c and Kconfig to dynamically select all possible UART combinations for RP2040

Signed-off-by: Hriday Keni <info@amken.us>
2024-04-24 22:32:29 -04:00
Kevin O'Connor
5e433fff06 rp2040: Only change SPI settings while peripheral is disabled
Make sure to disable/enable the peripheral to ensure the clock
polarity is properly set prior to a change in CS.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-25 12:06:02 -05:00
Kevin O'Connor
f1982edcd5 rp2040: Load vectortable into ram
Load the interrupt vector table into ram at startup.  This reduces the
chance of a flash cache access causing timing instability.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-25 11:05:11 -05:00
Kevin O'Connor
44e79e0c37 rp2040: Run all code from ram
Place all normal code into ram.  This reduces the chance that rp2040
instruction cache misses could cause subtle timing issues.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-25 11:03:45 -05:00
Kevin O'Connor
23c5b20f5b rp2040: Always link using rp2040_link.lds.S
Use the rp2040 specific linker script even when using a bootloader.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-25 11:03:40 -05:00
Kevin O'Connor
472fd32cab rp2040: Add support for double buffering on USB bulk tx packets
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-10-03 23:28:13 -04:00
Kevin O'Connor
90427fe30e rp2040: Add support for double buffering on USB bulk rx packets
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-10-03 23:28:13 -04:00
Kevin O'Connor
bdeec0f56d rp2040: Open code usb_read_packet() and usb_write_packet() in callers
Copy the code for these two functions to their respective callers.
This is in preparation for double buffer support.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-10-03 23:28:13 -04:00
Kevin O'Connor
83eecae028 rp2040: Add helper functions to usbserial.c
Add helper functions for manipulating the buffer memory and packet
control registers.  This is in preparation for double buffer support.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-10-03 23:28:13 -04:00
Kevin O'Connor
15d302901f Kconfig: Support selecting optional features on chips with small flash size
Add a new HAVE_LIMITED_CODE_SIZE symbol that enables a menu to select
optional features.  This symbol is enabled on chips with small build
sizes.

Replace the HAVE_GPIO_BITBANGING with four new symbols:
WANT_GPIO_BITBANGING, WANT_DISPLAYS, WANT_SENSORS, WANT_SOFTWARE_SPI,
and WANT_SOFTWARE_I2C.  This allows users a little more flexibility
when selecting features they need.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-06-08 12:59:30 -04:00
Kevin O'Connor
bec1d957d2 rp2040: Handle USB resets
On a USB bus reset the controller address needs to be reset to zero.
Otherwise, the device becomes unresponsive after a USB reset and will
remain unresponsive until a power cycle.  This often shows up in the
Linux system logs as "device descriptor read/64, error -32" messages.

Make sure USB_INTE_BUS_RESET_BITS is enabled and clear the USB address
on a bus reset.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-04-25 00:05:04 -04:00
Kevin O'Connor
34fd3f41ea usb_cdc: Only call bootloader_request() if CONFIG_HAVE_BOOTLOADER_REQUEST
Check for the build symbol prior to calling bootloader_request().
Enable the build symbol on rp2040, atsam, and atsamd chips.

This also enables serial bootloader requsts on rp2040, atsam, and
atsamd.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-12-30 21:28:32 -05:00
Chris Lee
aac613bf44 scripts: support CanBoot on RP2040 in flash_usb.py
Signed-off-by: Chris Lee <clee@mg8.org>
2022-12-19 15:42:53 -05:00
Kevin O'Connor
fe0fc29616 rp2040: Move watchdog code to new watchdog.c file
Move the watchdog code to its own file so that it is easier to disable
it for development builds.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-12-14 19:21:25 -05:00
Kevin O'Connor
9b342c65c8 armcm_link: Rename CONFIG_FLASH_START to CONFIG_FLASH_APPLICATION_ADDRESS
Rename the build symbol name for better clarity on what it represents.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-12-14 18:44:07 -05:00
Kevin O'Connor
52a6bed24e canbus: Rename canbus_send() to canhw_send()
Rename canbus_send() to canhw_send() and rename canbus_set_filter() to
canhw_set_filter().  This makes it more clear where the code should
reside.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-12-14 14:15:14 -05:00
Kevin O'Connor
e16a693b1e rp2040: Fix copy-paste error in Kconfig comment
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-12-14 13:34:15 -05:00
Kevin O'Connor
8977c4e764 rp2040: Fix watchdog enable
The rp2040 watchdog does not actually reset anything by default.  The
psm_hw->wdsel field must be programmed to actually get a reset on a
watchdog failure.  Program that field so the watchdog is usable.

Also, disable the watchdog before attempting a reboot into the
bootloader.  Otherwise the machine may just reboot a second time due
to a missed watchdog event in the bootloader.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-11-19 10:13:50 -05:00
Kevin O'Connor
b9a378c1ca rp2040: Fix boundary check for max gpio pin
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-11-19 10:13:50 -05:00
Kevin O'Connor
6485ff800b rp2040: Support CanBoot as bootloader
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-11-08 09:53:04 -05:00