5  Programming

(Englisch)

5.1 Memory Sections

In Figure 5.1 you see the different FLASH and SRAM sections of the STM32L4. Also have a look at the “starter” source code:

https://gitlab.com/hhoegl-tha/es/f446/starter

Figure 5.1

The memory sections are defined in the linker script STM32L476RG_FLASH.ld.

  • The first two entries in the vector table are important for the right program start:

    Entry 0: initial stack pointer (sp). This vector table entry is the only vector which is not a “real vector”, which means, it is not a pointer to executable code.

    Entry 1: initial program counter (pc)

    You can print these two values with a GDB command:

    (arm-gdb) x/2xw 0x08000000

5.2 Levels of abstraction

The following items are arranged from low to high abstraction level.

  1. Standalone C, C++ or assembler program without dependencies to other libraries. This is the stronger definition of bare-metal programming. A more general definition is programming without operating system, but with additional libraries.

  2. CMSIS: Abstraction of the Cortex M3 core and core peripherals. In addition a vendor specific part abstracts the microcontroller peripherals. CMSIS consists of a bunch of C header files.

  3. STM32 Cube: Software framework with “hardware abstraction layer” (HAL) and “low layer” (LL). Cube also include the CMSIS layer.

  4. libc: Standard C library (or libc++)

  5. Middleware Libraries for graphical user interfaces, TCP/IP networking, file systems, realtime operating systems and so on.

  6. High-level interpreters - for example JavaScript or Python.

The layers are often used in combinations:

Levels of programming

An overview of different programming techniques gives [YIUWAYS]. It covers Java, MatLab/SimuLink, Labview, Arduino, mbed, Finite State Machines and other programming languages like Ada, Pascal, BASIC.

Higher-level interpreted programming languages are more and more ported to microcontrollers. A few examples are JerryScript (https://jerryscript.net), eLua (https://www.eluaproject.net), Espruino (https://www.espruino.com) and Micropython (http://micropython.org).

5.3 CMSIS

Cortex Microcontroller Software Interface Standard

https://developer.arm.com/embedded/cmsis

CMSIS Block Diagram

CMSIS Blockdiagramm

  • Templates for startup code. The standard startup file in CMSIS is written in assembler (startup_stm32l476xx.s). The startup code calls SystemInit which is defined in system_stm32l4xx.c.

  • Documentation in Cube Library

    STM32Cube_FW_L4_V1.8.0/Drivers/CMSIS/Documentation/Core/html/

  • Essential CMSIS files of version 4.30.

    CMSIS Files

    You find the CMSIS file tree in one of the CMSIS projects ending with -cmsis, e.g. starter-cmsis or gpio-intr-cmsis.

    https://gitlab.com/hhoegl-tha/es/f446/starter-cmsis

Literature

  • CM4PM contains the most important CMSIS definitions.

  • Trevor Martin, The Designer’s Guide to the Cortex M3, chapter 4 “Cortex Microcontroller Software Interface Standard”, pp. 109 - 139. Chapter 6 “Developing with CMSIS RTOS”, pp. 165 - 216, [MARTIN].

5.4 Cube L4

  • Home: https://www.st.com/stm32cubefw

  • It consists of

    • Hardware Abstraction Layer (HAL)
    • Board Support Packages (BSP)
    • CMSIS
    • Middleware
    • Example programs
  • A smaller version in which I removed some unneeded material is here:

    https://hhoegl.informatik.hs-augsburg.de/es2/tools

    See the file stm32cubel4-1.8.0-small.tar.bz2 (ca. 110 MByte)

  • Cube F4 overview (from Getting started with STM32CubeF4 firmware package (UM1730))

    STM32Cube Overview

    The diagram comes from Release Notes for STM32CubeL4 Firmware Package, which is contained in the Cube package.

5.5 Standard C library

Typical embedded system standard C libraries are

XXX to do