Skip to content

Commit

Permalink
Merge pull request #3 from gion86/master
Browse files Browse the repository at this point in the history
Changes to compile on late avr-gcc and Arduino core
  • Loading branch information
andysworkshop committed Mar 17, 2018
2 parents 8f8b6bb + 8a7682b commit e75cdd0
Show file tree
Hide file tree
Showing 20 changed files with 468 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.map
*.elf
*.o
*.hex
*.d
/Debug/
.cproject
.project
.settings/
99 changes: 99 additions & 0 deletions examples/makefile
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"

40 changes: 40 additions & 0 deletions examples/test_bitset.cpp
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();
}
41 changes: 41 additions & 0 deletions examples/test_list.cpp
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();
}
45 changes: 45 additions & 0 deletions examples/test_map.cpp
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();
}
35 changes: 35 additions & 0 deletions examples/test_serial.cpp
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();
}

45 changes: 45 additions & 0 deletions examples/test_set.cpp
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();
}
43 changes: 43 additions & 0 deletions examples/test_stack.cpp
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();
}

Loading

0 comments on commit e75cdd0

Please sign in to comment.