Commit 13d63edd authored by tuengominh's avatar tuengominh

add content assignment 8

parent de13b2d7
Pipeline #154116 passed with stage
in 1 minute and 7 seconds
......@@ -14,8 +14,9 @@ active: 1
<p class="font-italic font-weight-bold">* I needed to individually read a <a href="#datasheet">micro-controller datasheet</a> and program the board previously designed in <a href="http://academany.fabcloud.io/fabacademy/2020/labs/barcelona/students/tue-ngo/assignments/week-06-electronics-design.html#dice">the 6th week</a>.</p>
<h2 id="theory">Understanding embedded systems</h2>
<p>Allow me to go through a very long note without any images attached, or go straight to the assignments <a href="#assignment">below.</a></p>
<h5>Micro-controller unit (MCU)</h5>
<p>I personally find the theory sections I wrote down during electronics weeks to be really useful since they helped me organizing knowledge of completely new pieces of knowledge. This week, guest instructor Guillem Campodron gave us a very informative session which untangled many concepts I didn't understand about embedded systems. Allow me to go through a very long note without any images attached, or go straight to the assignments <a href="#assignment">below.</a></p>
<p>In short, in order to write a software to a hardware, we need to go through a process of coding, compliling and flashing the programs into the chips.</p>
<h5>Target - Micro-controller unit (MCU)</h5>
<p>A typical <a href="https://en.wikipedia.org/wiki/Microcontroller">micro-controller</a> includes a processor core, memory and input/output (I/O) peripherals on a single chip. A micro-controller controls a singular function by interpreting data received from I/O peripherals using the central processor. The temporary information that the micro-controller receives is stored in its data memory, where the processor accesses it and uses instructions stored in its program memory (firmware) to decipher and apply the incoming data. It then uses its I/O peripherals to communicate and enact the appropriate action. There are many available micro-controller families, some of them are widely used such as AVR (tinyAVR and megaAVR), ARM (Cortex-A/R/M), or Xtensa (ESP32, ESP8266), etc. For example, the ATTiny1614 chip used in my LED dice board is from tinyAVR family. Due to the COVID-19 outbreak situation, we were also provided by the instructors an <a href="https://en.wikipedia.org/wiki/Arduino_Uno">Arduino Uno</a> board with ATmega328P chip, <a href="https://www.luisllamas.es/esp8266-nodemcu/">NodeMCU</a> board with ESP8266 chip and a <a href="https://gitlab.fabcloud.org/barcelonaworkshops/barduino-2.0">Barduino</a> board with ESP32 WROOM chip.</p>
<ul>
<li>Central processor (CPU): ranging from small and simple 4-bit processors to complex 64-bit processors. For example, my ATtiny1614 micro-controllers uses the 8-bit AVR processor. A processor can be considered as the brain of the device. It can respond to events and perform basic logic and I/O operations. It also performs data transfer operations, which communicate commands to other components in the larger embedded system.</li>
......@@ -26,7 +27,7 @@ active: 1
</ul>
<p></p>
<h5>Software development toolchain</h5>
<h5>Compiling - Toolchain</h5>
<p>A <a href="https://elinux.org/Toolchains">toolchain</a> is the set of software development tools that are chained together. <a href="https://en.wikipedia.org/wiki/GNU_toolchain">GNU toolchain</a> which consists a C compiler is widely used in programming embedded systems and most toolchains are developed base on GNU (for instance, <a href="https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers">AVR GNU toolchain and ARM GNU toolchain</a>). A toolchain usually consists of:</p>
<ul>
<li>Editor: editing source code to control embedded systems. It could be a standalone application or built into an IDE/IDP. An IDE/IDP often consists of a source code editor, a compiler, a linker and a debugger. <a href="https://www.arduino.cc/en/main/software">Arduino IDE</a> and <a href="https://www.microchip.com/mplab/avr-support/atmel-studio-7">Atmel Studio</a> are widely used by electronics lovers, and we were also introduced to <a href="https://docs.platformio.org/en/latest/what-is-platformio.html">PlatformIO</a> by our instructor Oscar.</li>
......@@ -40,9 +41,9 @@ active: 1
<p>In short, a toolchain is able to compile source code written in a high-level language into executables that can run on target devices. Most of the programs are written in C/C++, but there are also <a href="https://en.wikipedia.org/wiki/Espruino">Espruino</a> that supports JavaScript and <a href="https://micropython.org/">MicroPython</a> that supports Python 3. Both of them have their compatible hardware and software.</p>
<p></p>
<h5>In-system programmer</h5>
<p>I've already read about ISPs in the <a href="http://academany.fabcloud.io/fabacademy/2020/labs/barcelona/students/tue-ngo/assignments/week-04-electronics-production.html#isp">4th week</a>. Basically, an external programmer is an extra bit of hardware that connects between a host computer and the target board and allows the microcontroller to be programmed. Bootloader is a piece of firmware stored in ROM that allows installing new firmware without the need of an external programmer.</p>
<p>Sometimes we need utilities to download and upload the on-chip memories. <a href="https://www.nongnu.org/avrdude/">avrdude</a> is a programming utility working with <a href="https://gcc.gnu.org/wiki/avr-gcc">avr-gcc</a> compiler/linker and can be used effectively via the command line. <a href="https://en.wikipedia.org/wiki/Make_(software)">GNU Make</a> is the automation tool for compiling and building programs using avrdude and avr-gcc, with the option of transferring (<strong>flashing</strong>) the <code>.hex</code> file into the target chip.</p>
<h5>Flasing - In-system programmer</h5>
<p>To flash a program to a chip, we might need extra hardware (an ISP) and some software (a toolchain and the program that will communicate with the hardware programmer). I've already read about ISPs in the <a href="http://academany.fabcloud.io/fabacademy/2020/labs/barcelona/students/tue-ngo/assignments/week-04-electronics-production.html#isp">4th week</a>. Basically, an external ISP is an extra bit of hardware that connects between a host computer and the target board and allows the microcontroller to be programmed. Besides, depends on the chip, sometimes we have bootloader which is a piece of firmware stored in ROM that allows installing new firmware without the need of an external programmer.</p>
<p>In many cases, we need programming utilities to download and upload the on-chip memories. <a href="https://www.nongnu.org/avrdude/">avrdude</a> is a programming utility working with <a href="https://gcc.gnu.org/wiki/avr-gcc">avr-gcc</a> compiler/linker and can be used effectively via the command line. <a href="https://en.wikipedia.org/wiki/Make_(software)">GNU Make</a> is the automation tool for compiling and building programs using avrdude and avr-gcc, with the option of transferring (<strong>flashing</strong>) the <code>.hex</code> file into the target chip.</p>
<p></p>
<h2 id="assignment">Understanding electronics datasheets</h2>
......@@ -223,7 +224,7 @@ active: 1
}
</code>
</pre>
<p>The process was exactly the same as my LED dice, except for choosing the ESP32 Dev Module as the board, <code>/dev/cu.usbserial-D307S8WM</code> as the port (I was using my Mac at the moment). The interesting thing about ESP32 boards is that the <a href="https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection">ESP32 will enter the serial bootloader when GPIO0 is held low on reset</a>, otherwise it will run the program in flash. Many boards use a button marked "Flash" or "Boot" that pulls GPIO0 low when pressed. In the case of the Barduino board, we have a reset button and a programmer slider switch that changes the mode of the chip: programming mode or normal execution mode. This is indeed very important, since I had to switch on the programming mode and keep pressing the reset button during the flashing process in order to upload my program. Otherwise I would have the below error:</p>
<p>The process was exactly the same as my LED dice, except for choosing the ESP32 Dev Module as the board, <code>/dev/cu.usbserial-D307S8WM</code> as the port (I was using my Mac at the moment). The interesting thing about ESP32 boards is that the <a href="https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection">ESP32 will enter the serial bootloader when GPIO0 is held low on reset</a>, otherwise it will run the program in flash. Many boards use a button marked "Flash" or "Boot" that pulls GPIO0 low when pressed. In the case of the Barduino board, we have a programmer slider switch that changes the mode of the chip: programming mode or normal execution mode. This is indeed very important, since I had to switch on the programming mode and keep pressing the reset button during the flashing process in order to upload my program. Otherwise I would have the below error:</p>
<pre class="bg-light py-2 mt-0">
<code>A fatal error occurred: “Failed to connect to ESP32: Timed out waiting for packet header”</code>
</pre>
......@@ -291,7 +292,10 @@ active: 1
<p>The LED blinked on and off again (a bit faster I think), but it's unecessary to keep posting another video with the same content ;)</p>
<img src="{{site.baseurl}}/assets/img/assignments/week-08/platformio-3.png" class="img-fluid w-100"/>
<p></p>
<!--<h6>Plain C + Make</h6>
<!--<h6>MicroPython</h6>
<p>I definitely had to try MicroPython, since using MicroPython is a great way to get the most of a ESP32 board, and vice versa, the ESP32 chip is a great platform for using MicroPython.</p>
<p></p>
<h6>Plain C + Make</h6>
<p><a href="https://en.wikipedia.org/wiki/Make_(software)">Make</a> uses the following command line tools to compile C code: <kbd>avr-gcc</kbd> (compiling and linking with existing libraries), <kbd>avr-objcopy</kbd> (converting <code>.elf</code> files to <code>.hex</code>), <kbd>avrdude</kbd> (uploading/flashing <code>.hex</code> files to the chip).</p>
<p></p>-->
<!--<h5>Group assignment - Compare tinyAVR, megaAVR and Xtensa families</h5>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment