This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:introductiontoembeddedprogramming2 [2023/07/13 08:20] – ktokarz | en:iot-open:introductiontoembeddedprogramming2 [2023/11/23 10:18] (current) – pczekalski | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Introduction to Embedded Programming ====== | + | ======= Introduction to Embedded Programming ======= |
- | IoT systems share programming paradigms with embedded systems. Each microcontroller manufacturer has its own set of tools (usually | + | {{: |
+ | IoT systems share programming paradigms with embedded systems. Each microcontroller manufacturer has its own set of tools (called SDK or Development Framework) that frequently contain an IDE dedicated to the platform. There are some cross-platform solutions and frameworks, however.\\ | ||
Programming languages include: | Programming languages include: | ||
* C/C++ - undoubtedly the most popular, versatile, yet demanding programming language. With modern supporting tools such as syntax highlights, code samples, code generators (AI-based) and instant syntax checking, C/C++ programming became relatively easy but still requires solid software development foundations. On the other hand, it is probably the only programming language that is natively supported with hardware debugging features. C/C++ bare metal programming allows the developer to control all MCU features on the lowest level and implement energy-efficient, | * C/C++ - undoubtedly the most popular, versatile, yet demanding programming language. With modern supporting tools such as syntax highlights, code samples, code generators (AI-based) and instant syntax checking, C/C++ programming became relatively easy but still requires solid software development foundations. On the other hand, it is probably the only programming language that is natively supported with hardware debugging features. C/C++ bare metal programming allows the developer to control all MCU features on the lowest level and implement energy-efficient, | ||
Line 6: | Line 7: | ||
* Python (Micropython) - similarly to Java, offers an easy start but low flexibility and control over the hardware. Acceptable for prototyping. | * Python (Micropython) - similarly to Java, offers an easy start but low flexibility and control over the hardware. Acceptable for prototyping. | ||
* Other. | * Other. | ||
- | + | <WRAP excludefrompdf> | |
- | ===== IoT and Embedded Systems Programming Models ===== | + | The following chapters |
- | IoT device programming can be done on a variety of levels. Below we present | + | * [[en: |
- | + | | |
- | + | * [[en: | |
- | ==== Bare Metal Programming ==== | + | |
- | The bare metal programming model is where the software developer builds firmware (usually from scratch or based on a stub generated by the SDK) and flashes it to the MCU. The MCU usually does not contain software other than technical ones necessary for starting and updating the device, i.e. a bootloader. The developer must implement all algorithms, communication, | + | * [[en: |
- | + | </WRAP> | |
- | < | + | |
- | + | ||
- | Bare metal programming requires a good understanding of the hardware configuration | + | |
- | + | ||
- | In most cases, source code is written in C or C++ language or their combination (i.e. in the case of the STM). The development process for bare metal programming is present in the following figure {{ref> | + | |
- | + | ||
- | <figure prog_img_baremetal> | + | |
- | {{:en: | + | |
- | < | + | |
- | </ | + | |
- | + | ||
- | The bare metal programming model is considered the only one to enable developers to have absolute control over the hardware on a very low level. On the one hand, it brings opportunities to implement non-standard solutions and optimal code in terms of compactness and efficiency; on the other, it increases time-to-market delivery. Recent advances in development supporting tools (i.e. AI-based code generation), | + | |
- | + | ||
- | <table prog_tbl_baremetal> | + | |
- | < | + | |
- | ^ Pros ^ Cons ^ | + | |
- | | Absolute control over hardware | + | |
- | | Secure, low vulnerability | + | |
- | | No bottlenecks | + | |
- | | Efficient and compact code | Requires complex development environment | + | |
- | | Fastest, no overhead of the middleware | + | |
- | | Good community support | + | |
- | | Highly flexible, enables the developer to prepare non-standard solutions | + | |
- | | Provides hardware debugging capabilities | + | |
- | | Energy efficient, it gives control over low-level, energy-saving mechanisms (waitstates, | + | |
- | </ | + | |
- | + | ||
- | <note tip> | + | |
- | In the IoT world, it is common to distribute firmware remotely (OTA - Over The Air). For this reason, it is pretty frequent that the flash memory of the IoT device is split in half into two partitions, each containing a different version of the firmware (old and new). OTA mechanism flashes inactive partition, and then the bootloader swaps them during the reboot of the device once flashing is done. If new firmware fails to boot, the bootloader swaps back the partition to run the old version reboots the device and notifies about the update error.</ | + | |
- | + | ||
- | ==== Script Programming with Middleware ==== | + | |
- | Opposite to bare metal programming, | + | |
- | + | ||
- | < | + | |
- | + | ||
- | The development process for scripting programming is present in the following figure {{ref> | + | |
- | + | ||
- | <figure prog_img_scripting> | + | |
- | {{:en: | + | |
- | < | + | |
- | </ | + | |
- | + | ||
- | This programming model is suitable wherever standard solutions are implemented and where code execution efficiency is not critical, and there is no demand for real-time operations; eventually, the IoT device is unconstrained, | + | |
- | + | ||
- | <table prog_tbl_scripting> | + | |
- | < | + | |
- | ^ Pros ^ Cons ^ | + | |
- | | Better suitable for beginners | + | |
- | | Uses higher abstraction level | Not suitable for real-time operations | + | |
- | | Uses high-level programming languages | + | |
- | | Usually does not involve complex SDK/ | + | |
- | | Flexible enough to implement complex algorithms | + | |
- | | Rapid development | + | |
- | | | Hardware debugging is tricky or not possible at all | | + | |
- | </ | + | |
- | + | ||
- | ==== Configuring Firmware ==== | + | |
- | Several middleware (IoT frameworks) are available for various IoT devices. This development model focuses on reconfiguring the sealed firmware delivered "as is" using some configuration interface or script (or both). Eventually, modifying and recompiling it yourself is possible if it is open source. Still, the process is usually very complex, and understanding all relations and development toolchain sometimes is more complicated than developing a solution from scratch as a bare metal. Proprietary frameworks do not bring this opportunity at all and are delivered "as is" with a predefined set of features. The development is limited to reconfiguring the elements from simply switching them on and off through setting up access and credentials, | + | |
- | + | ||
- | < | + | |
- | + | ||
- | The development process for the middleware configuration model is present in the following figure {{ref> | + | |
- | + | ||
- | <figure prog_img_middleware> | + | |
- | {{:en: | + | |
- | < | + | |
- | </ | + | |
- | + | ||
- | Configuration range varies among IoT frameworks but commonly requires compatible hardware. Proprietary firmware provides sealed configuration software and encryption; thus, it virtually excludes any non-standard modifications or makes them very complex. IoT hardware used to be compatible with more than one firmware, and proprietary ones can be replaced with another open source, i.e. Tasmota ((https:// | + | |
- | + | ||
- | <table prog_img_middleware> | + | |
- | < | + | |
- | ^ Pros ^ Cons ^ | + | |
- | | Easy to use even for beginners | + | |
- | | Consistent environment (configuration, | + | |
- | | No need for SDK, configuration tools use plain text, browsers or apps | Low flexibility - limited support for hardware (only proprietary or limited compatibility in the case of the open source) | + | |
- | | Manufacturer' | + | |
- | | Usually reliable | + | |
- | | During the maintenance period, updates are given by the vendor | + | |
- | </ | + | |
- | + | ||
- | < | + |