Files
AVRDxBlink/README.md
T
2026-06-16 20:13:26 +02:00

57 lines
3.8 KiB
Markdown

# Emacs AVR IDE Template
This repository is a complete template to use **Emacs** as a lightweight, yet extremely powerful IDE for developing **AVR microcontrollers** (specifically modern AVR Dx/Ex series, but also fully backwards compatible with older series).
It uses **CMake** as the build system and relies on the combination of `avr-gcc`, `avrdude` (with ELF support), and `clangd` (Language Server) to enable code completion, fast compilation, and direct flashing from within the editor.
## System Prerequisites
* `avr-gcc` (AVR Toolchain Compiler)
* `avrdude` (Version 7.0 or higher highly recommended for native ELF support)
* `clangd` (For code completion, warnings, and error display in Emacs)
* `cmake` (Build System)
* `ripgrep` (Used for extremely fast searching in Emacs)
* Device Packs for modern AVRs: [Microchip Packs Repository](http://packs.download.microchip.com/)
## Emacs Packages
To achieve the perfect IDE feel, this template relies on several proven Emacs packages:
* **Projectile**: For project management (automatically finds the root folder based on `CMakeLists.txt`).
* **Eglot**: As an integrated C/C++ Language Server Client (communicates with `clangd` in the background).
* **Corfu**: For the modern auto-completion popup directly at the cursor.
* **Vertico, Orderless & Consult**: For smart, fault-tolerant searching across the entire project (including Ripgrep integration).
* **Doom Themes**: For an eye-friendly, modern dark mode.
## Emacs Configuration Installation
If you are setting up Emacs from scratch, you can use the provided example file:
1. Copy the file `init-example.el` to your Emacs configuration directory (usually `~/.emacs.d/` or `~/.config/emacs/`).
2. Rename it to `init.el`.
```bash
cp init-example.el ~/.emacs.d/init.el
```
3. Restart Emacs. On the first launch, all missing packages will automatically be downloaded and installed from MELPA.
## Changing the Microcontroller (MCU)
This project is configured for the **AVR128DB28** by default. If you want to use a different chip:
1. Open the file `CMakeLists.txt`.
2. Change the value of the `MCU` variable (e.g., to `atmega328p` or `avr128da28`).
3. If necessary, change the `DEVICE_PACK_DIR`. (For modern AVR Dx/EA series, the Device Pack from Microchip is required. For older models like the ATmega, you can often leave this path empty).
4. Press **F5** in Emacs to do a fresh configure and build.
*(CMake will regenerate the `compile_commands.json` file, allowing `clangd` to immediately know the registers and pins of the new chip for auto-completion!)*
## Development Workflow & Shortcuts
As soon as you open a `.c` or `.h` file in the project, Projectile will automatically detect the project, and Eglot will start the Language Server in the background.
The most important shortcuts for **project management** (via Projectile & Consult):
* `C-c p f`: Find file in project (Fuzzy Search).
* `C-r`: Search for text across the project (Consult Ripgrep - extremely fast!).
* `C-c p p`: Switch between different, locally stored projects.
The shortcuts for **building and flashing** (configured via F-keys in `init.el`):
* **`F5`**: **Clean Build**. Radically deletes the cache and completely rebuilds the project (Compiles including linker garbage collection for minimal size).
* **`F6`**: **Flash Code**. Flashes only the program code (Flash memory) via Avrdude. *(Standard command during development)*
* **`Strg + F6`**: **Flash Code & EEPROM**. Flashes the code and the EEPROM data.
* **`F7`**: **Read Fuses**. Reads the fuses from the microcontroller and displays them in the Emacs Compile window.
* **`Strg + F7`**: **Flash Fuses**. Writes the fuses directly defined in the C software (via `<avr/fuse.h>`) to the chip.
*Note: Since we use the modern ELF format, manually generating old `.hex` files is completely obsolete.*