Issue compiling firmware for atmega328p

Hello,
I have been running a dual MCU setup with an Arduino Nano as a secondary board. Compiling firmware for it went smoothly in the past, but I am now running into an issue updating it. Running make for either the atmega328 or 328p results in the following:

  Building out/compile_time_request.o
Version: v0.10.0-1-gb806d71e
  Linking out/klipper.elf
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x800a28 of out/klipper.elf section `.data' is not within region `data'
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x800b95 of out/klipper.elf section `.bss' is not within region `data'
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x800a28 of out/klipper.elf section `.data' is not within region `data'
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x800b95 of out/klipper.elf section `.bss' is not within region `data'
collect2: error: ld returned 1 exit status
make: *** [Makefile:72: out/klipper.elf] Error 1

It sounds like this has something to do with assigning memory, but I am not experienced with that kind of thing. Compiling for the atmega1284p for example works fine.

Works here with latest git.
Try running

make distclean
make menuconfig
make

Thanks for checking. There must be a difference in a compiler version or something else outside of Klipper I think. I tried make clean before, but distclean did not fix it either. Same results on two other systems with a fresh clone of Klipper.
I think the last time I compiled for the 328 successfully was on Debian Buster, but I am on Bullseye now.

Issue opened by another user here: v0.10.0-111-gdccd5554 Compile firmware For 328p failed · Issue #4872 · Klipper3d/klipper · GitHub
I added some details on a temporary workaround.

Hi there, the solution is

  • sudo nano /etc/apt/sources.list
  • Add deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
  • sudo nano /etc/apt/preferences.d/avr-buster

Package: avr-libc avrdud binutils-avr gcc-avr
Pin: release n=buster
Pin-Priority: 1001

-sudo apt update
-sudo apt install avr-libc avrdude binutils-avr gcc-avr
-make clean
-make and woala

image-elf-hex.zip (148.7 KB)

Now to flash our Arduino nano, we go inside the klipper folder and run the following: avrdude -C /etc/avrdude.conf -v -V -p atmega328p -carduino -P /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0 -b57600 -D -U flash:w:out/klipper.elf.hex:i

You have to specify the usb port of the Arduino, and also the model. The complete list is at the end

Result must be: >

avrdude: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

     System wide configuration file is "/etc/avrdude.conf"
     User configuration file is "/home/pi/.avrduderc"
     User configuration file does not exist or is not a regular file, skipping

     Using Port                    : /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
     Using Programmer              : arduino
     Overriding Baud Rate          : 57600
     AVR Part                      : ATmega328P
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PC2
     RESET disposition             : dedicated
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
       flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
       lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

     Programmer Type : Arduino
     Description     : Arduino
     Hardware Version: 2
     Firmware Version: 1.16
     Vtarget         : 0.0 V
     Varef           : 0.0 V
     Oscillator      : Off
     SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: reading input file “out/klipper.elf.hex”
avrdude: writing flash (30836 bytes):

Writing | ################################################## | 100% 9.66s

avrdude: 30836 bytes of flash written

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done. Thank you.

Complete list of devices:

Valid parts are:
uc3a0512 = AT32UC3A0512 [/etc/avrdude.conf:14601]
c128 = AT90CAN128 [/etc/avrdude.conf:3412]
c32 = AT90CAN32 [/etc/avrdude.conf:3796]
c64 = AT90CAN64 [/etc/avrdude.conf:3604]
pwm2 = AT90PWM2 [/etc/avrdude.conf:8989]
pwm216 = AT90PWM216 [/etc/avrdude.conf:9262]
pwm2b = AT90PWM2B [/etc/avrdude.conf:9182]
pwm3 = AT90PWM3 [/etc/avrdude.conf:9172]
pwm316 = AT90PWM316 [/etc/avrdude.conf:9209]
pwm3b = AT90PWM3B [/etc/avrdude.conf:9196]
1200 = AT90S1200 [/etc/avrdude.conf:1873]
2313 = AT90S2313 [/etc/avrdude.conf:2102]
2333 = AT90S2333 [/etc/avrdude.conf:2215]
2343 = AT90S2343 [/etc/avrdude.conf:2343]
4414 = AT90S4414 [/etc/avrdude.conf:1989]
4433 = AT90S4433 [/etc/avrdude.conf:2467]
4434 = AT90S4434 [/etc/avrdude.conf:2591]
8515 = AT90S8515 [/etc/avrdude.conf:2674]
8535 = AT90S8535 [/etc/avrdude.conf:2788]
usb1286 = AT90USB1286 [/etc/avrdude.conf:11909]
usb1287 = AT90USB1287 [/etc/avrdude.conf:12100]
usb162 = AT90USB162 [/etc/avrdude.conf:12113]
usb646 = AT90USB646 [/etc/avrdude.conf:11705]
usb647 = AT90USB647 [/etc/avrdude.conf:11896]
usb82 = AT90USB82 [/etc/avrdude.conf:12300]
m103 = ATmega103 [/etc/avrdude.conf:2909]
m128 = ATmega128 [/etc/avrdude.conf:3232]
m1280 = ATmega1280 [/etc/avrdude.conf:10014]
m1281 = ATmega1281 [/etc/avrdude.conf:10204]
m1284 = ATmega1284 [/etc/avrdude.conf:4608]
m1284p = ATmega1284P [/etc/avrdude.conf:4802]
m1284rfr2 = ATmega1284RFR2 [/etc/avrdude.conf:10639]
m128rfa1 = ATmega128RFA1 [/etc/avrdude.conf:10424]
m128rfr2 = ATmega128RFR2 [/etc/avrdude.conf:10527]
m16 = ATmega16 [/etc/avrdude.conf:3989]
m161 = ATmega161 [/etc/avrdude.conf:6134]
m162 = ATmega162 [/etc/avrdude.conf:4994]
m163 = ATmega163 [/etc/avrdude.conf:5192]
m164p = ATmega164P [/etc/avrdude.conf:4168]
m168 = ATmega168 [/etc/avrdude.conf:7964]
m168p = ATmega168P [/etc/avrdude.conf:8153]
m168pb = ATmega168PB [/etc/avrdude.conf:8165]
m169 = ATmega169 [/etc/avrdude.conf:5350]
m16u2 = ATmega16U2 [/etc/avrdude.conf:12677]
m2560 = ATmega2560 [/etc/avrdude.conf:10217]
m2561 = ATmega2561 [/etc/avrdude.conf:10411]
m2564rfr2 = ATmega2564RFR2 [/etc/avrdude.conf:10629]
m256rfr2 = ATmega256RFR2 [/etc/avrdude.conf:10478]
m32 = ATmega32 [/etc/avrdude.conf:5957]
m3208 = ATmega3208 [/etc/avrdude.conf:15744]
m3209 = ATmega3209 [/etc/avrdude.conf:15768]
m324p = ATmega324P [/etc/avrdude.conf:4192]
m324pa = ATmega324PA [/etc/avrdude.conf:4384]
m325 = ATmega325 [/etc/avrdude.conf:13047]
m3250 = ATmega3250 [/etc/avrdude.conf:13428]
m328 = ATmega328 [/etc/avrdude.conf:8366]
m328p = ATmega328P [/etc/avrdude.conf:8551]
m328pb = ATmega328PB [/etc/avrdude.conf:8559]
m329 = ATmega329 [/etc/avrdude.conf:5532]
m3290 = ATmega3290 [/etc/avrdude.conf:5731]
m3290p = ATmega3290P [/etc/avrdude.conf:5745]
m329p = ATmega329P [/etc/avrdude.conf:5717]
m32m1 = ATmega32M1 [/etc/avrdude.conf:8571]
m32u2 = ATmega32U2 [/etc/avrdude.conf:12489]
m32u4 = ATmega32U4 [/etc/avrdude.conf:11514]
m406 = ATMEGA406 [/etc/avrdude.conf:14939]
m48 = ATmega48 [/etc/avrdude.conf:7540]
m4808 = ATmega4808 [/etc/avrdude.conf:15792]
m4809 = ATmega4809 [/etc/avrdude.conf:15816]
m48p = ATmega48P [/etc/avrdude.conf:7727]
m48pb = ATmega48PB [/etc/avrdude.conf:7739]
m64 = ATmega64 [/etc/avrdude.conf:3049]
m640 = ATmega640 [/etc/avrdude.conf:9824]
m644 = ATmega644 [/etc/avrdude.conf:4400]
m644p = ATmega644P [/etc/avrdude.conf:4591]
m644rfr2 = ATmega644RFR2 [/etc/avrdude.conf:10649]
m645 = ATmega645 [/etc/avrdude.conf:13238]
m6450 = ATmega6450 [/etc/avrdude.conf:13440]
m649 = ATmega649 [/etc/avrdude.conf:5758]
m6490 = ATmega6490 [/etc/avrdude.conf:5944]
m64m1 = ATmega64M1 [/etc/avrdude.conf:8591]
m64rfr2 = ATmega64RFR2 [/etc/avrdude.conf:10540]
m8 = ATmega8 [/etc/avrdude.conf:6274]
m8515 = ATmega8515 [/etc/avrdude.conf:6435]
m8535 = ATmega8535 [/etc/avrdude.conf:6593]
m88 = ATmega88 [/etc/avrdude.conf:7752]
m88p = ATmega88P [/etc/avrdude.conf:7939]
m88pb = ATmega88PB [/etc/avrdude.conf:7951]
m8u2 = ATmega8U2 [/etc/avrdude.conf:12865]
t10 = ATtiny10 [/etc/avrdude.conf:14894]
t11 = ATtiny11 [/etc/avrdude.conf:1368]
t12 = ATtiny12 [/etc/avrdude.conf:1432]
t13 = ATtiny13 [/etc/avrdude.conf:1565]
t15 = ATtiny15 [/etc/avrdude.conf:1740]
t1604 = ATtiny1604 [/etc/avrdude.conf:15308]
t1606 = ATtiny1606 [/etc/avrdude.conf:15332]
t1607 = ATtiny1607 [/etc/avrdude.conf:15356]
t1614 = ATtiny1614 [/etc/avrdude.conf:15600]
t1616 = ATtiny1616 [/etc/avrdude.conf:15624]
t1617 = ATtiny1617 [/etc/avrdude.conf:15648]
t1634 = ATtiny1634 [/etc/avrdude.conf:14627]
t20 = ATtiny20 [/etc/avrdude.conf:14904]
t202 = ATtiny202 [/etc/avrdude.conf:15116]
t204 = ATtiny204 [/etc/avrdude.conf:15140]
t212 = ATtiny212 [/etc/avrdude.conf:15380]
t214 = ATtiny214 [/etc/avrdude.conf:15404]
t2313 = ATtiny2313 [/etc/avrdude.conf:8616]
t24 = ATtiny24 [/etc/avrdude.conf:10660]
t25 = ATtiny25 [/etc/avrdude.conf:9272]
t26 = ATtiny26 [/etc/avrdude.conf:6751]
t261 = ATtiny261 [/etc/avrdude.conf:6908]
t28 = ATtiny28 [/etc/avrdude.conf:7482]
t3214 = ATtiny3214 [/etc/avrdude.conf:15672]
t3216 = ATtiny3216 [/etc/avrdude.conf:15696]
t3217 = ATtiny3217 [/etc/avrdude.conf:15720]
t4 = ATtiny4 [/etc/avrdude.conf:14850]
t40 = ATtiny40 [/etc/avrdude.conf:14921]
t402 = ATtiny402 [/etc/avrdude.conf:15164]
t404 = ATtiny404 [/etc/avrdude.conf:15188]
t406 = ATtiny406 [/etc/avrdude.conf:15212]
t412 = ATtiny412 [/etc/avrdude.conf:15428]
t414 = ATtiny414 [/etc/avrdude.conf:15453]
t416 = ATtiny416 [/etc/avrdude.conf:15477]
t417 = ATtiny417 [/etc/avrdude.conf:15502]
t4313 = ATtiny4313 [/etc/avrdude.conf:8805]
t43u = ATtiny43u [/etc/avrdude.conf:11335]
t44 = ATtiny44 [/etc/avrdude.conf:10844]
t441 = ATtiny441 [/etc/avrdude.conf:11212]
t45 = ATtiny45 [/etc/avrdude.conf:9456]
t461 = ATtiny461 [/etc/avrdude.conf:7099]
t5 = ATtiny5 [/etc/avrdude.conf:14867]
t804 = ATtiny804 [/etc/avrdude.conf:15236]
t806 = ATtiny806 [/etc/avrdude.conf:15260]
t807 = ATtiny807 [/etc/avrdude.conf:15284]
t814 = ATtiny814 [/etc/avrdude.conf:15527]
t816 = ATtiny816 [/etc/avrdude.conf:15552]
t817 = ATtiny817 [/etc/avrdude.conf:15576]
t84 = ATtiny84 [/etc/avrdude.conf:11028]
t841 = ATtiny841 [/etc/avrdude.conf:11273]
t85 = ATtiny85 [/etc/avrdude.conf:9639]
t861 = ATtiny861 [/etc/avrdude.conf:7290]
t88 = ATtiny88 [/etc/avrdude.conf:8178]
t9 = ATtiny9 [/etc/avrdude.conf:14877]
x128a1 = ATxmega128A1 [/etc/avrdude.conf:13921]
x128a1d = ATxmega128A1revD [/etc/avrdude.conf:13937]
x128a1u = ATxmega128A1U [/etc/avrdude.conf:13947]
x128a3 = ATxmega128A3 [/etc/avrdude.conf:13958]
x128a3u = ATxmega128A3U [/etc/avrdude.conf:13968]
x128a4 = ATxmega128A4 [/etc/avrdude.conf:13979]
x128a4u = ATxmega128A4U [/etc/avrdude.conf:14037]
x128b1 = ATxmega128B1 [/etc/avrdude.conf:14090]
x128b3 = ATxmega128B3 [/etc/avrdude.conf:14149]
x128c3 = ATxmega128C3 [/etc/avrdude.conf:13848]
x128d3 = ATxmega128D3 [/etc/avrdude.conf:13901]
x128d4 = ATxmega128D4 [/etc/avrdude.conf:13911]
x16a4 = ATxmega16A4 [/etc/avrdude.conf:13579]
x16a4u = ATxmega16A4U [/etc/avrdude.conf:13506]
x16c4 = ATxmega16C4 [/etc/avrdude.conf:13559]
x16d4 = ATxmega16D4 [/etc/avrdude.conf:13569]
x16e5 = ATxmega16E5 [/etc/avrdude.conf:14496]
x192a1 = ATxmega192A1 [/etc/avrdude.conf:14223]
x192a3 = ATxmega192A3 [/etc/avrdude.conf:14239]
x192a3u = ATxmega192A3U [/etc/avrdude.conf:14249]
x192c3 = ATxmega192C3 [/etc/avrdude.conf:14160]
x192d3 = ATxmega192D3 [/etc/avrdude.conf:14213]
x256a1 = ATxmega256A1 [/etc/avrdude.conf:14323]
x256a3 = ATxmega256A3 [/etc/avrdude.conf:14339]
x256a3b = ATxmega256A3B [/etc/avrdude.conf:14360]
x256a3bu = ATxmega256A3BU [/etc/avrdude.conf:14370]
x256a3u = ATxmega256A3U [/etc/avrdude.conf:14349]
x256c3 = ATxmega256C3 [/etc/avrdude.conf:14260]
x256d3 = ATxmega256D3 [/etc/avrdude.conf:14313]
x32a4 = ATxmega32A4 [/etc/avrdude.conf:13668]
x32a4u = ATxmega32A4U [/etc/avrdude.conf:13595]
x32c4 = ATxmega32C4 [/etc/avrdude.conf:13648]
x32d4 = ATxmega32D4 [/etc/avrdude.conf:13658]
x32e5 = ATxmega32E5 [/etc/avrdude.conf:14548]
x384c3 = ATxmega384C3 [/etc/avrdude.conf:14381]
x384d3 = ATxmega384D3 [/etc/avrdude.conf:14434]
x64a1 = ATxmega64A1 [/etc/avrdude.conf:13768]
x64a1u = ATxmega64A1U [/etc/avrdude.conf:13784]
x64a3 = ATxmega64A3 [/etc/avrdude.conf:13795]
x64a3u = ATxmega64A3U [/etc/avrdude.conf:13805]
x64a4 = ATxmega64A4 [/etc/avrdude.conf:13816]
x64a4u = ATxmega64A4U [/etc/avrdude.conf:13684]
x64b1 = ATxmega64B1 [/etc/avrdude.conf:13826]
x64b3 = ATxmega64B3 [/etc/avrdude.conf:13837]
x64c3 = ATxmega64C3 [/etc/avrdude.conf:13737]
x64d3 = ATxmega64D3 [/etc/avrdude.conf:13748]
x64d4 = ATxmega64D4 [/etc/avrdude.conf:13758]
x8e5 = ATxmega8E5 [/etc/avrdude.conf:14444]
ucr2 = deprecated, use ‘uc3a0512’ [/etc/avrdude.conf:14617]

Regards

2 Likes

None of the other solutions worked for me to configure my Uno for the adxl345. I’m using Ubuntu, and klich3’s Buster fix just kept giving me errors when trying to sudo apt-get update. These steps are what I found worked for me, which I could not find anywhere else, so I will post them here in hopes that it helps someone save hours trying to get theirs to work. This is all done from a terminal window on the computer (or pi) with klipper:

cd ~/klipper
make menuconfig

-configure for the uno (atmega328p in my case), no changes to defaults for this chip. Exit and save

nano .config

-change anything you don’t need from y to n. For me this was:

CONFIG_WANT_GPIO_BITBANGING=n
CONFIG_WANT_DISPLAYS=n
CONFIG_WANT_SOFTWARE_I2C=n
CONFIG_HAVE_GPIO_ADC=n
CONFIG_HAVE_GPIO_I2C=n
CONFIG_HAVE_GPIO_HARD_PWM=n
CONFIG_INLINE_STEPPER_HACK=n

ctrl+s and ctrl+x to save and close

Some people have said that this is enough to get it to work for them, so try to compile again here:

make clean
make

This still gave me errors when trying to compile, so I had to do the next steps:

nano src/Makefile

Find the line that says:

sensors-src-$(CONFIG_HAVE_GPIO_SPI) := thermocouple.c sensor_adxl345.c \
    sensor_angle.c

and change it so that it only has sensor_adxl345.c, with the rest commented out.
You will want to change this back after, or other compilations will not have the other sensors (this may not be a problem depending on your printer)

sensors-src-$(CONFIG_HAVE_GPIO_SPI) := sensor_adxl345.c #thermocouple.c sensor_adxl345.c \
    #sensor_angle.c

after this, ctrl+s ctrl+x, and run

make clean
make

and it should compile with no memory/flash size related errors

1 Like

Thanks for this!

I changed the following and it sufficed: .config.zip (584 Bytes)

# These can be set instead in menuconfig.
CONFIG_WANT_DISPLAYS=n
CONFIG_WANT_SENSORS=n
CONFIG_WANT_LIS2DW=n
CONFIG_WANT_SOFTWARE_I2C=n
CONFIG_WANT_SOFTWARE_SPI=n

# These need to be set to "no".
CONFIG_HAVE_GPIO_SPI=n
CONFIG_HAVE_GPIO_I2C=n

Note that setting CONFIG_HAVE_GPIO_ADC=n would cause a protocol error later on.

Issues mentioning this:

I really regret to have found a comment from @Sineos saying that addressing this is low priority because the boards “are a dying breed anyway”.

In my opinion and local context, that idea would come out as rather obtuse. Everyone doing anything with electronics around me has an Arduino UNO and a CNC shield. I’d gladly bet that the UNO will probably outlive every board that has come out this year.

It would be better if Klipper could run on it without sacrifices. It is still probably the most popular entry-level MCU everywhere.

Thank You for this hint, Its fine in my case, but I had to purge before I was able to install the older version.

sudo apt purge avr-libc avrdude binutils-avr gcc-avr
sudo apt install avr-libc avrdude binutils-avr gcc-avr
1 Like