Skip to content
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

_BV was not declared in this scope while trying to compile Marlin #147

Open
dc740 opened this issue Jul 7, 2019 · 12 comments
Open

_BV was not declared in this scope while trying to compile Marlin #147

dc740 opened this issue Jul 7, 2019 · 12 comments

Comments

@dc740
Copy link

dc740 commented Jul 7, 2019

The error log is extensive, but it simply complains about _BV being out of scope. This can be reproduced by compiling Marling on branch bugfix-2.0.x (I haven't tried the 1.1 branch)

#######
Workaround:
Locate the packages directory (linux: inside ~/.arduino15) and find the Arduino.h file inside MCUdude_corefiles directory.

~/.arduino15/packages/MightyCore/hardware/avr/2.0.4/cores/MCUdude_corefiles/Arduino.h
(update the version as needed)

Add this:

#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif

#######

Error log when not using the workaround:

Arduino: 1.8.9 (Linux), Board: "ATmega1284, Yes (UART0), Standard pinout, 1284P, BOD 2.7V, LTO disabled, External 16 MHz"

In file included from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:19:0,
                 from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/Arduino.h:290,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/../shared/Marduino.h:33,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/HAL.h:27,
                 from sketch/src/lcd/dogm/../../inc/MarlinConfig.h:30,
                 from sketch/src/lcd/dogm/HAL_LCD_class_defines.h:24,
                 from sketch/src/lcd/dogm/ultralcd_DOGM.h:31,
                 from sketch/src/lcd/dogm/lcdprint_u8g.cpp:14:
/home/dc740/arduino-1.8.9/hardware/tools/avr/avr/include/avr/power.h: In function 'void clock_prescale_set(clock_div_t)':
/home/dc740/arduino-1.8.9/hardware/tools/avr/avr/include/avr/power.h:1511:31: error: '_BV' was not declared in this scope
     uint8_t __tmp = _BV(CLKPCE);
                               ^
In file included from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:14:0,
                 from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/Arduino.h:290,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/../shared/Marduino.h:33,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/HAL.h:27,
                 from sketch/src/lcd/dogm/../../inc/MarlinConfig.h:30,
                 from sketch/src/lcd/dogm/HAL_LCD_class_defines.h:24,
                 from sketch/src/lcd/dogm/ultralcd_DOGM.h:31,
                 from sketch/src/lcd/dogm/lcdprint_u8g.cpp:14:
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void enableSleep()':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:81:5: error: '_BV' was not declared in this scope
     sleep_enable();
     ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void disableSleep()':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:90:5: error: '_BV' was not declared in this scope
     sleep_disable();
     ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void sleepMode(uint8_t)':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:102:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_IDLE);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:107:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_ADC);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:112:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_PWR_DOWN);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:117:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_PWR_SAVE);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:122:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_STANDBY);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:127:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_EXT_STANDBY);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void sleep()':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:148:5: error: '_BV' was not declared in this scope
     sleep_mode();
     ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:148:5: error: '_BV' was not declared in this scope
     sleep_mode();
     ^
In file included from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:19:0,
                 from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/Arduino.h:290,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/../shared/Marduino.h:33,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/HAL.h:27,
                 from sketch/src/lcd/dogm/../../inc/MarlinConfig.h:30,
                 from sketch/src/lcd/dogm/HAL_LCD_class_defines.h:24,
                 from sketch/src/lcd/dogm/ultralcd_DOGM.h:31,
                 from sketch/src/lcd/dogm/ultralcd_DOGM.cpp:42:
/home/dc740/arduino-1.8.9/hardware/tools/avr/avr/include/avr/power.h: In function 'void clock_prescale_set(clock_div_t)':
/home/dc740/arduino-1.8.9/hardware/tools/avr/avr/include/avr/power.h:1511:31: error: '_BV' was not declared in this scope
     uint8_t __tmp = _BV(CLKPCE);
                               ^
In file included from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:14:0,
                 from /home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/Arduino.h:290,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/../shared/Marduino.h:33,
                 from sketch/src/lcd/dogm/../../inc/../HAL/HAL_AVR/HAL.h:27,
                 from sketch/src/lcd/dogm/../../inc/MarlinConfig.h:30,
                 from sketch/src/lcd/dogm/HAL_LCD_class_defines.h:24,
                 from sketch/src/lcd/dogm/ultralcd_DOGM.h:31,
                 from sketch/src/lcd/dogm/ultralcd_DOGM.cpp:42:
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void enableSleep()':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:81:5: error: '_BV' was not declared in this scope
     sleep_enable();
     ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void disableSleep()':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:90:5: error: '_BV' was not declared in this scope
     sleep_disable();
     ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void sleepMode(uint8_t)':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:102:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_IDLE);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:107:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_ADC);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:112:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_PWR_DOWN);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:117:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_PWR_SAVE);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:122:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_STANDBY);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:127:9: error: '_BV' was not declared in this scope
         set_sleep_mode(SLEEP_MODE_EXT_STANDBY);
         ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h: In function 'void sleep()':
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:148:5: error: '_BV' was not declared in this scope
     sleep_mode();
     ^
/home/dc740/.arduino15/packages/MightyCore/hardware/avr/2.0.2/cores/MCUdude_corefiles/wiring_extras.h:148:5: error: '_BV' was not declared in this scope
     sleep_mode();
     ^
exit status 1
Error compiling for board ATmega1284.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

@MCUdude
Copy link
Owner

MCUdude commented Jul 7, 2019

I have no experience with the Marlin FW. What happens if you add #include <avr/sfr_defs.h> to the top of the INO file?

@dc740
Copy link
Author

dc740 commented Jul 7, 2019

I get exactly the same error

@dc740
Copy link
Author

dc740 commented Jul 7, 2019

OK, I got around it by manually defining _BV in the power.h file. So, basically, adding #define _BV(bit) (1 << (bit)) inside of ~/arduino-1.8.9/hardware/tools/avr/avr/include/avr/power.h seems to be a good workaround. Adding it at the top of the .ino file made no difference, nor adding the .h file

A member of the arduino forums made me notice that MightyCore code is using the standard arduino pinout. I need to change this to the Sanguino pinout (Tools > Pinout > Sanguino).

@msalajka
Copy link

i've tried it (Marlin bugfix-2.0.x) with Ender 3 (board v1.1.4).

good place to put fix is:
..\packages\MightyCore\hardware\avr\2.0.2\cores\MCUdude_corefiles\Arduino.h

#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif

MightyCore/ATmega1284 setup:

  • Clock External 16 MHz
  • BOD disabled
  • LTO disabled
  • Sanguino pinout
  • 1284P variant
  • Bootloader UART0

bootloader burned via USBasp, Marlin firmware uploaded via usb.
Sketch uses 129972 bytes (99%) of program storage space.
With LTO enabled, sketch uses 122708 bytes (94%) of program storage space.

It works ok. ;)

@dc740
Copy link
Author

dc740 commented Jul 18, 2019

Same here. I updated my comment to reflect the fact that I was doing it wrong. I enabled BOD to 2.7 and it works OK too

@MCUdude
Copy link
Owner

MCUdude commented May 15, 2020

I'm curious; I've recently upgraded my old DIY Prusa i3 from 2014 with a brand new 32-bit board. I've also used PlatformIO to build the latest Marlin. But why are you using MightyCore for building for the ATmega1284P? I mean, that's completely fine, but I thought Marlin favored the Sanguino core? Is it to save flash?

@SpenceKonde
Copy link

SpenceKonde commented May 24, 2020

_BV should be defined by the core, it is widely used in existing code. I would characterize this a bug in the core.

@MCUdude
Copy link
Owner

MCUdude commented May 24, 2020

What's weird is that _BV works great in Arduino IDE and in PlatformIO projects. There's something with the Marlin build that's causing this. However, I haven't really looked into it.

I would characterize this a bug in the core.

In the core like in this core?

@SpenceKonde
Copy link

SpenceKonde commented May 24, 2020 via email

@MCUdude
Copy link
Owner

MCUdude commented May 24, 2020

For 8-bit AVR boards you can use both. For 32-bit you can only use PlatformIO. However, I don't see any reason not to use PlatformIO for a project as large as this. PlatformIO/VSCode is much better at handling multiple files.

@SpenceKonde
Copy link

SpenceKonde commented May 24, 2020 via email

@c---
Copy link

c--- commented May 19, 2022

The problem is caused by dependency cycles in MightyCore(?). I don't know where all of them are but at least between wiring_extras.h and Arduino.h which both include each other.

The solution was simply to remove the #include "wiring_extras.h" from Arduino.h. I don't know all the use cases for MightyCore so I don't know if this is a fix for anything other than my version of Marlin. Someone should probably spend some time "flattening" the dependency graph in the code base as this could both prevent errors and possibly speed up compilation.

If you enable verbose compilation in Arduino you can just copy/paste any (failing) gcc command and add the -E option to see what's going on in the preprocessor. This output is difficult to parse though. I don't know if there are maybe tools or options that can show everything in a more organized way.

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

No branches or pull requests

5 participants