Skip to content

Import the AVR arduino core. #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 19, 2023
Merged

Import the AVR arduino core. #48

merged 2 commits into from
Aug 19, 2023

Conversation

obra
Copy link
Member

@obra obra commented Aug 19, 2023

Arduino's AVR core has a bug where it locks up USB serial when it receives a 384 byte serial packet from macOS due to a bug in ZLP handling. This is fixed by patch arduino/Arduino#6886, which has been unapplied for the past 6 years.

This PR forks the Arduino AVR core so that our keyboards don't lock up when programmed on macOS.

From 34234c2c6a4cb77a60254e3db4c2d08d912684e6 Mon Sep 17 00:00:00 2001
From: Sandeep Mistry <s.mistry@bcmi-labs.cc>
Date: Fri, 3 Nov 2017 12:03:54 -0400
Subject: [PATCH] Handle receiving a ZLP in USB_Available

---
 cores/arduino/USBCore.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp
index e00fb028e22..4c5c50bfd16 100644
--- a/cores/arduino/USBCore.cpp
+++ b/cores/arduino/USBCore.cpp
@@ -171,6 +171,11 @@ static inline u8 FifoFree()
        return UEINTX & (1<<FIFOCON);
 }
 
+static inline u8 HasOUT()
+{
+       return UEINTX & (1<<RXOUTI);
+}
+
 static inline void ReleaseRX()
 {
        UEINTX = 0x6B;  // FIFOCON=0 NAKINI=1 RWAL=1 NAKOUTI=0 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=1
@@ -214,7 +219,12 @@ class LockEP
 u8 USB_Available(u8 ep)
 {
        LockEP lock(ep);
-       return FifoByteCount();
+       u8 n = FifoByteCount();
+
+       if (!n && HasOUT())
+               ReleaseRX(); // handle ZLP
+
+       return n;
 }
 
 //     Non Blocking receive

@obra obra merged commit 3578b64 into master Aug 19, 2023
@obra obra deleted the f/import-core branch August 19, 2023 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant