====== Software Development Tools and Platforms ====== {{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_m.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\ Software development in the bare metal model requires a development toolchain installed on the developer's computer. The vendor of the MCU usually provides a set of tools. This set frequently includes a dedicated compiler, linker, library management tools, configuration tools, debugger software, etc. These tools are command lines in most cases. Using a GCC ((https://gcc.gnu.org/)) C/C++ compiler is also quite common. On top of it, a GUI with a rich UI interface is built to simplify software development. Some vendors provide their own GUIs, such as STMicroelectronics' STM32CubeIDE (image {{ref>sdt_stm32cubeide}}). In contrast, others use already available universal code editing solutions and integrate with them, e.g. in the form of plugins or extensions. Vendors barely develop their own GUI solutions from scratch; instead, they adapt existing open-source ones, e.g. STM32CubeIDE is built on top of the Eclipse IDE ((https://www.eclipse.org/ide/)). Detailed instructions on the tools necessary to set the development environment, e.g., the STM32 WB chip family, are presented on the STM's YouTube channel ((https://www.youtube.com/watch?v=YSyaH5v3hys)).
{{ :en:iot-open:introductiontoembeddedprogramming2:stm32cubeide.png?660 | Eclipse for STM32 developers}} STM32CubeIDE: Eclipse for STM32 developers
Because documentation for the command line tools composing SDK is usually available, there are also universal solutions that enable developers to use a single GUI environment for various tasks and microcontrollers, switching among them quickly, such as Visual Studio Code (figure {{ref>sdt_vscode}}). Each platform requires its dedicated toolchain, anyway, and integration with universal code editors such as the aforementioned VS Code may be tricky. Luckily, there are tools to help with the automated installation of all required components, such as PlatformIO ((https://platformio.org/))), which we describe below.
{{ :en:iot-open:introductiontoembeddedprogramming2:vscodeide.png?660 | Universal development environment}} VS Code: a universal development environment
As the Arduino programming framework became a cross-platform standard, vendors provided low-level libraries implementing standard functionalities such as embedded communication protocols (Serial, SPI, I2C, 1Wire) and networking communication. Arduino, a manufacturer of popular development boards, provides an IDE (figure {{ref>sdt_arduinoide}}: Arduino IDE ((https://www.arduino.cc/en/software))) that is intended to be an entry-level development environment. It can be extended beyond genuine Arduino boards, e.g. with the Espressif toolchain for ESP8266 and ESP32. This software, however, is very limited in features and is suitable only for simple projects.
{{ :en:iot-open:introductiontoembeddedprogramming2:arduinoide.png?660 | Arduino IDE: an entry-level IDE for beginners}} Arduino IDE: an entry-level IDE for beginners
We suggest starting with VS Code and PlatformIO over Arduino IDE, even if you're a beginner. ===== Developers Middleware and Support Tools ===== Several additional tools usually come with the development toolchain provided by the hardware vendors. They include programmers (flashers, injecting firmware into the IoT device), configuration tools, power consumption calculators, etc. Installation is not always straightforward, and updating is tricky. Developers who use a variety of platforms (MCUs) struggle with instant updates and browsing the web for tools, samples and libraries. Moreover, handling libraries they use for development is time-consuming and involves instant monitoring of changes, manual copy-paste operations on files, etc. Moreover, it has to be done individually for every project. ==== PlatformIO ==== {{:en:iot-open:introductiontoembeddedprogramming2:platformio-logo.17fdc3bc.png?60 |}}The solution is a developer's middleware that integrates with selected IDE and helps to install, configure and maintain toolchains for hardware, software development libraries, and also contains a set of additional tools (e.g. serial port monitor, JTAG debugger, code repository integration, collaboration tools, remote development, etc.). As mentioned above, one example of a handy middleware for IoT and embedded development is PlatformIO. It is a command-line toolset that provides a whole ecosystem for virtually any hardware platform; it still uses the vendor's proprietary toolchains. It perfectly integrates with Visual Studio Code (among others) via VS Code's extension (plugin) systems. VS Code also works as a GUI for PlatformIO. In the following figures, we present its look and UI when integrated with Visual Studio Code (figures {{ref>std_pio1}}, {{ref>std_pio2}} and {{ref>std_pio3}}).
{{ :en:iot-open:introductiontoembeddedprogramming2:pio1.png?660 | VSCode with PlatformIO: starting page}} VSCode with PlatformIO: starting page
{{ :en:iot-open:introductiontoembeddedprogramming2:pio2.png?660 | VSCode with PlatformIO: library management}} VSCode with PlatformIO: library management
{{ :en:iot-open:introductiontoembeddedprogramming2:pio3.png?660 | VSCode with PlatformIO: toolchain management}} VSCode with PlatformIO: toolchain management
A PlatformIO-enabled IoT project is a set of files with a ''platformio.ini'' file in the root folder and ''main.cpp'' in the ''./src/'' subfolder (as, e.g. in the figure {{ref>std_pio1}}, project folder tree is to the left)). The ''platformio.ini'' file describes all technical parts of the project: the hardware platform, the method of uploading the firmware (usually via a serial port), software libraries that are included in the code and should be automatically pulled from the libraries repository during compilation and many other options ((https://docs.platformio.org/en/stable/projectconf/index.html)). Sample ''platformio.ini'' file is presented in the code below: [env:d1_mini] platform = espressif8266 board = d1_mini framework = arduino upload_port = /dev/ttyUSB0 upload_speed = 9600 monitor_port = /dev/ttyUSB0 lib_deps = arduino-libraries/LiquidCrystal@^1.0.7 adafruit/Adafruit Unified Sensor@^1.1.7 adafruit/DHT sensor library@^1.4.4 This code configures the ESP8266 (Espressif) hardware project, with specific developer board D1 Mini and programming done in the "Arduino" framework development model.\\ Communication with the IoT device is via serial port (here ''/dev/ttyUSB0'' for Linux or, e.g. ''COM3'' for Windows) and uses the same port for monitoring (serial port monitor for tracing messages from the MCU and code).\\ It uses three libraries registered in the library registry for PlatformIO: ''LiquidCrystal'', ''Adafruit Unified Sensor'' and ''DHT sensor library'', with explicit versions. PlatformIO's Library Manager automatically checks for updates and proposes to update libraries to the latest available if a version is not explicitly stated. The Library Registry in the PlatformIO is a repository of the Gitlab project, available online ((https://docs.platformio.org/en/latest/librarymanager/index.html)). Libraries are currently held per project instead of shared between projects.\\ At the start of the PlatformIO GUI and then periodically, it checks for PlatformIO updates and development toolchain updates, proposing to update them when a new version is available.