klipper icon indicating copy to clipboard operation
klipper copied to clipboard

avr: add lgt8f328p support

Open choryuidentify opened this issue 4 months ago • 3 comments

The Logic Green LGT8F328P is a low-cost, high-performance alternative to the ATmega328P. Unfortunately, due to several differences in chip specifications, firmware built for the ATmega328P cannot be used directly.

The main issue in Klipper is that the baud rate is corrupted by the chip’s clock configuration, causing serial communication to fail. This change resolves the issue by adjusting the CLKPR, and furthermore allows the clock to be increased up to 32 MHz, which is supported by the LGT8F328P.

image image

choryuidentify avatar Dec 18 '25 18:12 choryuidentify

oh, I found #6918 right before and I agree to this patch is (maybe) not have much users. But i decide to request this patch because... I have this board, and need small devboard to connect some devices, and... implementation is so simple. 🤗

choryuidentify avatar Dec 19 '25 01:12 choryuidentify

I add Port E and Port F for additional GPIO and ADC pins.

choryuidentify avatar Dec 20 '25 06:12 choryuidentify

Is it tested and ready from your side?

yes, I tested some peripherals (250000 host serial, BTT eddy with i2c, 12bit ADC)

choryuidentify avatar Dec 26 '25 04:12 choryuidentify

Thanks. Can you do something like the following to avoid having to overload CONFIG_MCU?

--- a/src/avr/Kconfig
+++ b/src/avr/Kconfig
@@ -54,6 +54,11 @@ config MCU
     default "atmega1280" if MACH_atmega1280
     default "atmega2560" if MACH_atmega2560
 
+config AVR_BUILD_MCU
+    string
+    default MCU if !MACH_lgt8f328p
+    default "atmega328p" if MACH_lgt8f328p
+
 config AVRDUDE_PROTOCOL
     string
     default "wiring" if MACH_atmega2560
diff --git a/src/avr/Makefile b/src/avr/Makefile
index f667de3b..7cf6d68f 100644
--- a/src/avr/Makefile
+++ b/src/avr/Makefile
@@ -6,7 +6,7 @@ CROSS_PREFIX=avr-
 dirs-y += src/avr src/generic
 
 CFLAGS-$(CONFIG_HAVE_LIMITED_CODE_SIZE) += -Os
-CFLAGS += $(CFLAGS-y) -mmcu=$(CONFIG_MCU)
+CFLAGS += $(CFLAGS-y) -mmcu=$(CONFIG_AVR_BUILD_MCU)
 
 # Add avr source files
 src-y += avr/main.c avr/timer.c

-Kevin

KevinOConnor avatar Dec 30 '25 02:12 KevinOConnor

Done!

choryuidentify avatar Dec 31 '25 02:12 choryuidentify

Thanks.

-Kevin

KevinOConnor avatar Dec 31 '25 02:12 KevinOConnor