ARM

 

Cortex M0

https://homepages.thm.de/~hg6458/semsts/CMSIS_Kendl.pdf

Bild1WIC … Wakeup Interrupt Controller

NVIC ...Nested Vector Interrupt Controller

AMBA … Advanced Microcontroller Bus Architecture   defines the Following Bus:

AHB-lite … Advanced High Performance Bus

 

  • THUMB2 Befehlssatz nur zum Teil implementiert

  • geringer Leistungsbedarf 85uW/MHz

  • Von Neumann Architektur

 

 

Cortex M0 vs M0+

 

Features

M0

M0+

Advantages of M0+ over M0

Pipeline

Three-stage

Two-stage

Improved response time,improved efficiency

Performance Efficiency

2.33 CoreMark/MHz

2.46 CoreMark/MHz

Lower power and higher performance

Memory Protection

Not available

Has optional Memory protection Unit

Makes system more secure by: Separating processes – Preventing tasks from corrupting stack or data memory used by other tasks Preventing unprivileged tasks from accessing peripherals that can be critical to the system security

Relocatable vectortable

Does not support

Supports

Allows relocating the interrupt vector table anywhere in the memory - enables different applications to use their own vector table.

Unprivileged/privileged mode execution

Does not support

Supports

Allows a task, such as the system calling in an operating system, to execute with more privileges than the user task or an application.

 

Bild2Cortex M3

ETM …

DAP

Code Interface

  • Harvard Architektur

  • voller THUMB2 Befehlssatz

Bild3Cortex M4

Floating Point Unit

  • Digitale Signalverarbeitung (MAC Multiply Accumulate)

Advanced High-performance Bus

Auszug aus der Wikipedia

Der Advanced High-performance Bus (AHB) ist Teil der Advanced Microcontroller Bus Architecture (AMBA)

Der AHB unterstützt:

Eine einfache Transaktion auf dem AHB besteht aus einer Adressphase und einer anschließenden Datenphase, dauert also ohne wait states nur zwei Takte. Dabei wird der Zugriff auf das Zielgerät über einen Arbiter mittels einer Mux gesteuert (non-tristate), so dass jeweils nur ein Bus-Master Zugriff auf den Bus hat.

Der Zugriff auf den Control-Bus in der Adressphase und den Datenbus in der Datenphase wird unabhängig nacheinander zugeteilt, so dass in der gleichen Taktphase ein Bus-Master die Adress- und Kontrollleitungen anlegen kann, während ein zweiter Master Daten liest oder schreibt (pipelined operations).

 

AHB-Lite

* is a subset of AHB; this subset simplifies the design for a bus with a single master.

Ports

  • Organized in groups (line bundles)

  • up to 32 pins / group

  • programmed individually or as a group

  • general purpose io or peripheral device pin

 

Connected internally via AHB Bridge or faster via IOBUS (1 cycle CPU local bus)

Image1

Image2

PORT FEATURES

 

  • configuration individually for each pin

  • Software-controlled multiplexing of peripheral functions on

  • dedicated Pin Configuration register

  • Configurable output driver and pull settings:

    • Totem-pole (push-pull)

    • Pull configuration

    • Driver strength

 

  • Configurable input buffer and pull settings:

    • Internal pull-up or pull-down

    • Input sampling criteria

    • nput buffer can be disabled if not needed for lower power consumption

  • Read-modify-write support for pin configuration, output value and pin direction

CLOCK System

 

CLK_MAIN … common source for synch clocks;
                          fed into common 8 bit prescaler  for synch clocks to CPU, AHB, APBx

CLK_CPU

CLK_AHB … some peripherals require an AHB clock ( same clock as CLK_CPU, but can run when cpu is stopped)

CLK_APBx … root clock source for peripherals who require APB clock (sync to CLK_CPU, but prescaler available and can run when CLK_CPU is stopped)

 

 

  • Sysctrl … physical Clock sources (XOSC,OSC32K, DFLL digital frequency locked loop ...)

  • Bild4GCLK  … generic clocks block

    • GCLK Generator (prescaler)

    • GCLK Multiplexer (mux to take any of the Generators as  source for a Generic Clock)

    • Generic Clocks (clock input of a peripheral)

      • Generic Clock 0 is intput to DFLL48M

  • PM  … power manager

    • synchronous clocks and prescaler for CPU, AHB, APBx and synch user interface of the peripherals

    • mask flags to turn off user interface of peripherals

 

An example

Bild5

Enabling a Peripheral

  • A running clock source.

  • clock from the Generic Clock Generator must be configured to use one of the running clock sources, and the generator must be enabled

  • The generic clock, through the Generic Clock Multiplexer, that connects to the peripheral needs to be configured with a running clock from the Generic Clock Generator, and the generic clock must be enabled.

  • The user interface of the peripheral needs to be unmasked in the PM. If this is not done the peripheral registers will read as all 0’s and any writes to the peripheral will be discarded

Getting Started with FreeRTOS on SAM

AT03664: Getting Started with FreeRTOS on SAMD20/D21/R21/L21/L22

Was ist ein RTOS?

  • Multitasking: Tasks laufen parallel; ein Scheduler entscheidet, wie viele Prozessorzyklen ein Task kriegt bevor auf den nächsten Task umgeschaltet wird; Illusion von Gleichzeitigkeit durch die hohe Umschaltrate

  • Multiuser OS: der Scheduler versucht, jeden User gleichmäßig zu bedienen (Prio); Desktop-OS: jedes Programm soll responsiv sein

  • RTOS Scheduler: die Reaktionszeit ist vorhersagbar (deterministisch) – es gibt für die Reaktion des Prozessors eine Deadline; jedem Teilprogramm (executive thread, task) kann eine Priorität zugewiesen werden; auf Grund der Prio entscheidet der Scheduler, welcher thread als nächstes aktiviert wird.

Was ist Free RTOS

  • Nur ein RTOS Kernel wegen der beschränkten Ressourcen der Prozessoren

  • Kernfunktionen:

    • Scheduler,

    • Inter-Task-Kommunikation,

    • Timing

    • Synchronisation

Semaphor

https://blog.feabhas.com/2009/09/mutex-vs-semaphores-%e2%80%93-part-1-semaphores/

 

  • Binärer S blockt einen Kritischen Bereiche; alle späteren Tasks, die auch diesen Bereich nutzen wollen müssen warten, bis der erste Task den Bereich wieder frei gibt

  • Counting Semaphor: ein Zähler muss erst auf Null stehen bevor der Bereich gesperrt wird
    vgl. Parkplatzverwaltung: am Anfang steht der Zähler auf MaxAnzahlParkplätze; jeder Parker dekrementiert um 1, wenn der Zähler auf Null steht müssen Anwärter auf den Parkplatz warten

ATMEL ASF

 

Atmel Software Framework

SAMD10 Cortex M0+    ASF      http://asf.atmel.com/docs/latest/samd10/html/

 

Tutorial

https://startingelectronics.org/software/atmel/asf-arm-tutorial/

A Primer: The LED Blink Program

 

Configure system tick to generate periodic interrupts

 

Line of Code (ATMEL Studio) :

SysTick_Config(system_gclk_gen_get_hz(GCLK_GENERATOR_0));

  • GCLK_GENERATOR_0 enum in gclk.h (Index of  available GCLK generators)

  • uint32_t system_gclk_gen_get_hz(const uint8_t generator) ...Determines the clock frequency (in Hz) of a specified Generic Clock generator (gclk.c)

Programming Technique

Set Register Contents

e.g. load the GENCTRL-Register with value 0

*((uint8_t*)&GCLK->GENCTRL.reg) = 0;


#define GCLK   ((Gclk *)0x40000C00U) /**< \brief (GCLK) APB Base Address */

 

 

 

typedef struct {

  __IO GCLK_CTRL_Type     CTRL;        /*Offset: 0x0 (R/W  8) Control */

  __I  GCLK_STATUS_Type   STATUS;      /*Offset: 0x1 (R/   8) Status */

  __IO GCLK_CLKCTRL_Type         CLKCTRL; /*Offset: 0x2 (R/W 16) Generic Clock Control */

  __IO GCLK_GENCTRL_Type         GENCTRL; /*Offset: 0x4 (R/W 32) Gen. Clk Gen  Control */

  __IO GCLK_GENDIV_Type          GENDIV; /* Off 0x8 (R/W 32) GenClockGen Division */

} Gclk;

 

 

typedef union {

  struct {

    uint32_t ID:4;             /*!< bit:  0.. 3  Generic Clock Generator Selection  */

    uint32_t :4;               /*!< bit:  4.. 7  Reserved                           */

… gekürzt

    uint32_t :10;              /*!< bit: 22..31  Reserved                           */

  } bit;                       /*!< Structure used for bit  access                  */

  uint32_t reg;                /*!< Type      used for register access              */

} GCLK_GENCTRL_Type;

  1. take the register address

  2. convert it to a pointer explicitely

  3. dereference this pointer to access the content of the register

  4. UNION allows to access bits within the 32bit Register or to take it all (.reg)

     

 Achtung! Um Probleme durch gleichzeitig auftretende Interrupts zu vermeiden:
system_interrupt_enter_critical_section();

system_interrupt_leave_critical_section();

 

Examples

http://start.atmel.com/#dashboard  … Configurator

 

 

Tools

Programmiertool für edbg (linux, win)

https://github.com/ataradov/edbg

Klonen und "make all"; dependant on Linux: libudev-dev

Worked on Ubuntu after reboot and with root rights e.g.

>sudo ./edbg -r -f /tmp/x.dat -t atmel_cm0p

 

 

Programmiertool ST-LINK V2

Programmer um 10 EUR;

Installation Linux:

https://startingelectronics.org/tutorials/STM32-microcontrollers/programming-STM32-flash-in-Linux/

Achtung! Das aktuelle Projekt findet man unter https://github.com/texane/stlink.git

Tools: st-flash und st-info

Terminalprogramm

(Ubuntu 16.04)

>sudo minicom -b 38400 -D /dev/ttyACM0

sudo kann entfallen, wenn man den User zur Gruppe der Sercon-User hinzufügt

>sudo adduser roland dialout

( mit anschließendem logout/login )

 

Das Gerät ist nicht sichtbar, aber ein

>dmesg

liefert

[ 1667.505618] usb 2-1: Product: mEDBG CMSIS-DAP

[ 1667.505621] usb 2-1: Manufacturer: ATMEL

[ 1667.505624] usb 2-1: SerialNumber: ATML2378020200007873

[ 1667.507899] hid-generic 0003:03EB:2145.0011: hiddev0,hidraw0: USB HID v1.11 Device [ATMEL mEDBG CMSIS-DAP] on usb-0000:00:14.0-1/input0

[ 1667.508043] cdc_acm 2-1:1.1: ttyACM0: USB ACM device