# Serial integrity issues with Duet3D Mini 5+ MCU code compiled on Bookworm & Trixie

**URL:** <https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109>\
**Category:** General Discussion\
**Created:** [October 28, 2025, 4:27am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109 "2025-10-28T04:27:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ReXT3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/rext3d/32/200_2.png) [@ReXT3D](https://klipper.discourse.group/u/ReXT3D)\
**Post date:** [October 28, 2025, 4:27am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/1 "2025-10-28T04:27:14Z")

</div>

### Summary:

The two most recent releases of the Raspberry Pi OS, Bookworm & Trixie, both produce MCU executables for Duet3D Mini 5+ (SAME54P20) that experience communication integrity issues between the host and the MCU over the standard USB interface. This results in perpetually increasing counts of `bytes_retransmit` and `bytes_invalid` in the `klippy.log` file.

### Background:

I recently completed some long outstanding maintenance on my oldest printer, which is a heavily modified CR-10S Pro running on a Duet 3D Mini 5+ MCU board with a Raspberry Pi 3B+ host. While already investing my time, I decided to upgrade the Pi to Trixie since it was still running on Bullseye. I previously attempted to upgrade this machine to Bookworm, but the Pi 3B+ experienced random OS freezes that forced me to revert to Bullseye. With the Pi upgraded to Trixie and the MCU code recompiled on Trixie and re-flashed, the machine started experiencing random shutdowns caused by `Lost communication with MCU ‘mcu’` errors.

It took many days to isolate this issue to the compiled MCU code. Inspecting the `klippy.log` from the CR-10S Pro revealed the first clue with increasing counts of `bytes_retransmit` and `bytes_invalid`, a significant deviation from years of constant `bytes_retransmit=9 bytes_invalid=0`in all previous releases of Pi OS. I involved my Voron that also runs on a Duet 3D Mini 5+ MCU board but with a Raspberry Pi 4B+ host running Bookworm. To my surprise and confusion I discovered that the Voron logs also showed similar increasing counts of `bytes_retransmit` and `bytes_invalid` (running on Bookworm). What made this even more confusing is that the comms errors would only increase when the stepper motors were active and in motion. I spent a few days chasing potential EMI issues and even looked at the power supply rails with my oscilloscope. Everything looked normal. I then decided to experiment with different versions of the Pi OS on the Voron…

### Findings:

Bullseye, Bookworm & Trixie all work fine with no comms errors, but only if the Duet MCU firmware is compiled on Bullseye. Following is a handy matrix summarizing my test results. The two numbers in each cell represent the total count of `bytes_retransmit` and `bytes_invalid` after homing and a few seconds of the exact same XY movements run by a macro.

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/3X/a/6/a637939a3e629533aaa3d851e34be6d952034870.png)

This immediately brought back bad memories of the issues with Bullseye compiling bad executable for Duet 2 MCU boards: [Duet 2 firmware compilation broken on Debian 11](https://klipper.discourse.group/t/duet-2-firmware-compilation-broken-on-debian-11/4762).

It seems that someone or something “out there” just does not like the idea of Klipper running on Duet hardware 😆 . Having said that, I would venture a guess that in many cases people may not even realize that they have communication issues between the host and the MCU without specifically checking the `klippy.log` file. In my case the Voron has been running on Bookworm since March 2025 without any obvious functional effects of these communication issues.

I wonder if any other MCUs are perhaps experiencing similar issues, or whether this is specifically limited to the Duet3D Mini 5+.

---

<div class="post-metadata">

**Author:** ![hcet14](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@hcet14](https://klipper.discourse.group/u/hcet14)\
**Post date:** [October 28, 2025, 6:46pm UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/2 "2025-10-28T18:46:02Z")

</div>

Interesting, thanks. You could post these findings also here [https://forums.raspberrypi.com](https://forums.raspberrypi.com).

---

<div class="post-metadata">

**Author:** ![ReXT3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/rext3d/32/200_2.png) [@ReXT3D](https://klipper.discourse.group/u/ReXT3D)\
**Post date:** [October 29, 2025, 4:23am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/3 "2025-10-29T04:23:30Z")

</div>

I am convinced that this is either a toolchain issue in the newer Linux distros or there is perhaps something fragile in the `atsamd` Klipper code.

---

<div class="post-metadata">

**Author:** ![koconnor](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@koconnor](https://klipper.discourse.group/u/koconnor)\
**Post date:** [November 4, 2025, 12:04am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/4 "2025-11-04T00:04:03Z")

</div>

Can you provide the gcc versions used to compile the mcu code (or post a Klipper log file from the broken versions so that we have that info)?

We recently ran into issues with gcc v12.0 compilers on the host - [serialqueue: decouple pending & ready queues by KevinOConnor · Pull Request #7100 · Klipper3d/klipper · GitHub](https://github.com/Klipper3d/klipper/pull/7100) . It’s entirely possible the same gcc issue could impact the mcu code.

-Kevin

---

<div class="post-metadata">

**Author:** ![ReXT3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/rext3d/32/200_2.png) [@ReXT3D](https://klipper.discourse.group/u/ReXT3D)\
**Post date:** [November 4, 2025, 2:28pm UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/5 "2025-11-04T14:28:55Z")

</div>

Thanks for your response Kevin, I was indeed curious if these issues could be related when I saw PR 7100.

Here are the gcc versions that I tried thus far:

| Pi OS | GCC Version | MCU Comms |
| --- | --- | --- |
| Bullseye | gcc: (15:8-2019-q3-1+b1) 8.3.1 20190703 (release) [gcc-8-branch revision 273027] binutils: (2.35.2-2+14+b2) 2.35.2 | Stable |
| Bookworm | gcc: (15:12.2.rel1-1) 12.2.1 20221205 binutils: (2.40-2+18+b1) 2.40 | Errors |
| Trixie | gcc: (15:14.2.rel1-1) 14.2.1 20241119 binutils: (2.44-3+23+b2) 2.44 | Errors |

| |
| --- |
| |

If and when I have a bit more time I will experiment some more with different sdk versions…

---

<div class="post-metadata">

**Author:** ![ReXT3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/rext3d/32/200_2.png) [@ReXT3D](https://klipper.discourse.group/u/ReXT3D)\
**Post date:** [November 5, 2025, 4:58am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/6 "2025-11-05T04:58:06Z")

</div>

This was really bugging me, no pun intended, so I spent some more time exploring. I think I can pretty conclusively confirm that this issue is caused by the compiler. Which likely means that many people running on Bookworm or Trixie, particularly on a Raspberry Pi, are likely seeing similar issues even on other non-Duet MCUs.

How have I reached this conclusion? I run three additional tests:

1. On my Ubuntu 25.10 VM I first removed the `gcc-arm-none-eabi` package.
2. I then installed the very latest toolchain `arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi` from [Arm GNU Toolchain Downloads – Arm Developer](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) and I recompiled the MCU code and reflashed the MCU. This continued to produce MCU comms errors.
3. I then installed the pre gcc-12 based `arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi` and I recompiled the MCU code and reflashed the MCU. This produced stable MCU comms!
4. Finally, I removed the `gcc-arm-none-eabi` package and installed `arm-gnu-toolchain-11.3.rel1-aarch64-arm-none-eabi` on a test Raspberry Pi running Trixie. I recompiled the MCU code and reflashed the MCU. Predictably, this also produces stable MCU comms!

I was additionally going to install the most recent toolchain `arm-gnu-toolchain-14.3.rel1` on a Raspberry Pi running on Bullseye to confirm that it breaks the MCU code again, but I run out of time. I think what I have done is pretty conclusive.

It is somewhat shocking that this type of a bug would persist in a compiler for so many years! Undoubtedly it must produce numerous other regressions outside of Klipper.

---

<div class="post-metadata">

**Author:** ![koconnor](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@koconnor](https://klipper.discourse.group/u/koconnor)\
**Post date:** [November 6, 2025, 2:35am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/7 "2025-11-06T02:35:00Z")

</div>

For what it is worth, it is possible that there is a subtle bug in the Klipper atsamd implementation that is only now being exposed by a minor change in the compiler. Unfortunately, tracking down these types of issues is challenging.

There is a gcc v15.1 version available. My Fedora desktop machine has that version (`arm-none-eabi-gcc (Fedora 15.1.0-1.fc42) 15.1.0`). It would probably be a good idea to check if the issue goes away with the very latest gcc version. (If it does go away, there’s a greater chance the issue is the compiler.) If you don’t have access to that gcc version I can compile a binary for you, or you can wait until I’m able to run tests on my atsamd test chips.

Thanks,  
-Kevin

---

<div class="post-metadata">

**Author:** ![ReXT3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/rext3d/32/200_2.png) [@ReXT3D](https://klipper.discourse.group/u/ReXT3D)\
**Post date:** [November 6, 2025, 2:26pm UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/8 "2025-11-06T14:26:09Z")

</div>

I’ve done just enough coding in the past, including some fiddling with gcc on an ancient m68k architecture, to understand that this is like finding the proverbial needle in a haystack.

I̶f̶ ̶y̶o̶u̶ ̶c̶o̶m̶p̶i̶l̶e̶ ̶a̶ ̶b̶i̶n̶a̶r̶y̶ ̶w̶i̶t̶h̶ ̶g̶c̶c̶ ̶v̶1̶5̶.̶1̶ ̶f̶o̶r̶ ̶S̶A̶M̶E̶5̶4̶P̶2̶0̶,̶ ̶I̶ ̶w̶o̶u̶l̶d̶ ̶b̶e̶ ̶v̶e̶r̶y̶ ̶h̶a̶p̶p̶y̶ ̶t̶o̶ ̶t̶r̶y̶ ̶i̶t̶.̶

UPDATE 1: I set-up arm toolchain build environment in an Ubuntu VM using the instructions from [Tooling / gnu-devtools-for-arm · GitLab](https://gitlab.arm.com/tooling/gnu-devtools-for-arm) . This will allow me to assemble the toolchain with different versions of the required components. I am currently building a toolchain with the latest gcc-15.2 sources. Will provide additional updates when I have them…

UPDATE 2: Not good news, unfortunately. The comms errors persist with the latest gcc 15.2.0: `bytes_retransmit=742 bytes_invalid=1246 send_seq=6503`

UPDATE 3: I can confirm that there are no comms errors with gcc 11.5.0 that I built from sources obtained from [gnu.org](http://gnu.org). Advancing from gcc 11.5.0 to 12.1.0 introduces the regression and the comms errors begin. FWIW, I started with source from [arm-gnu-toolchain-src-snapshot-14.3.rel1.tar.xz](https://developer.arm.com/-/media/Files/downloads/gnu/14.3.rel1/srcrel/arm-gnu-toolchain-src-snapshot-14.3.rel1.tar.xz), and then rebuilt the toolchain repeatedly by replacing the `gcc` source sub-directory with gcc sources downloaded from [gnu.org](http://gnu.org) for each version that I tested. So the only change in the sources was the gcc. This was fun - it took many hours for each toolchain build in a VM on a Ryzen 5950x. Almost reminded me of bootstrapping gcc 3 on a m68k years ago… almost.

At this point I think the next step is klipper code review (above my paygrade) or perhaps disassembly of the object files (also above my paygrade). I can fairly easily supply the object files for all gcc versions that I tested.

UPDATE 4: Almost by pure coincidence I discovered that when the final executable is linked with the `-fno-lto` flag, the resultant exacutable no longer shows the comms errors with the recent gcc versions. Of course this creates other issues, such as adverse impact on MCU performance and resultant `MCU ‘mcu’ shutdown: Rescheduled timer in the past` errors if I try to run the printer at full speed (Voron 2.4 at 300-350 mm/s with 0.8 deg steppers set to 128 microsteps). But the comms errors disappear.

Thank you.

---

<div class="post-metadata">

**Author:** ![koconnor](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@koconnor](https://klipper.discourse.group/u/koconnor)\
**Post date:** [December 13, 2025, 1:10am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/9 "2025-12-13T01:10:17Z")

</div>

Okay, thanks. I finally got around to testing my ATSAME51J19 test board (“Adafruit Feather M4 CAN Express”). It seems I can reproduce something similar here.

I can compile and flash the firmware with both new and old gcc.  
New shows: `Loaded 130 commands (v0.13.0-424-g818b49e4 / gcc: (Fedora 15.1.0-1.fc42) 15.1.0 binutils: (Fedora 2.44-1.fc42) 2.44)`  
Old shows: `Loaded 130 commands (v0.13.0-423-gf52a6f94 / gcc: (15:7-2018-q2-6) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] binutils: (2.31.1-11+rpi1+11) 2.31.1)`

Both seem to run fine when idling. However, I get different results if I stress the communication interface via the command benchmark test ( [Benchmarks - Klipper documentation](https://www.klipper3d.org/Benchmarks.html#command-dispatch-benchmark) ). The old gcc does not show any incrementing `invalid_bytes`. The new gcc shows a large amount of incrementing `invalid_bytes`. I don’t see retransmits on either, but I’d guess that is due to the nature of the command benchmark test.

This would seem to indicate that there is a problem in the low-level USB mcu to host tx implementation on atsamd.

I’ll try to investigate further.  
-Kevin

---

<div class="post-metadata">

**Author:** ![koconnor](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@koconnor](https://klipper.discourse.group/u/koconnor)\
**Post date:** [December 13, 2025, 4:10am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/10 "2025-12-13T04:10:06Z")

</div>

I think I was able to track this down. It looks like a bug that has always been in the code, and is now showing up due to a slightly different memory layout in newer versions of gcc. Hopefully the issue is fixed with the PR at: [atsamd: Fix possible buffer overflow in usbserial.c by KevinOConnor · Pull Request #7142 · Klipper3d/klipper · GitHub](https://github.com/Klipper3d/klipper/pull/7142)

-Kevin

---

<div class="post-metadata">

**Author:** ![ReXT3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/rext3d/32/200_2.png) [@ReXT3D](https://klipper.discourse.group/u/ReXT3D)\
**Post date:** [December 13, 2025, 5:17am UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/11 "2025-12-13T05:17:03Z")

</div>

Hi Kevin, thank you so much for looking into this!

Coincidentally, today was my last official work day for the year and I was just about to post with a question if there was anything else I could do to help on my end 😃

I am delighted to report that the MCU code compiled with the current gcc on Trixie, `Loaded MCU ‘mcu’ 130 commands (v0.13.0-423-gf52a6f94-dirty-20251212_235642-raspberry / gcc: (15:14.2.rel1-1) 14.2.1 20241119 binutils: (2.44-3+23+b2) 2.44)`, now works perfectly and there are no longer any communication anomalies!

Many thanks for your time!  
Peter

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/klipper/original/1X/64419bf2aac6639e6ef5cef200dcd456b0a01ac3.png) [@system](https://klipper.discourse.group/u/system)\
**Post date:** [January 12, 2026, 3:17pm UTC](https://klipper.discourse.group/t/serial-integrity-issues-with-duet3d-mini-5-mcu-code-compiled-on-bookworm-trixie/25109/12 "2026-01-12T15:17:27Z")

</div>

Closed on January 12, 2026, 3:17pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
