qmk / qmk_firmware

Open-source keyboard firmware for Atmel AVR and Arm USB families
https://qmk.fm
GNU General Public License v2.0
18.15k stars 39.08k forks source link

Errors when building for atmega328p #2445

Closed evyd13 closed 6 years ago

evyd13 commented 6 years ago

I have a board with an atmega328p which I'm trying to port to QMK, but I'm getting errors when building. You can find my code here: https://github.com/Maartenwut/ydpm40-qmk.

The error I'm getting is:

Compiling: ./tmk_core/common/avr/bootloader.c ./tmk_core/common/avr/bootloader.c: In function ‘bootloader_jump’: ./tmk_core/common/avr/bootloader.c:156:13: error: ‘UDCON’ undeclared (first use in this function) UDCON = 1; ^ ./tmk_core/common/avr/bootloader.c:156:13: note: each undeclared identifier is reported only once for each function it appears in ./tmk_core/common/avr/bootloader.c:157:13: error: ‘USBCON’ undeclared (first use in this function) USBCON = (1<<FRZCLK); // disable USB ^ ./tmk_core/common/avr/bootloader.c:157:26: error: ‘FRZCLK’ undeclared (first use in this function) USBCON = (1<<FRZCLK); // disable USB ^ ./tmk_core/common/avr/bootloader.c:158:13: error: ‘UCSR1B’ undeclared (first use in this function) UCSR1B = 0; ^

fredizzimo commented 6 years ago

You probably need a newer version of the AVR compiler. If the package manager of your operating system doesn't provide you one, you can install it from here http://www.microchip.com/avr-support/avr-and-arm-toolchains-(c-compilers)

drashna commented 6 years ago

Was this still an issue, @Maartenwut ?

evyd13 commented 6 years ago

I'll have another go at it tonight.

evyd13 commented 6 years ago

Still an issue unfortunately, same error. Even updated avr-gcc to 5.4.

drashna commented 6 years ago

What OS is this?

evyd13 commented 6 years ago

Debian Sid on a virtual machine. Are you able to build successfully?

drashna commented 6 years ago

yeah, it's erroring out for me, as well, same locations. So it's not a compiler error, I think. But rather a config issue.

I think that the 328p isn't supported by the bootloader_jump function properly, and that's why it's having issues.

fauxpark commented 6 years ago

These errors are occurring because the symbols UDCON, USBCON, FRZCLK and UCSR1B don't exist in the 328P-specific io.h (32U4 for comparison). And it is not that surprising - the 328P does not have any inbuilt USB functionality like the 32U4 does, so those registers don't physically exist.

Try changing this line to:

#ifndef __AVR_ATmega328P__

The 32A also does not have USB, so the block is ignored if we're compiling for that chip.

drashna commented 6 years ago

@fauxpark If that works for them, wouldn't it be a good idea to change that line to:

#if !defined(__AVR_ATmega32A__ ) && !defined(__AVR_ATmega328P__)

Assuming my syntax isn't completely wrong

fauxpark commented 6 years ago

It would, I just didn't recall OTOH exactly how to chain multiple ifndefs - that looks about right.

evyd13 commented 6 years ago

Works like a charm! Thanks guys 👍 Who's gonna do a pull request to edit this line?

drashna commented 6 years ago

ooo ooo, you are!

:)

Nah, I'll do it

RivasMario commented 1 year ago

if anyone finds this, for atmega328p you need to use usbaspoader bootloader