MCUdude / MiniCore

Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB
Other
984 stars 243 forks source link

Cannot compile bootloader #52

Closed canique closed 5 years ago

canique commented 6 years ago

The documentation says: "You need to install make, avr-libc, avr-binutils and avr-gcc"

I have avr-libc (2.0.0) binutils-avr (2.26) gcc-avr (5.4.0)

When executing: /usr/bin/avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328pb -DF_CPU=16000000L -DBAUD_RATE=115200 -DLED_START_FLASHES=2 -DLED=B5 -DUART=0 -c -o optiboot_flash.o optiboot_flash.c

I get numerous errors... (see below) but when I select mmcu=atmega328p then the compilation works...

In file included from optiboot_flash.c:250:0: /usr/lib/avr/include/avr/io.h:623:6: warning: #warning "device type not defined" [-Wcpp]

warning "device type not defined"

  ^

In file included from optiboot_flash.c:252:0: /usr/lib/avr/include/avr/eeprom.h:41:3: warning: #warning "Device does not have EEPROM available." [-Wcpp]

warning "Device does not have EEPROM available."

^ In file included from optiboot_flash.c:259:0: boot.h:127:4: error: #error AVR processor does not provide bootloader support!

error AVR processor does not provide bootloader support!

^

boot.h:138:4: error: #error Cannot find SPM Enable bit definition!

error Cannot find SPM Enable bit definition!

^

optiboot_flash.c:311:2: warning: #warning BAUD_RATE error greater than 2% [-Wcpp]

warning BAUD_RATE error greater than 2%

^ optiboot_flash.c: In function ‘main’: optiboot_flash.c:506:8: error: ‘MCUSR’ undeclared (first use in this function) ch = MCUSR; ^ optiboot_flash.c:506:8: note: each undeclared identifier is reported only once for each function it appears in In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:521:20: error: ‘WDRF’ undeclared (first use in this function) if ((ch & (_BV(WDRF) | _BV(EXTRF))) != _BV(EXTRF)) { ^ optiboot_flash.c:521:32: error: ‘EXTRF’ undeclared (first use in this function) if ((ch & (_BV(WDRF) | _BV(EXTRF))) != _BV(EXTRF)) { ^ optiboot_flash.c:545:3: error: ‘TCCR1B’ undeclared (first use in this function) TCCR1B = _BV(CS12) | _BV(CS10); // div 1024 ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:545:16: error: ‘CS12’ undeclared (first use in this function) TCCR1B = _BV(CS12) | _BV(CS10); // div 1024 ^ optiboot_flash.c:545:28: error: ‘CS10’ undeclared (first use in this function) TCCR1B = _BV(CS12) | _BV(CS10); // div 1024 ^ In file included from optiboot_flash.c:269:0: pin_defs.h:231:18: error: ‘UCSR0A’ undeclared (first use in this function)

define UART_SRA UCSR0A

              ^

optiboot_flash.c:557:3: note: in expansion of macro ‘UART_SRA’ UART_SRA = _BV(U2X0); //Double speed mode USART0 ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:557:18: error: ‘U2X0’ undeclared (first use in this function) UART_SRA = _BV(U2X0); //Double speed mode USART0 ^ In file included from optiboot_flash.c:269:0: pin_defs.h:232:18: error: ‘UCSR0B’ undeclared (first use in this function)

define UART_SRB UCSR0B

              ^

optiboot_flash.c:558:3: note: in expansion of macro ‘UART_SRB’ UART_SRB = _BV(RXEN0) | _BV(TXEN0); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:558:18: error: ‘RXEN0’ undeclared (first use in this function) UART_SRB = _BV(RXEN0) | _BV(TXEN0); ^ optiboot_flash.c:558:31: error: ‘TXEN0’ undeclared (first use in this function) UART_SRB = _BV(RXEN0) | _BV(TXEN0); ^ In file included from optiboot_flash.c:269:0: pin_defs.h:233:18: error: ‘UCSR0C’ undeclared (first use in this function)

define UART_SRC UCSR0C

              ^

optiboot_flash.c:559:3: note: in expansion of macro ‘UART_SRC’ UART_SRC = _BV(UCSZ00) | _BV(UCSZ01); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:559:18: error: ‘UCSZ00’ undeclared (first use in this function) UART_SRC = _BV(UCSZ00) | _BV(UCSZ01); ^ optiboot_flash.c:559:32: error: ‘UCSZ01’ undeclared (first use in this function) UART_SRC = _BV(UCSZ00) | _BV(UCSZ01); ^ In file included from optiboot_flash.c:269:0: pin_defs.h:234:18: error: ‘UBRR0L’ undeclared (first use in this function)

define UART_SRL UBRR0L

              ^

optiboot_flash.c:560:3: note: in expansion of macro ‘UART_SRL’ UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE 4L) / (BAUD_RATE 8L) - 1 ); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:332:30: error: ‘WDP2’ undeclared (first use in this function)

define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE))

                          ^

optiboot_flash.c:565:18: note: in expansion of macro ‘WATCHDOG_1S’ watchdogConfig(WATCHDOG_1S); ^ optiboot_flash.c:332:42: error: ‘WDP1’ undeclared (first use in this function)

define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE))

                                      ^

optiboot_flash.c:565:18: note: in expansion of macro ‘WATCHDOG_1S’ watchdogConfig(WATCHDOG_1S); ^ optiboot_flash.c:332:54: error: ‘WDE’ undeclared (first use in this function)

define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE))

                                                  ^

optiboot_flash.c:565:18: note: in expansion of macro ‘WATCHDOG_1S’ watchdogConfig(WATCHDOG_1S); ^ In file included from optiboot_flash.c:269:0: pin_defs.h:406:21: error: ‘DDRB’ undeclared (first use in this function)

define LED_DDR DDRB

                 ^

optiboot_flash.c:569:3: note: in expansion of macro ‘LED_DDR’ LED_DDR |= _BV(LED); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: pin_defs.h:409:17: error: ‘PINB5’ undeclared (first use in this function)

define LED PINB5

             ^

optiboot_flash.c:569:18: note: in expansion of macro ‘LED’ LED_DDR |= _BV(LED); ^ optiboot_flash.c:748:13: error: ‘SIGNATURE_0’ undeclared (first use in this function) putch(SIGNATURE_0); ^ optiboot_flash.c:749:13: error: ‘SIGNATURE_1’ undeclared (first use in this function) putch(SIGNATURE_1); ^ optiboot_flash.c:750:13: error: ‘SIGNATURE_2’ undeclared (first use in this function) putch(SIGNATURE_2); ^ In file included from optiboot_flash.c:269:0: optiboot_flash.c: In function ‘putch’: pin_defs.h:231:18: error: ‘UCSR0A’ undeclared (first use in this function)

define UART_SRA UCSR0A

              ^

optiboot_flash.c:767:12: note: in expansion of macro ‘UART_SRA’ while (!(UART_SRA & _BV(UDRE0))); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:767:27: error: ‘UDRE0’ undeclared (first use in this function) while (!(UART_SRA & _BV(UDRE0))); ^ In file included from optiboot_flash.c:269:0: pin_defs.h:235:18: error: ‘UDR0’ undeclared (first use in this function)

define UART_UDR UDR0

              ^

optiboot_flash.c:768:3: note: in expansion of macro ‘UART_UDR’ UART_UDR = ch; ^ optiboot_flash.c: In function ‘getch’: pin_defs.h:231:18: error: ‘UCSR0A’ undeclared (first use in this function)

define UART_SRA UCSR0A

              ^

optiboot_flash.c:834:11: note: in expansion of macro ‘UART_SRA’ while(!(UART_SRA & _BV(RXC0))) ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:834:26: error: ‘RXC0’ undeclared (first use in this function) while(!(UART_SRA & _BV(RXC0))) ^ optiboot_flash.c:836:24: error: ‘FE0’ undeclared (first use in this function) if (!(UART_SRA & _BV(FE0))) { ^ In file included from optiboot_flash.c:269:0: pin_defs.h:235:18: error: ‘UDR0’ undeclared (first use in this function)

define UART_UDR UDR0

              ^

optiboot_flash.c:848:8: note: in expansion of macro ‘UART_UDR’ ch = UART_UDR; ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c: In function ‘verifySpace’: optiboot_flash.c:326:30: error: ‘WDE’ undeclared (first use in this function)

define WATCHDOG_16MS (_BV(WDE))

                          ^

optiboot_flash.c:890:20: note: in expansion of macro ‘WATCHDOG_16MS’ watchdogConfig(WATCHDOG_16MS); // shorten WD timeout ^ optiboot_flash.c: In function ‘flash_led’: optiboot_flash.c:900:5: error: ‘TCNT1’ undeclared (first use in this function) TCNT1 = -(F_CPU/(1024*16)); ^ optiboot_flash.c:901:5: error: ‘TIFR1’ undeclared (first use in this function) TIFR1 = _BV(TOV1); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:901:17: error: ‘TOV1’ undeclared (first use in this function) TIFR1 = _BV(TOV1); ^ In file included from optiboot_flash.c:269:0: pin_defs.h:408:21: error: ‘PINB’ undeclared (first use in this function)

define LED_PIN PINB

                 ^

optiboot_flash.c:908:5: note: in expansion of macro ‘LED_PIN’ LED_PIN |= _BV(LED); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: pin_defs.h:409:17: error: ‘PINB5’ undeclared (first use in this function)

define LED PINB5

             ^

optiboot_flash.c:908:20: note: in expansion of macro ‘LED’ LED_PIN |= _BV(LED); ^ optiboot_flash.c: In function ‘watchdogConfig’: optiboot_flash.c:923:3: error: ‘WDTCSR’ undeclared (first use in this function) WDTCSR = _BV(WDCE) | _BV(WDE); ^ In file included from /usr/lib/avr/include/avr/io.h:99:0, from optiboot_flash.c:250: optiboot_flash.c:923:16: error: ‘WDCE’ undeclared (first use in this function) WDTCSR = _BV(WDCE) | _BV(WDE); ^ optiboot_flash.c:923:28: error: ‘WDE’ undeclared (first use in this function) WDTCSR = _BV(WDCE) | _BV(WDE); ^ optiboot_flash.c: In function ‘writebuffer’: boot.h:207:40: error: ‘__SPM_ENABLE’ undeclared (first use in this function)

define __BOOT_PAGE_ERASE (_BV(__SPM_ENABLE) | _BV(PGERS))

                                    ^

optiboot_flash.c:983:38: note: in expansion of macro ‘BOOT_PAGE_ERASE’ do_spm((uint16_t)(void*)address,BOOT_PAGE_ERASE,0); ^ boot.h:207:60: error: ‘PGERS’ undeclared (first use in this function)

define __BOOT_PAGE_ERASE (_BV(__SPM_ENABLE) | _BV(PGERS))

                                                        ^

optiboot_flash.c:983:38: note: in expansion of macro ‘BOOT_PAGE_ERASE’ do_spm((uint16_t)(void*)address,BOOT_PAGE_ERASE,0); ^ boot.h:208:60: error: ‘PGWRT’ undeclared (first use in this function)

define __BOOT_PAGE_WRITE (_BV(__SPM_ENABLE) | _BV(PGWRT))

                                                        ^

optiboot_flash.c:999:38: note: in expansion of macro ‘BOOT_PAGE_WRITE’ do_spm((uint16_t)(void*)address,BOOT_PAGE_WRITE,0); ^ optiboot_flash.c: In function ‘do_spm’: optiboot_flash.c:1084:25: error: ‘SPM_REG’ undeclared (first use in this function) : "i" (_SFR_IO_ADDR(SPM_REG)), ^ boot.h:199:65: error: ‘__SPM_ENABLE’ undeclared (first use in this function)

define boot_spm_busy() (__SPM_REG & (uint8_t)_BV(__SPM_ENABLE))

                                                             ^

boot.h:205:49: note: in expansion of macro ‘boot_spm_busy’

define boot_spm_busy_wait() do{}while(boot_spm_busy())

                                             ^

optiboot_flash.c:1095:5: note: in expansion of macro ‘boot_spm_busy_wait’ boot_spm_busy_wait(); ^

MCUdude commented 6 years ago

That's because the stock version of avr-gcc 5.4.0 doesn't support ATmega328PB. I'm using the compiler that's included in AVR boards v1.6.207. On my mac it's located in the following directory: /Users/Hans/Library/Arduino15/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2/bin/avr-gcc

canique commented 6 years ago

Great, thank you! I could compile it under Windows now by using the compiler in /Users/{username}/AppData/Local/Arduino15/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2/bin/avr-gcc

Just for reference: Under linux I used this preferences file under /etc/apt/preferences.d/: Package: gcc-avr binutils-avr avr-libc libmpfr6 libstdc++6 libmpc3 Pin: release a=testing Pin-Priority: 950

Package: * Pin: release a=testing Pin-Priority: 99

and installed with this command sudo apt-get install gcc-avr binutils-avr avr-libc libmpfr6 libmpc3

but this only gives you version 5.4.0-atmel3.6.0 so it's not the correct version.

MCUdude commented 6 years ago

Thanks for the info. I'll update the instructions as soon as gcc 5.4.x supports the new *PB series 👍

MCUdude commented 5 years ago

Should be fixed now. See https://github.com/MCUdude/optiboot_flash for details.