I want to flash Duet3HC with Klipper. The problem is that there is no USB port on this board.
I tried to download the firmware via CAN port, but as far as I understand it can’t be done without USB port (even with USB-CAN adapter). Please advise me if I am wrong.
The second option is to use SWD pins for flashing. I tried using OpenOCD by connecting Raspberry Pi 4 via SWD (GPIO25 - SWDCLK, GPIO24 - SWDIO, GPIO18 - nRST). As I understand it, the boot is successful, however, when subsequently connecting to CANbus I do not see this board via ~/klippy-env/bin/python ~/klipper/scripts/canbus_query.py can0. Also, the DIAG LED that shows CAN synchronization between boards (when working with RRF) is not lit. My openocd.cfg:
pi@klid3:~/bootloader $ sudo openocd
[sudo] password for pi:
Open On-Chip Debugger 0.12.0+dev-00731-g1173473f6 (2024-10-04-14:18)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Warn : TMS/SWDIO moved to GPIO 8 (pin 24). Check the wiring please!
Warn : Interface already configured, ignoring
Warn : Interface already configured, ignoring
DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
DEPRECATED! use 'adapter srst pulse_width' not 'adapter_nsrst_assert_width'
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : clock speed 1985 kHz
Info : SWD DPIDR 0x2ba01477
Info : [atsame5.cpu] Cortex-M4 r0p1 processor detected
Info : [atsame5.cpu] target has 6 breakpoints, 4 watchpoints
Info : [atsame5.cpu] Examination succeed
Info : [atsame5.cpu] starting gdb server on 3333
Info : Listening on port 3333 for gdb connections
[atsame5.cpu] halted due to breakpoint, current mode: Thread
xPSR: 0x01000000 pc: 0x00010100 msp: 0x464c457c
[atsame5.cpu] halted due to breakpoint, current mode: Thread
xPSR: 0x01000000 pc: 0x00010100 msp: 0x464c457c
** Programming Started **
Info : SAM MCU: SAME51N19A (512KB Flash, 192KB RAM)
** Programming Finished **
** Verify Started **
** Verified OK **
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Configuring klipper:
Processor model (SAME51J19)
Bootloader offset (16KiB bootloader(Arduino M0, Duet3 Bootloader))
Clock Reference (25MHz (standard))
Communication interface (CAN bus (on PB13/PB12))
Not an expert on these chips, but typically there is rarely a thing like “family compatibility”. E.g. on the STM side of life, a STM32H723xxx and STM32H743xxx needs different settings.
Again without being the authority, but this is exactly what needs to be reflected in the settings that are behind the make menuconfig choices.
There might not be much missing, but I cannot offer this guidance.
I don’t have much familiarity with the Atmel ARM platforms, so I couldn’t tell you anything specific about the N variant’s requirements or setup in Klipper and whether or not selecting the J variant will work.
Just glancing at your openocd configuration it doesn’t look like you specified a programming address. So it would start at memory address 0, overwriting the duet bootloader. You could try configuring the klipper build with no bootloader and reprogramming.
FWIW, any “sync” or “diag” leds that are toggled in Duet’s firmware when CANbus sync was achieved will not do the same for Klipper.
Then I chose “SAME51N19” in make menuconfig and flash Klipper.elf. I tried “no bootloader” options too, but this doesn’t help. I found the necessary files for this microcontroller in the lib/same51/include folder, and I think they were imported when I added the SAME51N19 to Kconfig. Do I need to change something else in Klipper files? I used the commit with same51j19 to find more changes needed, but the rest is the same for the SAME51 family as I understand it. (atsamd: Add Kconfig definitions for same51j19 and same54p20 chips · Klipper3d/klipper@bdf79ca · GitHub)
Unfortunately I’m not familiar enough with the atsame implementation to provide strong guidance as far as what is necessary to bring up a new variant. At a cursory glance your change seems ok.
It looks like the diag LED is on pin PC10. You could try adding PC10 to the GPIO Pins to set at micro-controller startup selection in the menuconfig. If the LED turns on you know that Klipper is running and you have a communication issue. If it doesn’t, then there is a build or programming issue.
I debugged klipper.elf using openocd and @koconnor told me that the problem is with the external clocking source, I tried changing the Clock Reference to Internal clock and the system worked: the LED lit up and I could find the uuid on the CAN bus. Then I found in Duet3_Exp_3HC_Schematic that MCU is connected to 12MHz crystal. I changed the following block in src/atsamd/Kconfig and everything is also working. I am working with board version 1.01, if you are working with board v1.02, you will need to select 25MHz crystal in make menuconfig.
choice
prompt "Clock Reference"
config CLOCK_REF_X32K
bool "32.768Khz crystal" if !MACH_SAMC21
config CLOCK_REF_X12M
bool "12Mhz crystal" if MACH_SAMC21 || MACH_SAMX5
config CLOCK_REF_X25M
bool "25Mhz crystal" if MACH_SAMC21 || MACH_SAMX5
config CLOCK_REF_INTERNAL
bool "Internal clock" if !MACH_SAMC21
endchoice
To flash Duet 3 Expansion 3HC you need to follow the steps below:
Change the src/atsamd/Kconfig file according to the attached file (rename to Kconfig) Kconfig.txt (7.1 KB)
Go to ~/klipper, make menuconfig. Select the following configuration and make. If you are using version 1.01, you need to select Clock Reference (12 MHz crystal).
Micro-controller Architecture (SAMC21/SAMD21/SAMD51/SAME5x)
Processor model (SAME51N19)
Bootloader offset (no bootloader)
Clock Reference (25MHz crystal)
Processor speed (120 MHz (standard))
Communication interface (CAN bus (on PB13/PB12))
GPIO pins to set at microcontroller startup (PC10)
Connect Duet6HC to Raspberry Pi via SWD: for this you need JST ZH 1.5mm 6pin connector. The connection diagram to Raspberry Pi 4: GPIO25 - SWDCLK, GPIO24 - SWDIO, GPIO18 - nRST, GND - GND, 3.3 V - 3.3 V.
Next you need to install Openocd on the Raspberry: I used the guide.
Create a file openocd.cfg (you can in the openocd folder or create your own). Here is my file, maybe there is something unnecessary in it (the path to the klipper.elf file may be different for you). openocd.cfg (383 Bytes)
From the folder with the file run sudo openocd
Check that there are no errors, programming and verification were successful and the DIAG_LED is on.
Connect CAN to a board that is programmed as USB to CAN bus bridge (e.g. Duet6HC) and look for the uuid of the board in the web interface or with the command ~/klippy-env/bin/python ~/klipper/scripts/canbus_query.py can0
Customize printer.cfg
When I make my printer.cfg for this board, I will also post it.
I added the 12M crystal implementation to samd51_clock and it seems to work as it should. Here is the resulting file. samd51_clock.c.txt (8.2 KB)
However, now I am facing another problem when connecting to the tmc5160 via SPI. The following error is displayed: “Unable to write tmc spi ‘stepper_x’ register GLOBALSCALER”. I have checked that all pins are specified correctly and tried to find a solution on the forum, but no success so far. @koconnor can you tell me if the source code supports this connection? Here are the settings from printer.cfg: