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

Makefile Compilation #485

Open
NicoHood opened this Issue Aug 23, 2017 · 13 comments

Comments

Projects
None yet
3 participants
@NicoHood
Contributor

NicoHood commented Aug 23, 2017

Hi,
I try to compile FastLED based on a DMBS makefile for an atmega32u4 (no Arduino environment).

I got the code compiling with a few tricks, but I have not tested it, and only included the FestLED.h file, nothing more. It would be nice if you could give me some guidiance what is required to use FastLED with a pure makefile. I am willing to write a DMBS makefile (and patches via PR, if required) so others can use that too.

My findings are based on FastLED 3.1.6

in pixelset.h abs() was undefined. I added used:

#include "FastLED.h"
#ifndef ARDUINO
#include "stdlib.h"
#endif

In led_sysdefs_avr.h I had to uncomment:

// Define the register types
//#if defined(ARDUINO) // && ARDUINO < 150
typedef volatile       uint8_t RoReg; /**< Read only 8-bit register (volatile const unsigned int) */
typedef volatile       uint8_t RwReg; /**< Read-Write 8-bit register (volatile unsigned int) */
//#endif

FastLED requires some Arduino functions for pinmapping (as a fallback). I disabled it, and then no pinMode functions (etc.) were not required anymore. Is this the correct way? The pins for an atmega 32u4 should be defined already, I am using the same layout.

CC_FLAGS     =  -D FASTLED_NO_PINMAP

I also upgraded to c++11 (something I found on some website, more compiler flags might be required):

CPP_STANDARD = gnu++11
CPP_FLAGS = -fno-threadsafe-statics

And finally I added some more code to suppress some more errors. I know that I need to reimplement micros() later.

typedef uint8_t byte;
typedef bool boolean;

static uint32_t micros(){
    return 0;
}

Now I started to add other cpp files to my makefile. I made the following changes:

colorutils has no pow() function, so I added

#include <math.h>

noise.cpp missing memset:

#include <string.h>

power_mgt.cpp, dont use digitalwrite. I disabled the whole function calculate_max_brightness_for_power_mW

I end up getting the error:

/tmp/cc8iIq0B.ltrans0.ltrans.o:(.rodata+0x4): undefined reference to `__cxa_pure_virtual'

I fixed those by hints from this thread:
http://www.avrfreaks.net/forum/avr-c-micro-how

h file:

void * operator new(size_t size);
void * operator new[](size_t size);
void operator delete(void * ptr);
void operator delete[](void * ptr);
__extension__ typedef int __guard __attribute__((mode (__DI__)));
extern "C" void __cxa_pure_virtual(void);
extern "C" int __cxa_guard_acquire(__guard *);
extern "C" void __cxa_guard_release (__guard *);
extern "C" void __cxa_guard_abort (__guard *);

cpp file:

#include <stdlib.h>

void *operator new(size_t size) {
  return malloc(size);
}

void *operator new[](size_t size) {
  return malloc(size);
}

void operator delete(void * ptr) {
  free(ptr);
}

void operator delete[](void * ptr) {
  free(ptr);
}

void __cxa_pure_virtual(void) {};
int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
void __cxa_guard_release (__guard *g) {*(char *)g = 1;};
void __cxa_guard_abort (__guard *) {};

After that I had to add functions for millis() and delay().

FastLED/FastLED.cpp:129:5: error: '::delay' has not been declared

Does anyone has more experience on using FastLED with AVRs but via makefile? Any (older) examples maybe?

@NicoHood NicoHood referenced this issue Aug 23, 2017

Merged

Some C++ fixes #17

@focalintent

This comment has been minimized.

Show comment
Hide comment
@focalintent

focalintent Aug 23, 2017

Member

The missinng C++ bits can be gotten by just setting the macro NEED_CXX_BITS - which will include the C++ symbols that fastled needs.

Other things involve making sure include paths are set up properly.

I’ve intentionally not included a makefile in here because they end up being pretty different based on SDK and build environments and platform and such (I have done it multiple times for contract work involving the library) and it isn’t something that I want to deal with supporting - and doing something autoconf based is right out. I think the folks who have done makefile work that they’d be willing to share/talk about are more likely to be in the g+ community than following issues on here.

I’ll leave this open for a bit in case other folks have comments to add.

Member

focalintent commented Aug 23, 2017

The missinng C++ bits can be gotten by just setting the macro NEED_CXX_BITS - which will include the C++ symbols that fastled needs.

Other things involve making sure include paths are set up properly.

I’ve intentionally not included a makefile in here because they end up being pretty different based on SDK and build environments and platform and such (I have done it multiple times for contract work involving the library) and it isn’t something that I want to deal with supporting - and doing something autoconf based is right out. I think the folks who have done makefile work that they’d be willing to share/talk about are more likely to be in the g+ community than following issues on here.

I’ll leave this open for a bit in case other folks have comments to add.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Aug 23, 2017

Contributor

Thanks! This reduced the modifications.

Those are the changes I made directly to fastled. Maybe those can be fixed upstream:
https://github.com/FastLED/FastLED/compare/master...NicoHood:makefile?expand=1

Especially the switch from boolean to bool and byte to uint8_t should be considered. See arduino/Arduino#4673

I've added this special header via -include file.h compiler flag:

#pragma once

#include <stddef.h>
#include <util/delay.h>

static uint32_t micros(){
    return 0;
}

static uint32_t millis(){
    return micros() / 1000UL;
}

static void delay(uint32_t ms){
    _delay_ms(ms);
}

And the extra makefile options:

SRC          = $(TARGET).cpp $(AVR_LIB_PATH)/FastLED/FastLED.cpp $(AVR_LIB_PATH)/FastLED/power_mgt.cpp $(AVR_LIB_PATH)/FastLED/noise.cpp $(AVR_LIB_PATH)/FastLED/wiring.cpp $(AVR_LIB_PATH)/FastLED/lib8tion.cpp $(AVR_LIB_PATH)/FastLED/hsv2rgb.cpp $(AVR_LIB_PATH)/FastLED/colorutils.cpp $(AVR_LIB_PATH)/FastLED/bitswap.cpp
CC_FLAGS     = -I $(AVR_LIB_PATH)/FastLED -include $(AVR_LIB_PATH)/core.h -D FASTLED_NO_PINMAP
CPP_STANDARD = gnu++11
CPP_FLAGS += -fpermissive -fno-exceptions -fno-threadsafe-statics 
#-fno-devirtualize
CPP_FLAGS += -DNEED_CXX_BITS
Contributor

NicoHood commented Aug 23, 2017

Thanks! This reduced the modifications.

Those are the changes I made directly to fastled. Maybe those can be fixed upstream:
https://github.com/FastLED/FastLED/compare/master...NicoHood:makefile?expand=1

Especially the switch from boolean to bool and byte to uint8_t should be considered. See arduino/Arduino#4673

I've added this special header via -include file.h compiler flag:

#pragma once

#include <stddef.h>
#include <util/delay.h>

static uint32_t micros(){
    return 0;
}

static uint32_t millis(){
    return micros() / 1000UL;
}

static void delay(uint32_t ms){
    _delay_ms(ms);
}

And the extra makefile options:

SRC          = $(TARGET).cpp $(AVR_LIB_PATH)/FastLED/FastLED.cpp $(AVR_LIB_PATH)/FastLED/power_mgt.cpp $(AVR_LIB_PATH)/FastLED/noise.cpp $(AVR_LIB_PATH)/FastLED/wiring.cpp $(AVR_LIB_PATH)/FastLED/lib8tion.cpp $(AVR_LIB_PATH)/FastLED/hsv2rgb.cpp $(AVR_LIB_PATH)/FastLED/colorutils.cpp $(AVR_LIB_PATH)/FastLED/bitswap.cpp
CC_FLAGS     = -I $(AVR_LIB_PATH)/FastLED -include $(AVR_LIB_PATH)/core.h -D FASTLED_NO_PINMAP
CPP_STANDARD = gnu++11
CPP_FLAGS += -fpermissive -fno-exceptions -fno-threadsafe-statics 
#-fno-devirtualize
CPP_FLAGS += -DNEED_CXX_BITS
@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Aug 23, 2017

Contributor

Can't you use _delay_ms instead of delay? Maybe calling delay_micros(1000) might make more sense in being more precise.
http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

Contributor

NicoHood commented Aug 23, 2017

Can't you use _delay_ms instead of delay? Maybe calling delay_micros(1000) might make more sense in being more precise.
http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

@focalintent

This comment has been minimized.

Show comment
Hide comment
@focalintent

focalintent Aug 23, 2017

Member

I’m using delay because that’s what’s on the arduino platform and that is what the largest majority of library users by far is using. I’m not going to drop to platform specific code outside of the platforms directory.

Moving to stdint types is an ongoing thing that happens with other work, or rather will be once I get back to actively working on the library.

Member

focalintent commented Aug 23, 2017

I’m using delay because that’s what’s on the arduino platform and that is what the largest majority of library users by far is using. I’m not going to drop to platform specific code outside of the platforms directory.

Moving to stdint types is an ongoing thing that happens with other work, or rather will be once I get back to actively working on the library.

@focalintent

This comment has been minimized.

Show comment
Hide comment
@focalintent

focalintent Aug 23, 2017

Member

Also on arduino delay calls yield which I believe delayMicroseconds does not.

Member

focalintent commented Aug 23, 2017

Also on arduino delay calls yield which I believe delayMicroseconds does not.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Aug 23, 2017

Contributor

If I am not wrong those commits should be easy to merge:
f360030
d73ed0d

About the other things:
Maybe we could add ifndef ARDUINO around those which should get rid of those problems and the code should work for both?

I currently have no led hardware. Would be interesting to test my output. Maybe we could add makefile support with very few fixes.

Contributor

NicoHood commented Aug 23, 2017

If I am not wrong those commits should be easy to merge:
f360030
d73ed0d

About the other things:
Maybe we could add ifndef ARDUINO around those which should get rid of those problems and the code should work for both?

I currently have no led hardware. Would be interesting to test my output. Maybe we could add makefile support with very few fixes.

@focalintent

This comment has been minimized.

Show comment
Hide comment
@focalintent

focalintent Aug 23, 2017

Member

The type updates I’ll take — the tossing ifdef stuff around is not something I’m willing to take blindly without testing myself, especially since some of the things are things that will need local replacement, the compiler errors will be useful for that for folks building outside the arduino environment.

And again - while I’ve done work to make building outside of arduino easier to do it is not something I want to claim is supported nor is it something that I want to actively support.

Member

focalintent commented Aug 23, 2017

The type updates I’ll take — the tossing ifdef stuff around is not something I’m willing to take blindly without testing myself, especially since some of the things are things that will need local replacement, the compiler errors will be useful for that for folks building outside the arduino environment.

And again - while I’ve done work to make building outside of arduino easier to do it is not something I want to claim is supported nor is it something that I want to actively support.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Aug 23, 2017

Contributor

Thanks! Sure, I totally understand. I also need to test this myself. It might take some time until I get my hands on real led hardware. I will report back, when I got more updates :)

Contributor

NicoHood commented Aug 23, 2017

Thanks! Sure, I totally understand. I also need to test this myself. It might take some time until I get my hands on real led hardware. I will report back, when I got more updates :)

@ladislas

This comment has been minimized.

Show comment
Hide comment
@ladislas

ladislas Aug 31, 2017

Hi there!
First thanks a lot @focalintent for the amazing work! And thank you @NicoHood for all the information you provided.

I was able to compile FastLED using the Arduino-Makefile.

Furthermore, I did not need to set -DNEED_CXX_BITS in my Makefile or in the code. Is that normal? Setting it will cause an error and complain that extern "C" void __cxa_pure_virtual (void) {}
is defined multiple times.

ladislas commented Aug 31, 2017

Hi there!
First thanks a lot @focalintent for the amazing work! And thank you @NicoHood for all the information you provided.

I was able to compile FastLED using the Arduino-Makefile.

Furthermore, I did not need to set -DNEED_CXX_BITS in my Makefile or in the code. Is that normal? Setting it will cause an error and complain that extern "C" void __cxa_pure_virtual (void) {}
is defined multiple times.

@focalintent

This comment has been minimized.

Show comment
Hide comment
@focalintent

focalintent Aug 31, 2017

Member

It depends on the platform and target, which is why it is something that isn’t on all the time by default.

Member

focalintent commented Aug 31, 2017

It depends on the platform and target, which is why it is something that isn’t on all the time by default.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Aug 31, 2017

Contributor

@ladislas I think Arduino-makefile is just another tools similar to arduino-builder. You do not need to use the IDE (GUI), and can use a commandline tool instead. However this does not get rid of the whole Arduino core (which my aim is).

And thatswhy the Arduino code gets pulled in, you have the function defined multiple times and no real improvement from my point of view. In your case I'd rather directly use arduino-builder.

@focalintent I got hardware (NEOPIXEL) to test now. I will prepare a PR once I got all fixes applied. I will try to make it generally work, so nothing else breaks. The changes should be very small.

Contributor

NicoHood commented Aug 31, 2017

@ladislas I think Arduino-makefile is just another tools similar to arduino-builder. You do not need to use the IDE (GUI), and can use a commandline tool instead. However this does not get rid of the whole Arduino core (which my aim is).

And thatswhy the Arduino code gets pulled in, you have the function defined multiple times and no real improvement from my point of view. In your case I'd rather directly use arduino-builder.

@focalintent I got hardware (NEOPIXEL) to test now. I will prepare a PR once I got all fixes applied. I will try to make it generally work, so nothing else breaks. The changes should be very small.

@ladislas

This comment has been minimized.

Show comment
Hide comment
@ladislas

ladislas Sep 1, 2017

@NicoHood do you have a repo with your project somewhere? I'd love to take a look and maybe help.

I've just managed to make FastLED Neopixel work with ChRT (ChibiOS/RT for Arduino).

I'm waiting for my APA102 to arrive to do a comparison.

ladislas commented Sep 1, 2017

@NicoHood do you have a repo with your project somewhere? I'd love to take a look and maybe help.

I've just managed to make FastLED Neopixel work with ChRT (ChibiOS/RT for Arduino).

I'm waiting for my APA102 to arrive to do a comparison.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Sep 1, 2017

Contributor

Oh yes, I did not mention yet:
https://github.com/NicoHood/avr

The makefile works. Neopixel Leds are working (tested!) and the other chipsets seem to compile. If you want to reproduce it you must make sure that you use my fastled fork, as well as the dmbs fork as described in the readme. I hope those fixes get applied soon :) I will prepare a PR for FastLED.

Contributor

NicoHood commented Sep 1, 2017

Oh yes, I did not mention yet:
https://github.com/NicoHood/avr

The makefile works. Neopixel Leds are working (tested!) and the other chipsets seem to compile. If you want to reproduce it you must make sure that you use my fastled fork, as well as the dmbs fork as described in the readme. I hope those fixes get applied soon :) I will prepare a PR for FastLED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment