1 of 30

Sisteme embeded

Curs 1

2 of 30

Embedded system

  • A controller programmed and controlled by a real-time operating system (RTOS) with a dedicated function within a larger mechanical or electrical system, often with real-time computing constraints.
    • based on microcontrollers
    • complexity ranges from low to high, depending on the task
  • Types/architectures:
    • Simple control loop
    • Interrupt-controlled system
    • Cooperative multitasking (the loop is hidden in an API)
    • Preemptive multitasking or multi-threading (a low-level piece of code switches between tasks or threads based on a timer)
    • Monolithic kernels (embedded Linux)

3 of 30

Bare-Metal vs. RTOS

Bare-metal applications: generally small, fast and relatively easy to understand with a simple application . Typical components:

    • Initialization: Initializing the hardware and software components in main().
    • Super-loop state machine: Code to manage the application. The actions are based on the results of the interrupts (e.g. a SPI packet was received or a timer expired) or by polling.
    • ISRs: Code executed by interrupts for peripherals, timers or other device specific items (e.g. exceptions or multi-core communication).
  • Once more complicated logic is required, an RTOS starts to shine.
  • Minimal RTOS application: allows multiple developers to add content without dealing with potentially a fragile super-loop.

4 of 30

CISC vs RISC

  • Reduced Instruction Set Computing
  • On RISC processors, the instruction set operations and the microcode operations are very close.
  • RISC instructions sets are smaller, more atomic:
    • add the contents of two registers together.
    • ARM devices are RISC!

  • Complex Instruction Set Computing
  • On CISC, the complex instructions need to be translated into smaller microcode ops (as described above with the CISC add example). This means that the instruction decoder (the bit that works out what the CPU actually needs to do) is much simpler on a RISC processor, and simpler means less power and greater efficiency.
  • CISC instruction sets are larger, more complex:
    • add together two numbers stored in main memory:
    • the CPU needs to fetch the number from address-1 (one operation), fetch the number from address-2 (second operation), add the two numbers (third operation) …
  • All modern CPUs use a concept known as microcode, an internal instruction set of the CPU that describes atomic (micro) operations that the CPU actually executes.

5 of 30

ARM - Advanced RISC Machine

  • ARM
    • RISC
    • ARM was designed for power efficient processors
    • average ARM based smartphone SoC (including the GPU) has a maximum instantaneous peak power of around 3W
    • ARM’s big.LITTLE architecture is an innovation that Intel is nowhere near replicating. In big.LITTLE the cores in the CPU don’t need to be of the same type. 
  • Arduino?
        • Modelele cu AVR 8/32 biti are RISC but not ARM compatible …
        • Modele cu ARM Cortex-M0+ (32-bit), ARM Cortex-M3
        • STM32 Blue Pill (30 lei!), compatibil Arduino
  • Raspberry Pi ?
    • different I/O than most ARMs and that I/O is not too well documented
    • proprietary bootloader in the GPU!

6 of 30

Cortex M (Embedded) 

  • Platforme pentru development
    • NXP (LPC or Kinetis)
    • Atmel (SAM)
    • Cypress (PSoC4/5) 
    • ST-Microelectronics (STM32)

    • In this course we use: STM32F405
      • 32 de biti -> Maximum memory 4GB
      • 192 Kbytes of system SRAM, that can be accessed as:
        • bytes,
        • half-words (16 bits)
        • full words (32 bits)
      • Little endian (LSB) format for bytes
      • Has:
        • code area starts from address 0x0000 0000
        • data area (SRAM) starts from address 0x2000 0000
        • Can boot from code area (flash mem. ), but also from internal SRAM

7 of 30

RTOS – Real Time Operating System

A real time system is a time bound system which has well defined fixed time constraints.

  • Processing must be done within the defined constraints or the system will fail. They either are event driven or time sharing. Event driven systems switch between tasks based on their priorities while time sharing systems switch the task based on clock interrupts.
  • Most RTOS’s use a pre-emptive scheduling algorithm.
  • Key factors in a real-time OS are minimal interrupt latency and minimal thread switching latency;
  • There are many versions: TI-RTOS, OpenRTOS, FreeRTOS (most ported including Arduino/AVR)

Types of RTOS

  • Soft Real-Time Operating System
  • The soft real-time operating system has certain deadlines, may be missed and they will take the action at a time t=0+. The soft real-time operating system is a type of OS and it does not contain constrained to extreme rules. The critical time of this operating system is delayed to some extent. The examples of this operating system are the digital camera, mobile phones and online data etc.
  • Hard Real-Time Operating System
  • This is also a type of OS and it is predicted by a deadline. The predicted deadlines will react at a time t = 0. Some examples of this operating system are air bag control in cars, anti-lock brake, and engine control system etc.
  • Firm Real-Time Operating System
  • In the firm real-time, an operating system has certain time constraints, they are not strict and it may cause undesired effects.Examples of this operating system are a visual inspection in industrial automation.

8 of 30

RTOS Components

  • Scheduler: Preemptive scheduler that guarantees the highest priority thread it running.
  • Communication Mechanism: Semaphores, Message Queues, Queues, etc.
  • Critical Region Mechanisms: Mutexes, Gates, Locks, etc.
  • Timing Services: Clocks, Timers, etc.
  • Power Management: For low power devices, power management is generally part of the RTOS since it knows the state of the device.
  • Memory Management: Variable-size heaps, fixed-size heaps, etc.
  • Peripheral Drivers: UART, SPI, I2C, etc.
  • Protocol stacks: BLE, WiFi, etc.
  • File System: FatFS, etc.
  • Device Management: Exception Handling, Boot, etc.

9 of 30

RTOS – Real Time Operating System

  • Asynchronous communication

x8

times

10 of 30

Handling in RTOS of 2 async communications

  • Integration of serial reading algorithm below ... the application is downloaded to the device along with RTOS!

11 of 30

Software execution in time

  • RTOS provides mechanism to switch tasks
  • Provides several services to tasks:
    • Services are reusable components (guarantees worst case interrupt latency)
    • System calls can run complex functions as tasks

12 of 30

Task, handler, API

  • Task – application managed by the RTOS
  • Handler
    • software executed by interruption of currently executed software (interrupt handler, exception handler, Cyclic handler, etc.)
  • System calls – will be referred as APIs

13 of 30

Task switch�

  • Replacing data in the CPU registers

14 of 30

Definitions

  • Context switch = CPU register switch
  • Dispatch = transferring execution rights from on task to another (includes context switch)
  • Task Control Block = stored data related to each task, one for each task

15 of 30

Queues

  • TCB link to form a queue

16 of 30

Task states

  • Running/Active state:
    • Task being executed (only 1 task can be executed at once)
    • Executed in order of priority
  • Ready State
    • Prepared to be executed
  • Pending
    • Task waiting for a resource
  • Waiting/Suspended state
    • Has abandoned the right to execute as it is waiting for an event
  • Dormant
    • Only registered at the RTOS but it is not executed yet (no need for compute time)

17 of 30

Scheduling

  • Determines which task is selected from Ready state tasks
  • Priorities are assigned at task initialization (lower numbers – higher prority)
  • More tasks with the same priority? Usually the algorithm Priority based FIFO algorithm

18 of 30

Handles

  • Higher priority than tasks
  • Interrupts disabled during handle execution
  • Software executed at task interruption
    • interrupt handler,
    • exception handler,
    • cyclic handler: activated periodically

19 of 30

Interrupt types

  • Non OS managed (fast, higher priority)
    • APIs cannot be called in the interrupt processing program
    • Low overhead (no task switching -> no overhead)
  • OS managed
    • Can invoke APIs in the interrupt processing algorithm
    • Can pass on processes to tasks
    • High processing overhead because they are able to call APIs

20 of 30

APIs

  • Activate, terminate, delay tasks
    • Activate: moves task from dormant to ready (if higher prority, it ca enter running state!)
    • Self-terminate task: moves state from running to dormant
    • Terminate task:
      • ready -> dormant
      • running -> dormant
    • Delay: moves state to Waiting, after time elapses moves it to ready;

21 of 30

Tick process

  • Used for time management in RTOS
  • Periodically activated, disables interrupts! (interrupt response deteriorates)
  • Processes are occurring with every tick
  • Has high overhead (100us – 1ms)
  • The shorter it is the higher is the precision, but the higher the overhead!

Same task, different number of waiting tasks

22 of 30

RTOS for multi core processors

  • Symmetric Processor Multicore system

  • Asymmetric Processor Multicore system

23 of 30

RTOS for multicore

  • RTOS handles:
    • Inter-task communication
    • Task switching between processors depending on load (no longer has to be handled by the program)
  • Gives large overhead
  • For 3+ processors, cant
  • Guarantee execution time

24 of 30

Applications

  • The hardware
  • Installing the software
  • Writing the code (P1: Blink program)
  • Downloading RTOS+application to the device (flashing using the JTAG)
  • Debugging the application
  • P2: Commanding the relay (electrically operated switch)
  • P3: Reading the button
  • …if enough time serial communication P4

25 of 30

Installing the software

- Se descarca si se instaleaza Visual GDB - https://visualgdb.com/download/

- in Visual Studio intram in Tools -> Visual GDB -> Manage Visual GDB Packages

26 of 30

Instalare componente Visual GDB

Instalam:

  • ARM Toolchain,
  • STM32 Devices,
  • OpenOCD,
  • Embedded Profiler and
  • Fast semihosting

 Se descarca si se instaleaza driver st-link si PL2302: https://bit.ly/2tLdYLH

27 of 30

Creare Proiect in Visual Studio

  • File >> New >> Project >> Visual GDB >> Embedded Project

28 of 30

Conectam placa

29 of 30

Instalam exemplul blink cu FreeRTOS

30 of 30

Verificare conexiune

  • Apasam butonul “TEST” din dreapta sus si vedem urmatorul mesaj