Skip to content

Commit

Permalink
[AVR port] update READMEs and add Arduino libraries definitions (spi,…
Browse files Browse the repository at this point in the history
… i2c, …)
  • Loading branch information
Mikael BRIDAY committed Nov 21, 2017
1 parent c43af81 commit f8d6e82
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 39 deletions.
71 changes: 61 additions & 10 deletions examples/avr/README.md
@@ -1,31 +1,82 @@
#Trampoline examples for AVR8 Targets

This directory shows some examples for 8 bits AVR targets, including some Arduino boards.

For all these examples, the Gcc cross-compiler is required.

# Installation
##avr-gcc cross-compiler
**Linux** (Debian/Ubuntu) -> `sudo apt-get install avr-libc gcc-avr avrdude`

**MacOSX** -> AVR CrossPack ([http://www.obdev.at/products/crosspack/download.html]())
**MacOSX** -> [AVR CrossPack](http://www.obdev.at/products/crosspack/download.html)

**Windows** -> Winavr (integrated in Atmel Studio, or [here](http://winavr.sourceforge.net)).

## Arduino libraries installation

Arduino libraries should be installed separately as a git submodule.

**Windows** -> Winavr (integrated in Atmel Studio, or [http://winavr.sourceforge.net]())
in the trampoline installation path:

```sh
git submodule init
git submodule update machines/avr/arduino
```

It gets the trampoline patched version of ArduinoCore-avr from [GitHub](https://github.com/TrampolineRTOS/ArduinoCore-avr.git).

##Compilation
Examples may be built either from the command line (a Makefile is generated from the goil compiler) or with Atmel Studio (Windows only).
The build script is written in Python (2.7 and 3.x) and works for Windows, Mac and Linux. The build script (make.py) is generated from goil the first time goil is called.

See examples, for the correct first call to goil (in runGoil.bat for Windows).

## flash
The avrdude port should be set as en environmemnt variable. Then, the build script can call avrdude to flash the Arduino:

example (`/dev/tty.usbmodem1421` for Mac, but may be `/dev/ttyUSB0` with Linux…).

```sh
export AVRDUDE_PORT="/dev/tty.usbmodem1421"
./make.py flash
```

# Arduino Libraries

## Installed libraries

The avr arduino installation is set in `machines/avr/arduino`.
Default Libraries are:

* advancedIO : tone, noTone, pulseIn, …
* serial : Serial object
* spi
* i2c (refered as Wire in Arduino…).
* eeprom
* softwareSerial

To insert a library in your project, add in your .oil file (in section `CPU->OS->BUILD`):

```
LIBRARY = serial;
```
You have an example in the `serial/` example (both Arduino Uno and Mega).

### Command line (with Makefile)
The definition is in file `goil/templates/config/avr/arduino/config.oil`

This is the most simple approach. The Makefile is generated by `goil` (`goil` is the compiler that generates data structures of the application from the an `.oil` description).
The `Goil` compiler should have been previously built.
## adding your own libraries
You may need to add your own libraries, it can be added in the file `goil/templates/config/avr/arduino/config.oil`. For the SPI library for instance:

In the different sub-directories, the command line compilation is detailed, including the flash process.
```
LIBRARY spi {
PATH = "avr/arduino/libraries/SPI/src"; //path from machine/
CPPFILE = "SPI.cpp"; //list of files (CPPFILE, CFILE, ASFILE)
};
```

### Atmel Studio
# Using Atmel Studio
The Atmel Studio project allows to insert breakpoints and interactive debug. The generation of a project is not automatic, and should be based on the source files that are compiled in the classic `Makefile` based approach…

* create a new C++ project (ATMega328P device for Arduino Uno)
* add all the files compiled using the `make` command line (see section before)
* add all the files compiled using the `./make.py -j 1` command line.
* update project properties (`projet->toolchain->C compiler->directories`) with the directories defined in the compilation rules of the 'make' command line (directories starting with -I...)
* copy and paste these directories in `C++ compiler-> directories` and `assembler/General`
* add the symbols used in the 'make' command line (starting with `-D`...) in the `symbols` part (without the `-D`)
Expand Down
28 changes: 20 additions & 8 deletions examples/avr/arduinoMega2560/README.md
@@ -1,17 +1,18 @@
AVR sample projects Arduino Mega 2560 boards (ATMega2560)
see the README.md in the parent folder for general information.

The main difference with the core of ATMega328p (Arduino Uno) is that the program counter uses 3 bytes (2 only on the ATMega328p).

***Be sure that Arduino related libraries are installed: see [README.md](../README.md) in parent folder***

#first run
In the first run, the `goil` compiler will generate:

* a python build script `make.py` (to build everything)
* C data structures related to the `.oil` description.
* C data structures related to the `.oil` description (in directory with the name of the .oil file, but with no extension)

If `file.oil` is the main `oil` file, and `TRAMPOLINE_ROOT` is the path to the root of trampoline:

`$goil --target=avr/arduino/mega --templates=$TRAMPOLINE_ROOT/goil/templates/ file.oil`
`$goil --target=avr/arduino/uno --templates=$TRAMPOLINE_ROOT/goil/templates/ file.oil`

#Build
The commands builds the binary file (both the `.elf` and `.hex` files).
Expand All @@ -20,17 +21,28 @@ The commands builds the binary file (both the `.elf` and `.hex` files).

`goil` will now be called directly from the python build script if the .oil file is updated, it should not be called directly again.

in case of problem, you may need to run `./make.py -j 1` to have the full compilation line.

#flash

Use the `avrdude` utility, that comes with Arduino.
The avrdude port should be set as en environmemnt variable. Then, the build script can call avrdude to flash the Arduino:

example (`/dev/tty.usbmodem1421` for Mac, but may be `/dev/ttyUSB0` with Linux…).

```sh
export AVRDUDE_PORT="/dev/tty.usbmodem1421"
./make.py flash
```

or using `avrdude` directly:

```sh
avrdude -c wiring -p m2560 -D -P /dev/ttyACM0 -U flash:w:trampuinoSerial.hex
$avrdude -c arduino -p m2560 -P /dev/tty.usbmodem1421 -U flash:w:AVRTrampolineBin.hex
```

where:
In this example:

* `-p m2560 ` is for the ATMega2560p
* `-c wiring ` is the (ISP programmer on the Arduino Mega) on the USB interface.
* `-p m2560` is for the ATMega2560
* `-c wiring` is the (ISP programmer on the Arduino Mega) on the USB interface.
Type 'avrdude -c toto' to get the full programer list
* `-P` the device name used in the Arduino User Interface (COMmunication port)
3 changes: 0 additions & 3 deletions examples/avr/arduinoMega2560/blink/blink.oil
Expand Up @@ -10,9 +10,6 @@ OIL_VERSION = "2.5" : "test" ;
CPU test {
OS config {
STATUS = STANDARD;
ARDUINO = TRUE {
SERIAL = TRUE; //use the serial interface
};
BUILD = TRUE {
TRAMPOLINE_BASE_PATH = "../../../..";
APP_NAME = "trampuinoBlink";
Expand Down
6 changes: 3 additions & 3 deletions examples/avr/arduinoMega2560/extInterrupt/extInterrupt.oil
Expand Up @@ -10,9 +10,6 @@ OIL_VERSION = "2.5" : "test" ;
CPU test {
OS config {
STATUS = STANDARD;
ARDUINO = TRUE {
SERIAL = TRUE; //use the serial interface
};
BUILD = TRUE {
TRAMPOLINE_BASE_PATH = "../../../..";
APP_NAME = "trampuinoIT";
Expand All @@ -23,6 +20,9 @@ CPU test {
ASSEMBLER = "avr-gcc";
COPIER = "avr-objcopy";
SYSTEM = PYTHON;

LIBRARY=serial;

};
SYSTEM_CALL = TRUE;
};
Expand Down
6 changes: 3 additions & 3 deletions examples/avr/arduinoMega2560/serial/serial.oil
Expand Up @@ -10,9 +10,6 @@ OIL_VERSION = "2.5" : "test" ;
CPU test {
OS config {
STATUS = STANDARD;
ARDUINO = TRUE {
SERIAL = TRUE; //use the serial interface
};
BUILD = TRUE {
TRAMPOLINE_BASE_PATH = "../../../..";
APP_NAME = "trampuinoSerial";
Expand All @@ -23,6 +20,9 @@ CPU test {
ASSEMBLER = "avr-gcc";
COPIER = "avr-objcopy";
SYSTEM = PYTHON;

LIBRARY=serial;

};
SYSTEM_CALL = TRUE;
};
Expand Down
23 changes: 15 additions & 8 deletions examples/avr/arduinoUno/README.md
@@ -1,12 +1,13 @@
AVR sample projects Arduino Uno boards (ATMega328P)
see the README.md in the parent folder for general information.

***Be sure that Arduino related libraries are installed: see [README.md](../README.md) in parent folder***


#first run
In the first run, the `goil` compiler will generate:

* a python build script `make.py` (to build everything)
* C data structures related to the `.oil` description.
* C data structures related to the `.oil` description (in directory with the name of the .oil file, but with no extension)

If `file.oil` is the main `oil` file, and `TRAMPOLINE_ROOT` is the path to the root of trampoline:

Expand All @@ -20,21 +21,27 @@ The commands builds the binary file (both the `.elf` and `.hex` files).

`goil` will now be called directly from the python build script if the .oil file is updated, it should not be called directly again.

#flash
in case of problem, you may need to run `./make.py -j 1` to have the full compilation line.

***DEPRECATED***
#flash

The serial device name should be defined in the oil file (`CPU -> OS -> ARDUINO section`). For example:
The avrdude port should be set as en environmemnt variable. Then, the build script can call avrdude to flash the Arduino:

` PORT = "/dev/tty.usbmodem1411";`
example (`/dev/tty.usbmodem1421` for Mac, but may be `/dev/ttyUSB0` with Linux…).

$make -s flash
```sh
export AVRDUDE_PORT="/dev/tty.usbmodem1421"
./make.py flash
```

or using `avrdude` directly:

`$avrdude -c arduino -p m328p -P /dev/tty.usbmodem1421 -U flash:w:AVRTrampolineBin.hex`
```sh
$avrdude -c arduino -p m328p -P /dev/tty.usbmodem1421 -U flash:w:AVRTrampolineBin.hex
```

In this example:

* `-p m328p` is for the ATMega328p
* `-c avrispmkII` is the (ISP programmer on the Arduino Uno) on the USB interface.
Type 'avrdude -c toto' to get the full programer list
Expand Down
22 changes: 21 additions & 1 deletion goil/templates/config/avr/arduino/config.oil
Expand Up @@ -29,7 +29,7 @@ CPU avrArduino {
};

LIBRARY serial {
PATH = "avr/arduino/cores/arduino";
PATH = "avr/arduino/cores/arduino";
CPPFILE = "Print.cpp"; //Stream inherits from Print
CPPFILE = "Stream.cpp"; //HardwareSerial inherits from Stream
CPPFILE = "HardwareSerial0.cpp";
Expand All @@ -39,6 +39,26 @@ CPU avrArduino {
CPPFILE = "HardwareSerial.cpp";
};

LIBRARY spi {
PATH = "avr/arduino/libraries/SPI/src";
CPPFILE = "SPI.cpp";
};

LIBRARY i2c {
PATH = "avr/arduino/libraries/Wire/src";
CPPFILE = "Wire.cpp";
CFILE = "utility/twi.c";
};

LIBRARY eeprom {
PATH = "avr/arduino/libraries/EEPROM/src"; //only .h files.
};

LIBRARY softwareSerial {
PATH = "avr/arduino/libraries/SoftwareSerial/src";
CPPFILE = "SoftwareSerial.cpp";
};

// not used (at this date):
// IPAddress.cpp
// PluggableUSB.cpp
Expand Down
8 changes: 5 additions & 3 deletions goil/templates/config/avr/arduino/mega/config.oil
@@ -1,7 +1,7 @@
CPU avrArduino {

PLATFORM_FILES arduinoMega {
PATH = "avr/arduino/hardware/variants/mega";
PATH = "avr/arduino/variants/mega";
};

BUILDOPTIONS buildOptionsForArduino {
Expand All @@ -27,8 +27,10 @@ CPU arduino {
COMMAND flash {
MESSAGE = "Flashing";
COMMAND = "avrdude";
INPUT = TARGET { EXT = ""; };
PREOPTION = "-c stk500v2 -p m2560 -P/dev/ttyUSB0 -U flash:w:";
INPUT = TARGET { EXT = ".hex"; };
PREOPTION = "-c wiring -p m2560";
PREOPT = ENVAR { NAME = "AVRDUDE_PORT"; OPT = "-P"; };
PREOPT = LITERAL { VALUE = "flash:w:"; OPT = "-U"; };
};
};
};

0 comments on commit f8d6e82

Please sign in to comment.