This is an old revision of the document!


Introduction to the Programming Frameworks

In the beginning, it is essential to distinguish an IoT Framework that is a set of tools, firmware for a variety of devices, sometimes also hardware, delivered as is and providing developers with configuration capabilities on the high abstraction level from the Programming Framework that is related to the low-level programming, here in C/C++, referred to as an SDK. SDK tends to be a narrower definition than a programming framework as it contains not only SDK but also tools, development toolchain and code organisation rules.
In this chapter, however, we discuss programming frameworks (SDKs and source code organisation) that define how your IoT code is organised on the low-level, in the bare metal programming model.
Almost every MCU (microchip/microcontroller) vendor develops its own SDK, providing programmers with a specific programming framework. It is worth nothing to mention that, in many cases, it follows the general programming construction of the source code for C or C++, such as below:

int main() {
    std::cout << "Hello IoT!";
    return 0;
}

A common approach is to use a GUI to automate the generation of the source code that contains hardware-specific configuration, i.e. timers, GPIOs, and interrupts, to automate monotonous and complex tasks and speed up time to market. Still, as hardware differs, it is particular for each platform, and usually, code development requires a rigorous approach to inject user-specific code only in predefined locations. Otherwise, it may break source code or even delete it when re-generating configuration using SDK tools and automation. Sample main() function for the STM32 MCU is presented below. Developers are intended to fill their code only in predefined areas, such as starting from USER CODE BEGIN Init and finishing before USER CODE END Init; otherwise, the source code will be gone when updating the configuration:

int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
  HAL_Init();
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
  SystemClock_Config();
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
  MX_GPIO_Init();
  MX_LPUART1_UART_Init();
  MX_NVIC_Init();
  /* USER CODE BEGIN 2 */
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      nUARTBufferLen = sprintf((char*)tUARTBuffer, "Hello World!\n\r");
      HAL_UART_Transmit_IT(&hlpuart1, tUARTBuffer, nUARTBufferLen);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Studying specific platforms is time-consuming, and as each vendor has its own approach, knowledge and source codes are usually not portable between microcontrollers. Specific frameworks for vendors are (among others):

  • Espressif ESP8266
    • ESP8266 RTOS SDK
    • ESP8266 Non-OS SDK
    • Arduino
  • AVR
    • Arduino
  • Espressif ESP32
    • ESP-IDF
    • Arduino
  • Nordic Semiconductors nRF52
    • Mbed
    • Zephyr RTOS
    • nRF5 SDK
    • Arduino
  • ST Microelectronics STM32 series
    • Mbed
    • CMSIS
    • Zephyr RTOS
    • Registers programming model (RAW)
    • STM32Cube (HAL)
    • Arduino

Typical C++ code, as presented above, is a single-pass execution. At the same time, microcontrollers used to work infinitely, handling their duties such as reading sensors, communicating over the network, sending and receiving data, routing messages and so on, thus, requiring setting up an infinite while (1) loop for processing. Many tasks need to be done in parallel, so it is common to include a task scheduling mechanism to run multiple tasks asynchronously. A common is to use a port of the FreeRTOS [1] or its port for the specific Microcontroller, modified by the vendor, i.e. as in the case of the ESP32 [2] to support multiple cores.

Even if the name FreeRTOS suggests it is a Real-Time Operating System, it is not. It is included as a C/C++ library to the source code and built into the firmware along with the algorithm. The name may be misleading, suggesting it runs in the background before your application starts as Windows or Linux does, while it does not.

Arduino Framework

Observing the list above, one can easily find that many platforms have common frameworks, but the Arduino framework is present for all of them. Arduino framework is a cross-platform approach providing a slightly higher level of abstraction over dedicated frameworks, and it is the most popular among hobbyists, students, professionals and even researchers at the moment. Arduino Framework is a reasonable balance between uniform code organisation and elements of cross-hardware HAL, still bringing opportunities to access hardware on a low level and get the advantage of the advanced features of modern IoT microcontrollers such as, i.e. power management. Most hardware vendors support this framework natively, and it has become almost an industry standard. Some advanced hardware control may require integration or other native frameworks, anyway. Still, the Arduino framework has real-time capacity. It is powerful and flexible enough to handle most IoT-related tasks, and most of all, it has excellent community support with dozens of software libraries, examples and applications worldwide.

A dummy C/C++ code for the Arduino framework looks as follows:

void setup()
{
 
}
 
void loop()
{
 
}

The void setup() function is executed only once after the microcontroller reboots. void loop() function is executed in a loop automatically once a single pass is finished. There is no need to implement a dummy while(1) inside the code; moreover, it is usually not advised or even forbidden. It is because, for every execution of the loop() statement, many other tasks, such as handling communication, may be executed. Making a single pass of the loop() function infinite could cause starvation of the other underlying processes the framework handles.

en/iot-open/introductiontoembeddedprogramming2/languagesandframeworks.1687450949.txt.gz · Last modified: 2023/06/22 13:22 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0