-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from gion86/master
Changes to compile on late avr-gcc and Arduino core
- Loading branch information
Showing
20 changed files
with
468 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.map | ||
*.elf | ||
*.o | ||
*.hex | ||
*.d | ||
/Debug/ | ||
.cproject | ||
.project | ||
.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
CXX=avr-g++ | ||
|
||
ARDUINO_DIR=/opt/arduino | ||
ARDUINO_CORE_DIR=/home/gionata/workspace_Arduino/Core/ArduinoCore | ||
PROJECT_DIR=.. | ||
|
||
# avr tools path | ||
AVR_OBJCOPY=avr-objcopy | ||
AVR_SIZE=avr-size | ||
AVRDUDE=$(ARDUINO_DIR)/hardware/tools/avrdude | ||
|
||
|
||
# CPU type and speed | ||
MCU=atmega328p | ||
CPU_SPEED=16000000UL | ||
|
||
# Arduino USB port for Linux | ||
PORT=/dev/ttyACM0 | ||
|
||
|
||
# Include (dependencies: avr-stl, arduino) | ||
INCLUDE=-I../include -I$(ARDUINO_CORE_DIR) | ||
|
||
# Libraries (dependencies: unocore) | ||
LIBS=-L$(ARDUINO_CORE_DIR)/Arduino_Uno -lunocore | ||
|
||
# Executable name | ||
TARGET=testSTL | ||
|
||
CFLAGS=-Wall -Wno-unused-local-typedefs -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields\ | ||
-fno-exceptions -ffunction-sections -fdata-sections -fno-use-cxa-atexit -mmcu=$(MCU) -DF_CPU=$(CPU_SPEED) \ | ||
-MMD -MP -MF"$(OBJ).d" -MT"$(OBJ).d" | ||
|
||
CLINKFLAGS=-Wl,-Map,$(TARGET).map,--cref -Wl,-gc-sections -mmcu=$(MCU) | ||
|
||
vector: OBJ=test_vector | ||
vector: clean build sizedummy upload | ||
|
||
string: OBJ=test_string | ||
string: clean build sizedummy upload | ||
|
||
serial: OBJ=test_serial | ||
serial: clean build sizedummy upload | ||
|
||
stack: OBJ=test_stack | ||
stack: clean build sizedummy upload | ||
|
||
bitset: OBJ=test_bitset | ||
bitset: clean build sizedummy upload | ||
|
||
list: OBJ=test_list | ||
list: clean build sizedummy upload | ||
|
||
set: OBJ=test_set | ||
set: clean build sizedummy upload | ||
|
||
map: OBJ=test_map | ||
map: clean build sizedummy upload | ||
|
||
build: $(TARGET).hex | ||
|
||
$(TARGET).hex: $(TARGET).elf | ||
@echo 'Create Flash image (ihex format)' | ||
$(AVR_OBJCOPY) -R .eeprom -O ihex $< $@ | ||
@echo 'Finished building target: $@' | ||
@echo ' ' | ||
|
||
$(TARGET).elf: | ||
make -e $(OBJ).o | ||
@echo 'Building target: $@' | ||
@echo 'Invoking: AVR C++ Linker' | ||
$(CXX) $(CLINKFLAGS) $(INCLUDE) $(OBJ).o -o $@ $(LIBS) | ||
@echo 'Finished building target: $@' | ||
@echo ' ' | ||
|
||
%.o: %.cpp | ||
$(CXX) $< $(CFLAGS) $(INCLUDE) -c -o $@ | ||
|
||
upload: | ||
@echo 'Invoking: AVRDude' | ||
$(AVRDUDE) -C $(AVRDUDE).conf -pm328p -carduino -P$(PORT) -b115200 -Uflash:w:$(TARGET).hex:a | ||
@echo 'Finished building: $@' | ||
@echo ' ' | ||
|
||
sizedummy: $(TARGET).elf | ||
@echo 'Invoking: Print Size' | ||
$(AVR_SIZE) --format=avr --mcu=$(MCU) $(TARGET).elf | ||
@echo 'Finished building: $@' | ||
@echo ' ' | ||
|
||
clean: | ||
@echo -n Cleaning ... | ||
$(shell rm $(TARGET).elf 2> /dev/null) | ||
$(shell rm $(TARGET).hex 2> /dev/null) | ||
$(shell rm $(TARGET).map 2> /dev/null) | ||
$(shell rm *.o 2> /dev/null) | ||
$(shell rm *.d 2> /dev/null) | ||
@echo " done" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <Arduino.h> | ||
#include <pnew.cpp> | ||
|
||
#include <HardwareSerial.h> | ||
#include <serstream> | ||
#include <bitset> | ||
|
||
/* | ||
* Test std::bitset | ||
*/ | ||
|
||
struct TestBitset { | ||
|
||
static void RunTest() { | ||
|
||
std::ohserialstream serial(Serial); | ||
|
||
std::bitset<64> mybits(0); | ||
|
||
// set bits 63 and 31 using | ||
// different methods | ||
|
||
mybits[63]=1; | ||
mybits|=0x80000000; | ||
|
||
serial << mybits << std::endl; | ||
} | ||
|
||
}; | ||
|
||
TestBitset b; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
delay(1000); | ||
b.RunTest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <Arduino.h> | ||
#include <pnew.cpp> | ||
|
||
#include <HardwareSerial.h> | ||
#include <serstream> | ||
#include <list> | ||
|
||
/* | ||
* Test std::list | ||
*/ | ||
|
||
struct TestList { | ||
|
||
static void RunTest() { | ||
|
||
std::ohserialstream serial(Serial); | ||
std::list<int> lst; | ||
std::list<int>::const_iterator it; | ||
int i; | ||
|
||
for(i=0;i<50;i++) | ||
lst.push_back(i); | ||
|
||
for(it=lst.begin();it!=lst.end();it++) | ||
serial << *it << ' '; | ||
|
||
serial << std::endl; | ||
} | ||
|
||
}; | ||
|
||
TestList l; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
delay(1000); | ||
l.RunTest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <Arduino.h> | ||
#include <pnew.cpp> | ||
|
||
#include <serstream> | ||
#include <map> | ||
|
||
|
||
/* | ||
* Test std::map | ||
*/ | ||
|
||
struct TestMap { | ||
|
||
static void RunTest() { | ||
|
||
std::ohserialstream serial(Serial); | ||
|
||
std::map<int,const char *> days; | ||
int i; | ||
|
||
days[1]="Monday"; | ||
days[2]="Tuesday"; | ||
days[3]="Wednesday"; | ||
days[4]="Thursday"; | ||
days[5]="Friday"; | ||
days[6]="Saturday"; | ||
days[7]="Sunday"; | ||
|
||
for(i=1;i<=7;i++) | ||
serial << days[i] << std::endl; | ||
|
||
serial << std::endl; | ||
} | ||
}; | ||
|
||
TestMap m; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
delay(1000); | ||
m.RunTest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <Arduino.h> | ||
#include <pnew.cpp> | ||
|
||
#include <HardwareSerial.h> | ||
#include <serstream> | ||
#include <iomanip> // for setprecision() | ||
#include <sstream> | ||
|
||
/* | ||
* Run some tests on the hardware serial stream | ||
*/ | ||
|
||
struct TestSerial { | ||
|
||
static void RunTest() { | ||
|
||
std::ohserialstream serial(Serial); | ||
|
||
serial << "Hello world" << std::endl | ||
<< "Floating point: " | ||
<< std::setprecision(3) << 3.14159 << std::endl; | ||
} | ||
}; | ||
|
||
TestSerial s; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
delay(1000); | ||
s.RunTest(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <Arduino.h> | ||
#include <pnew.cpp> | ||
|
||
#include <serstream> | ||
#include <set> | ||
|
||
/* | ||
* Test std::set | ||
*/ | ||
|
||
struct TestSet { | ||
|
||
static void RunTest() { | ||
|
||
std::ohserialstream serial(Serial); | ||
|
||
std::set<int> s1,s2; | ||
int i; | ||
|
||
for(i=0;i<10;i++) | ||
s1.insert(i); | ||
|
||
for(i=5;i<15;i++) | ||
s2.insert(i); | ||
|
||
std::set_intersection( | ||
s1.begin(),s1.end(), | ||
s2.begin(),s2.end(), | ||
std::ostream_iterator<int>(serial," ")); | ||
|
||
serial << std::endl; | ||
} | ||
}; | ||
|
||
|
||
TestSet s; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
delay(1000); | ||
s.RunTest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <Arduino.h> | ||
#include <pnew.cpp> | ||
|
||
#include <HardwareSerial.h> | ||
#include <serstream> | ||
#include <stack> | ||
#include <vector> | ||
|
||
/* | ||
* Test std::stack | ||
*/ | ||
|
||
struct TestStack { | ||
|
||
static void RunTest() { | ||
|
||
std::ohserialstream serial(Serial); | ||
std::stack<int,std::vector<int> > stk; | ||
int i; | ||
|
||
for(i=0;i<20;i++) | ||
stk.push(i); | ||
|
||
while(!stk.empty()) { | ||
serial << stk.top() << ' '; | ||
stk.pop(); | ||
} | ||
|
||
serial << std::endl; | ||
} | ||
}; | ||
|
||
TestStack s; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
delay(1000); | ||
s.RunTest(); | ||
} | ||
|
Oops, something went wrong.