# Microprocessors and -controllers

- [audiobook of data sheet ATtiny212_412](https://drive.google.com/file/d/1TNgZ8BKVB2FlWRgD33BMKDShWadj8DH4/view)
- [recitation](https://vimeo.com/1056097345)
  - [presentation](https://fabacademy.org/2025/recitation/debugging/)
- [literature explaining working with AVRs](https://github.com/SpenceKonde/AVR-Guidance/tree/master)
- [microcontroller vs -processor](https://www.geeksforgeeks.org/whats-difference-between-microcontoller-%C2%B5c-and-microprocessor-%C2%B5p/)
- [download platformio for vscode](https://marketplace.visualstudio.com/_apis/public/gallery/publishers/platformio/vsextensions/platformio-ide/3.3.4/vspackage)

## MCU
An **MCU** is a group of **microcontroller units** that share a common architecture, design, and often the same core features
- **ARM Cortex-M** is a popular MCU family, where multiple manufacturers like **STMicroelectronics**, **NXP**, and **Microchip** produce MCUs that are based on the ARM Cortex-M core.
- **AVR** is another MCU family, famously used in the **Arduino** platform.
- **PIC** is a family of MCUs from **Microchip Technology**, with a range of devices from small 8-bit controllers to more powerful 16-bit and 32-bit versions.

Within each MCU family, you’ll typically see models that differ by features like:
- **Flash memory size**
- **RAM size**
- **Clock speed**
- **Number of GPIO pins**
- **Peripheral support** (e.g., UART, SPI, I2C, timers, etc.)

[In-System Programming (ISP)](https://smh-tech.com/corporate-blog/in-system-programming-isp-and-pre-programming-what-is-the-difference/)
- the act of programming a microcontroller while it is already mounted on the board
- Contrary to Pre-Programming. You program the contro

[CMSIS-DAP Devices](https://mtm.cba.mit.edu/2021/2021-10_microcontroller-primer/tools-cmsis-dap/#cmsis-dap-devices) are all devices that can write programs into a microcontroller's memory using JTAG or SWD.
ler before soldering it somewhere.


## Available Controllers
At least 5 of each:
- [SEEEDSTUDIO XIAO SAMD21 NO HDRS](https://files.seeedstudio.com/wiki/Seeeduino-Cortex-M0-/res/SAM-D21-Datasheet.pdf) 
- [SEEEDSTUDIO XIAO ESP32C3 NO HDRS](https://files.seeedstudio.com/wiki/Seeed-Studio-XIAO-ESP32/esp32-c3_datasheet.pdf)  
- [SEEEDSTUDIO XIAO ESP32S3 NO HDRS](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf)  
- [SEEED STUDIO XIAO RP2040 ARDUINO](https://files.seeedstudio.com/wiki/XIAO-RP2040/res/rp2040_datasheet.pdf)  
- ATSAMD11C14A-SSUT  
- ATSAMD21E18A-AUT  
- ATTINY412-SSFR  
- ATTINY1624-SSFR  
- ATTINY3226-SU  
- AVR128DB32-I/PT

|                | Xiao RP2040 | Pico RP2040 | ESP32C3 | ESP32S3 | SAMD21 | ATSAMD11C14A-SSUT | ATSAMD21E18A-AUT | ATTINY412-SSFR | ATTINY1624-SSFR | ATTINY3226-SU | AVR128DB32-I/PT    |
|----------------|-------------|-------------|---------|---------|--------|-------------------|------------------|----------------|-----------------|---------------|--------------------|
| Type           |ARM Cortex M0+ 32Bit|ARM Cortex M0+ 32Bit|  ESP-RISC-V  32Bit | Xtensa® 32-bit LX7 | ARM-Cortex M0+ 32Bit| ARM Cortex-M0+ 32Bit| ARM Cortex M0+ 32Bit | AVR® RISC 8-bit | AVR® RISC 8-bit | AVR® RISC 8-bit  |  AVR® RISC 8-bit   |
| Frequency      | 133MHz      | 133MHz      | 160 MHz | 240 MHz | 48MHz  | 48MHz             | 48MHz            | 20MHz          | 20MHz           | 20MHz         | 24MHz              |
| SRAM           | 264KB       | 264KB       | 400 KB  | 8MB     | 32KB   | 4KB               | 32KB             | 256B           | 2KB             | 3KB           | 16KB               |
| onboard memory | 2MB         | 2MB         | 4MB     | 8MB     | 256KB  | 16KB              | 256KB            | 4KB            | 16KB            | 32KB          | 128KB              |
| I/O-Pins       | 11          | 26          | 11      | 11      | 11     | 12                | 26               | 6              | 12              | 18            | 25/26 (1x only In) |
| ADC            | 4           | 3           | 3       | 9       | 11     | 5                 | 6                | 6              | 9               | 15            | 13                 |
| DAC            | 0           | 0           | 0       | 0       | 1      | 1                 | 1                | 1              | 0               | 0             | 1                  |
| Package        |             |             |         |         |        | SOIC-14           | TQFP-32          | SOIC-8         | SOIC-14         | SOIC-20       | TQFP-32            |
| Price          | 4,68 $      | 5 $         | 4,99 $  | 7,49 $  | 5,4 $  | 1,58 $            | 4,03 $           | 0,59 $         | 1,01 $          | 1,29 $        | 2,06 $             |
| FPU available? |             |             |         |         |        |                   |                  |                |                 |               |                    | 

### RP2040 (Raspberry Pi Pico)  
**Toolchain**:  
- **Primary**: [Pico SDK](https://github.com/raspberrypi/pico-sdk) (C/C++), CMake  
- **Alternatives**: Arduino IDE (via [Arduino-Pico Core](https://github.com/earlephilhower/arduino-pico)), MicroPython/CircuitPython  

**Workflow**:  
1. Write code in C/C++ or Python.  
2. Build with CMake (Pico SDK) or Arduino IDE.  
3. Flash via USB (UF2 bootloader) or SWD debugger (e.g., Picoprobe).  

**Efficiency Tips**:  
- Use Visual Studio Code with the Pico SDK extension for CMake integration.  
- Leverage Picoprobe (a second Pico) for debugging.  

### ESP32 (Espressif)  
**Toolchain**:  
- **Primary**: [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/) (C/C++), PlatformIO  
- **Alternatives**: Arduino IDE (via [ESP32 Core](https://github.com/espressif/arduino-esp32))  

**Workflow**:  
1. Develop in C/C++ (ESP-IDF) or Arduino framework.  
2. Build with ESP-IDF CLI or PlatformIO.  
3. Flash via USB (esptool.py) or OTA updates.  

**Efficiency Tips**:  
- PlatformIO streamlines ESP-IDF/Arduino workflows.  
- Use ESP-Prog or JTAG for advanced debugging.  

### SAMD21/SAMD11 (Atmel/Microchip)  
**Toolchain**:  
- **Primary**: [Atmel/Microchip Studio](https://www.microchip.com/en-us/tools-resources/develop/microchip-studio) (C/C++)  
- **Alternatives**: Arduino IDE (via [SAMD Core](https://github.com/arduino/ArduinoCore-avr))  

**Workflow**:  
1. Code in C/C++ (Microchip Studio) or Arduino.  
2. Build and flash via USB (UF2 bootloader) or EDBG/SWD.  

**Efficiency Tips**:  
- Use Arduino IDE for simplicity; enable verbose upload for debugging.  
- For low-level control, use CMSIS libraries in Microchip Studio.  

### Attiny/AVR128 (AVR Family)  
**Toolchain**:  
- **Primary**: [AVR-GCC](https://www.nongnu.org/avr-libc/) + [AVRdude](https://www.nongnu.org/avrdude/)  
- **Alternatives**: Arduino IDE (via [ATTiny Core](https://github.com/SpenceKonde/ATTinyCore))  

**Workflow**:  
1. Write code in C/C++ or Arduino.  
2. Compile with AVR-GCC or Arduino IDE.  
3. Flash via ISP programmer (e.g., USBasp, Arduino-as-ISP).  

**Efficiency Tips**:  
- Use PlatformIO for project management.  
- For tinyAVR (e.g., ATtiny85), optimize code size with `-Os` compiler flag.  

### General Workflow Optimization Tips  
1. **Unified Environments**:  
   - **PlatformIO** (VS Code) supports all listed MCUs, reducing toolchain setup time.  
   - **Arduino IDE** (with board managers) simplifies entry-level development.  

2. **Debugging Tools**:  
   - **SWD/JTAG**: Use for RP2040, ESP32, SAMD21 (e.g., Segger J-Link, CMSIS-DAP).  
   - **Serial Monitor**: Essential for ESP32/RP2040 debugging.  

3. **Version Control**:  
   - Use `git` for code management; track dependencies (e.g., submodules for Pico SDK).  

4. **Automation**:  
   - Write Makefiles or use PlatformIO scripts for CI/CD pipelines.  

QFP mit Beinchen seitlich  
TQFP ohne Beinchen  
Soic-8 8 Beinchen  
Punkt oder Kerbe kennzeichnen Pin 1

## Putting code onto it
[In-System Programming (ISP)](https://smh-tech.com/corporate-blog/in-system-programming-isp-and-pre-programming-what-is-the-difference/)
- the act of programming a microcontroller while it is already mounted on the board
- Contrary to Pre-Programming. You program the contro

[CMSIS-DAP Devices](https://mtm.cba.mit.edu/2021/2021-10_microcontroller-primer/tools-cmsis-dap/#cmsis-dap-devices) are all devices that can write programs into a microcontroller's memory using JTAG or SWD.
ler before soldering it somewhere.

[Serial Peripheral Interface (SPI)](https://www.geeksforgeeks.org/what-is-serial-peripheral-interface-spi/)
- A standard synchronous serial communication interface used for short-distance communication between a main device and one or more peripheral devices.
- synchronous (needs clock signal), serial communication
- multiple secondary devices are possible
- full-duplex
- pins:
    - MOSI (main out secondary in) 
    - MISO (main in secondary out)
    - SCK (clock)
    - SS (secondary select): select which secondary device to communicate with

Serial Peripheral Data Interface (SPDI)
- do not find any source for it
- [Good Article GERMAN](https://www.mikrocontroller.net/articles/Serial_Peripheral_Interface)

[Joint Test Action Group (JTAG)](https://mtm.cba.mit.edu/2021/2021-10_microcontroller-primer/tools-cmsis-dap/)
- eletronics manufacturers committee
- they developed a protocol with the same name
- mostly used for programming ARM cores
- daisy-chaining possible
- pins
    - TMS: mode select
    - TCLK: clock
    - TDO: data out
    - TDI: data in
    - nRESET: reset (optional)

![](https://mtm.cba.mit.edu/2021/2021-10_microcontroller-primer/10-pin.gif)
      


[Serial Wire Debug (SWD)](https://mtm.cba.mit.edu/2021/2021-10_microcontroller-primer/tools-cmsis-dap/)
- two-pin variant of the JTAG protocol -> replaced JTAG
- daisy-chaining not possible
- most common on newer ARM chips
- pins:
    - swdio: in/out
    - swclk: clock


[Unified Program and Debug Interface (UPDI)](https://onlinedocs.microchip.com/oxy/GUID-19DFE3E8-6314-4CFE-BA69-1357E28C8092-en-US-1/GUID-A2FD739F-A1D8-4C2F-9482-0B8AF9DCF435.html)
- proprietary
- single-wire,
- bi-directional, half-duplex
- asynchronous
- [can use off-the shelf UART adapters](https://mtm.cba.mit.edu/2021/2021-10_microcontroller-primer/tools-updi/)
- used to program AVR microcontrollers released since 2016, ATTINY412, ATTINY164.
- [more detailed blog article](https://www.linkedin.com/pulse/what-updi-unified-program-debug-interface-yamil-garcia)
- debugging is hidden behind a proprietary interface, but even though you can snoop on the protocol with just a serial adapter and even though the large scale structure of the protocol is known too
- [even more detailed article](https://github.com/SpenceKonde/AVR-Guidance/blob/main/UPDI/jtag2updi.md)
- i did not find out what part of the protocol actually is proprietary and what not.

![](https://onlinedocs.microchip.com/oxy/GUID-19DFE3E8-6314-4CFE-BA69-1357E28C8092-en-US-1/GUID-E6D91E8A-2AAD-4BC7-8425-911DF88542DF-low.png)

## Difference between microcontroller and -processor
...

## Programmierer:

### ISP-Programmierer

[AVRISP MKII](https://www.microchip.com/en-us/development-tool/atavrisp2)  
![](https://www.microchip.com/content/dam/mchp/mrt-dam/devtools/1747-atavrisp2.jpg)  
[FabISP](https://fab.cba.mit.edu/content/archive/projects/fabisp/)  
![](https://fab.cba.mit.edu/content/archive/projects/fabisp/fabisp570.jpg)

### JTAG-Programmierer

[ATMEL-ICE](https://www.microchip.com/en-us/development-tool/ATATMEL-ICE)  
![](https://www.microchip.com/content/dam/mchp/mrt-dam/devtools/1949-atatmel-ice.jpg)

[http://pub.fabcloud.io/programmers/summary/](http://pub.fabcloud.io/programmers/summary/)