https://wiki.dlang.org/api.php?action=feedcontributions&user=ErnyTech&feedformat=atomD Wiki - User contributions [en]2024-03-29T04:47:58ZUser contributionsMediaWiki 1.31.2https://wiki.dlang.org/?title=D_on_AVR&diff=9734D on AVR2019-12-20T22:55:28Z<p>ErnyTech: Fix build</p>
<hr />
<div>AVR is a family of 8-bit RISC microcontrollers, are widely used for embedded applications where a simple, inexpensive and low-powered microcontroller is needed.<br />
<br />
In the FOSS community, AVR-GCC has always been used as a toolchian for AVR which includes all the tools needed to compile a C source, copy the object files into a hex file and write it to the ROM of the microcontroller.<br />
<br />
The merge of the AVR backend for LLVM (https://github.com/avr-llvm) in the upstream LLVM project has given rise to the porting of modern languages to develop on AVR, such as Rust (https://github.com/avr-rust), Go (https://github.com/tinygo-org/tinygo) and Swift (http://swiftforarduino.com/).<br />
<br />
D has its frontend for LLVM so you can use it to program on AVR.<br />
<br />
== Get LLVM source ==<br />
<br />
<syntaxhighlight lang="shell"><br />
$ wget https://releases.llvm.org/9.0.0/llvm-9.0.0.src.tar.xz<br />
$ tar xf llvm-9.0.0.src.tar.xz<br />
</syntaxhighlight><br />
<br />
== Build and install LLVM with AVR target ==<br />
<syntaxhighlight lang="shell"><br />
$ cd llvm-9.0.0.src<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR \<br />
-DLLVM_TARGETS_TO_BUILD= -DLLVM_BINUTILS_INCDIR=/usr/include \<br />
-D CMAKE_INSTALL_PREFIX=/opt/llvm-avr<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Get LDC source ==<br />
<syntaxhighlight lang="shell"><br />
$ git clone https://github.com/ldc-developers/ldc -b v1.18.0<br />
</syntaxhighlight><br />
<br />
== Build and install LDC with LLVM AVR ==<br />
<syntaxhighlight lang="shell"><br />
$ cd ldc<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/opt/ldc-avr -DLLVM_ROOT_DIR=/opt/llvm-avr<br />
$ ninja<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Test D with AVR ==<br />
<syntaxhighlight lang="d"><br />
enum AVR_ARCH = 5; // AVR architecture of your MCU<br />
<br />
static if (AVR_ARCH >= 100) {<br />
enum SFR_OFFSET = 0x00;<br />
} else {<br />
enum SFR_OFFSET = 0x20;<br />
}<br />
<br />
enum ubyte* MMIO_BYTE(ubyte memAddr) = cast(ubyte*) memAddr;<br />
enum ubyte* SFR_IO8(ubyte ioAddr) = MMIO_BYTE!(ioAddr + SFR_OFFSET);<br />
<br />
enum ubyte* PINB = SFR_IO8!(0x03);<br />
enum ubyte* DDRB = SFR_IO8!(0x04);<br />
enum ubyte* PORTB = SFR_IO8!(0x05);<br />
<br />
extern(C) void main() {<br />
import core.bitop;<br />
<br />
volatileStore(DDRB, 0xFF); // Set all PORT B to output<br />
<br />
while (true) {<br />
volatileStore(PORTB, 0xFF); // Set all PORT B to high<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
This simple code will set all I/O PORTS B to high, on Arduino UNO for example the PORT B is connected to the digital pins from 8 to 13 and this code will cause the internal LED to light up as it is connected to PIN 13.<br />
<br />
== How to build and run the test code ==<br />
First of all to generate an object file for AVR, convert it to HEX and then flash it into the flash memory of the MCU is advisable to use AVR GCC as C toolchain, linker, objcopy (to convert to hex) and avrdude (to load it into flash).<br />
<br />
Therefore it is necessary to install AVR-GCC, to do this consult the documentation of your operating system.<br />
<br />
The following commands need AVR-GCC installed and in a directory present in the PATH environment variable and are meant to be used with Arduino UNO, minor modifications are needed for other AVR MCUs<br />
<br />
<syntaxhighlight lang="shell"><br />
$ /opt/ldc-avr/bin/ldc2 -betterC -Oz -mtriple=avr -mcpu=atmega328p -Xcc=-mmcu=atmega328p -gcc=avr-gcc test.d<br />
$ avr-objcopy -O ihex -R .eeprom test test.hex // -R .eeprom is used to avoid overwriting the EEPROM, since is used to store data<br />
$ avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:test.hex // Write the hex in the ROM and reset MCU<br />
</syntaxhighlight><br />
<br />
== Current projects for use D on AVR ==<br />
* AVRD - https://github.com/WebFreak001/avrd<br />
<br />
== Info about the GNU/LINUX distros ==<br />
* ArchLinux, The llvm package in the official repo is already builded with the AVR flag (https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/llvm#n40), therefore the ArchLinux LDC package also supports the AVR target out-of-the-box</div>ErnyTechhttps://wiki.dlang.org/?title=D_on_AVR&diff=9733D on AVR2019-12-20T22:54:45Z<p>ErnyTech: uppercase ldc</p>
<hr />
<div>AVR is a family of 8-bit RISC microcontrollers, are widely used for embedded applications where a simple, inexpensive and low-powered microcontroller is needed.<br />
<br />
In the FOSS community, AVR-GCC has always been used as a toolchian for AVR which includes all the tools needed to compile a C source, copy the object files into a hex file and write it to the ROM of the microcontroller.<br />
<br />
The merge of the AVR backend for LLVM (https://github.com/avr-llvm) in the upstream LLVM project has given rise to the porting of modern languages to develop on AVR, such as Rust (https://github.com/avr-rust), Go (https://github.com/tinygo-org/tinygo) and Swift (http://swiftforarduino.com/).<br />
<br />
D has its frontend for LLVM so you can use it to program on AVR.<br />
<br />
== Get LLVM source ==<br />
<br />
<syntaxhighlight lang="shell"><br />
$ wget https://releases.llvm.org/9.0.0/llvm-9.0.0.src.tar.xz<br />
$ tar xf llvm-9.0.0.src.tar.xz<br />
</syntaxhighlight><br />
<br />
== Build and install LLVM with AVR target ==<br />
<syntaxhighlight lang="shell"><br />
$ cd llvm-9.0.0.src<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR \<br />
-DLLVM_TARGETS_TO_BUILD= -DLLVM_BINUTILS_INCDIR=/usr/include \<br />
-D CMAKE_INSTALL_PREFIX=/opt/llvm-avr<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Get LDC source ==<br />
<syntaxhighlight lang="shell"><br />
$ git clone https://github.com/ldc-developers/ldc -b v1.18.0<br />
</syntaxhighlight><br />
<br />
== Build and install LDC with LLVM AVR ==<br />
<syntaxhighlight lang="shell"><br />
$ cd ldc<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/opt/ldc-avr -DLLVM_ROOT_DIR=/opt/llvm-avr<br />
$ ninja ldc2<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Test D with AVR ==<br />
<syntaxhighlight lang="d"><br />
enum AVR_ARCH = 5; // AVR architecture of your MCU<br />
<br />
static if (AVR_ARCH >= 100) {<br />
enum SFR_OFFSET = 0x00;<br />
} else {<br />
enum SFR_OFFSET = 0x20;<br />
}<br />
<br />
enum ubyte* MMIO_BYTE(ubyte memAddr) = cast(ubyte*) memAddr;<br />
enum ubyte* SFR_IO8(ubyte ioAddr) = MMIO_BYTE!(ioAddr + SFR_OFFSET);<br />
<br />
enum ubyte* PINB = SFR_IO8!(0x03);<br />
enum ubyte* DDRB = SFR_IO8!(0x04);<br />
enum ubyte* PORTB = SFR_IO8!(0x05);<br />
<br />
extern(C) void main() {<br />
import core.bitop;<br />
<br />
volatileStore(DDRB, 0xFF); // Set all PORT B to output<br />
<br />
while (true) {<br />
volatileStore(PORTB, 0xFF); // Set all PORT B to high<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
This simple code will set all I/O PORTS B to high, on Arduino UNO for example the PORT B is connected to the digital pins from 8 to 13 and this code will cause the internal LED to light up as it is connected to PIN 13.<br />
<br />
== How to build and run the test code ==<br />
First of all to generate an object file for AVR, convert it to HEX and then flash it into the flash memory of the MCU is advisable to use AVR GCC as C toolchain, linker, objcopy (to convert to hex) and avrdude (to load it into flash).<br />
<br />
Therefore it is necessary to install AVR-GCC, to do this consult the documentation of your operating system.<br />
<br />
The following commands need AVR-GCC installed and in a directory present in the PATH environment variable and are meant to be used with Arduino UNO, minor modifications are needed for other AVR MCUs<br />
<br />
<syntaxhighlight lang="shell"><br />
$ /opt/ldc-avr/bin/ldc2 -betterC -Oz -mtriple=avr -mcpu=atmega328p -Xcc=-mmcu=atmega328p -gcc=avr-gcc test.d<br />
$ avr-objcopy -O ihex -R .eeprom test test.hex // -R .eeprom is used to avoid overwriting the EEPROM, since is used to store data<br />
$ avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:test.hex // Write the hex in the ROM and reset MCU<br />
</syntaxhighlight><br />
<br />
== Current projects for use D on AVR ==<br />
* AVRD - https://github.com/WebFreak001/avrd<br />
<br />
== Info about the GNU/LINUX distros ==<br />
* ArchLinux, The llvm package in the official repo is already builded with the AVR flag (https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/llvm#n40), therefore the ArchLinux LDC package also supports the AVR target out-of-the-box</div>ErnyTechhttps://wiki.dlang.org/?title=D_on_AVR&diff=9732D on AVR2019-12-20T22:52:30Z<p>ErnyTech: Fix</p>
<hr />
<div>AVR is a family of 8-bit RISC microcontrollers, are widely used for embedded applications where a simple, inexpensive and low-powered microcontroller is needed.<br />
<br />
In the FOSS community, AVR-GCC has always been used as a toolchian for AVR which includes all the tools needed to compile a C source, copy the object files into a hex file and write it to the ROM of the microcontroller.<br />
<br />
The merge of the AVR backend for LLVM (https://github.com/avr-llvm) in the upstream LLVM project has given rise to the porting of modern languages to develop on AVR, such as Rust (https://github.com/avr-rust), Go (https://github.com/tinygo-org/tinygo) and Swift (http://swiftforarduino.com/).<br />
<br />
D has its frontend for LLVM so you can use it to program on AVR.<br />
<br />
== Get LLVM source ==<br />
<br />
<syntaxhighlight lang="shell"><br />
$ wget https://releases.llvm.org/9.0.0/llvm-9.0.0.src.tar.xz<br />
$ tar xf llvm-9.0.0.src.tar.xz<br />
</syntaxhighlight><br />
<br />
== Build and install LLVM with AVR target ==<br />
<syntaxhighlight lang="shell"><br />
$ cd llvm-9.0.0.src<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR \<br />
-DLLVM_TARGETS_TO_BUILD= -DLLVM_BINUTILS_INCDIR=/usr/include \<br />
-D CMAKE_INSTALL_PREFIX=/opt/llvm-avr<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Get LDC source ==<br />
<syntaxhighlight lang="shell"><br />
$ git clone https://github.com/ldc-developers/ldc -b v1.18.0<br />
</syntaxhighlight><br />
<br />
== Build and install ldc with LLVM AVR ==<br />
<syntaxhighlight lang="shell"><br />
$ cd ldc<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/opt/ldc-avr -DLLVM_ROOT_DIR=/opt/llvm-avr<br />
$ ninja ldc2<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Test D with AVR ==<br />
<syntaxhighlight lang="d"><br />
enum AVR_ARCH = 5; // AVR architecture of your MCU<br />
<br />
static if (AVR_ARCH >= 100) {<br />
enum SFR_OFFSET = 0x00;<br />
} else {<br />
enum SFR_OFFSET = 0x20;<br />
}<br />
<br />
enum ubyte* MMIO_BYTE(ubyte memAddr) = cast(ubyte*) memAddr;<br />
enum ubyte* SFR_IO8(ubyte ioAddr) = MMIO_BYTE!(ioAddr + SFR_OFFSET);<br />
<br />
enum ubyte* PINB = SFR_IO8!(0x03);<br />
enum ubyte* DDRB = SFR_IO8!(0x04);<br />
enum ubyte* PORTB = SFR_IO8!(0x05);<br />
<br />
extern(C) void main() {<br />
import core.bitop;<br />
<br />
volatileStore(DDRB, 0xFF); // Set all PORT B to output<br />
<br />
while (true) {<br />
volatileStore(PORTB, 0xFF); // Set all PORT B to high<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
This simple code will set all I/O PORTS B to high, on Arduino UNO for example the PORT B is connected to the digital pins from 8 to 13 and this code will cause the internal LED to light up as it is connected to PIN 13.<br />
<br />
== How to build and run the test code ==<br />
First of all to generate an object file for AVR, convert it to HEX and then flash it into the flash memory of the MCU is advisable to use AVR GCC as C toolchain, linker, objcopy (to convert to hex) and avrdude (to load it into flash).<br />
<br />
Therefore it is necessary to install AVR-GCC, to do this consult the documentation of your operating system.<br />
<br />
The following commands need AVR-GCC installed and in a directory present in the PATH environment variable and are meant to be used with Arduino UNO, minor modifications are needed for other AVR MCUs<br />
<br />
<syntaxhighlight lang="shell"><br />
$ /opt/ldc-avr/bin/ldc2 -betterC -Oz -mtriple=avr -mcpu=atmega328p -Xcc=-mmcu=atmega328p -gcc=avr-gcc test.d<br />
$ avr-objcopy -O ihex -R .eeprom test test.hex // -R .eeprom is used to avoid overwriting the EEPROM, since is used to store data<br />
$ avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:test.hex // Write the hex in the ROM and reset MCU<br />
</syntaxhighlight><br />
<br />
== Current projects for use D on AVR ==<br />
* AVRD - https://github.com/WebFreak001/avrd<br />
<br />
== Info about the GNU/LINUX distros ==<br />
* ArchLinux, The llvm package in the official repo is already builded with the AVR flag (https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/llvm#n40), therefore the ArchLinux LDC package also supports the AVR target out-of-the-box</div>ErnyTechhttps://wiki.dlang.org/?title=Template:Latest_DMD_Version_Raw&diff=9727Template:Latest DMD Version Raw2019-12-07T21:03:31Z<p>ErnyTech: Update dmd version</p>
<hr />
<div>2.089.0</div>ErnyTechhttps://wiki.dlang.org/?title=D_on_AVR&diff=9717D on AVR2019-11-27T14:27:17Z<p>ErnyTech: D on AVR</p>
<hr />
<div>AVR is a family of 8-bit RISC microcontrollers, are widely used for embedded applications where a simple, inexpensive and low-powered microcontroller is needed.<br />
<br />
In the FOSS community, AVR-GCC has always been used as a toolchian for AVR which includes all the tools needed to compile a C source, copy the object files into a hex file and write it to the ROM of the microcontroller.<br />
<br />
The merge of the AVR backend for LLVM (https://github.com/avr-llvm) in the upstream LLVM project has given rise to the porting of modern languages to develop on AVR, such as Rust (https://github.com/avr-rust), Go (https://github.com/tinygo-org/tinygo) and Swift (http://swiftforarduino.com/).<br />
<br />
D has its frontend for LLVM so you can use it to program on AVR.<br />
<br />
== Get LLVM source ==<br />
<br />
<syntaxhighlight lang="shell"><br />
$ wget https://releases.llvm.org/9.0.0/llvm-9.0.0.src.tar.xz<br />
$ tar xf llvm-9.0.0.src.tar.xz<br />
</syntaxhighlight><br />
<br />
== Build and install LLVM with AVR target ==<br />
<syntaxhighlight lang="shell"><br />
$ cd llvm-9.0.0.src<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR \<br />
-DLLVM_TARGETS_TO_BUILD= -DLLVM_BINUTILS_INCDIR=/usr/include \<br />
-D CMAKE_INSTALL_PREFIX=/opt/llvm-avr<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Get LDC source ==<br />
<syntaxhighlight lang="shell"><br />
$ git clone https://github.com/ldc-developers/ldc -b v1.18.0<br />
</syntaxhighlight><br />
<br />
== Build and install ldc with LLVM AVR ==<br />
<syntaxhighlight lang="shell"><br />
$ cd ldc<br />
$ mkdir build<br />
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/opt/ldc-avr -DLLVM_ROOT_DIR=/opt/llvm-avr<br />
$ ninja ldc2<br />
$ sudo ninja install<br />
</syntaxhighlight><br />
<br />
== Test D with AVR ==<br />
<syntaxhighlight lang="d"><br />
enum AVR_ARCH = 5; // AVR architecture of your MCU<br />
<br />
static if (AVR_ARCH >= 100) {<br />
enum SFR_OFFSET = 0x00;<br />
} else {<br />
enum SFR_OFFSET = 0x20;<br />
}<br />
<br />
enum ubyte* MMIO_BYTE(ubyte memAddr) = cast(ubyte*) memAddr;<br />
enum ubyte* SFR_IO8(ubyte ioAddr) = MMIO_BYTE!(ioAddr + SFR_OFFSET);<br />
<br />
enum ubyte* PINB = SFR_IO8!(0x03);<br />
enum ubyte* DDRB = SFR_IO8!(0x04);<br />
enum ubyte* PORTB = SFR_IO8!(0x05);<br />
<br />
extern(C) void main() {<br />
import core.bitop;<br />
<br />
volatileStore(DDRB, 0xFF); // Set all PORT B to output<br />
<br />
while (true) {<br />
volatileStore(PORTB, 0xFF); // Set all PORT B to high<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
This simple code will set all I/O PORTS B to high, on Arduino UNO for example the PORT B is connected to the digital pins from 8 to 13, on Arduino UNO this code will cause the internal LED to light up as it is connected to PIN 13.<br />
<br />
== How to build and run the test code ==<br />
First of all to generate an object file for AVR, convert it to HEX and then flash it into the flash memory of the MCU is advisable to use AVR GCC as C toolchain, linker, objcopy (to convert to hex) and avrdude (to load it into flash).<br />
<br />
Therefore it is necessary to install AVR-GCC, to do this consult the documentation of your operating system.<br />
<br />
The following commands need AVR-GCC installed and in a directory present in the PATH environment variable and are meant to be used with Arduino UNO, minor modifications are needed for other AVR MCUs<br />
<br />
<syntaxhighlight lang="shell"><br />
$ /opt/ldc-avr/bin/ldc2 -betterC -Oz -mtriple=avr -mcpu=atmega328p -Xcc=-mmcu=atmega328p -gcc=avr-gcc test.d<br />
$ avr-objcopy -O ihex -R .eeprom test test.hex // -R .eeprom is used to avoid overwriting the EEPROM, since is used to store data<br />
$ avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:test.hex // Write the hex in the ROM and reset MCU<br />
</syntaxhighlight><br />
<br />
== Current projects for use D on AVR ==<br />
* AVRD - https://github.com/WebFreak001/avrd<br />
<br />
== Info about the GNU/LINUX distros ==<br />
* ArchLinux, The llvm package in the official repo is already builded with the AVR flag (https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/llvm#n40), therefore the ArchLinux LDC package also supports the AVR target out-of-the-box</div>ErnyTech