svd2cpp/README.md

70 lines
2.2 KiB
Markdown
Raw Normal View History

2019-12-02 10:57:23 +00:00
# svd2cpp
2023-03-06 16:52:51 +00:00
2019-12-02 10:57:23 +00:00
Zero-cost abstraction register library generator.
2023-03-06 16:52:51 +00:00
2019-12-02 10:57:23 +00:00
## What is *svd2cpp*?
2023-03-06 16:52:51 +00:00
*svd2cpp* is a generator that parses .svd files provided by ARM chip vendor. It generates header file that allows for reading and writing to microcontroller's registers with zero overhead.
2019-12-02 10:57:23 +00:00
2019-12-02 11:30:07 +00:00
### Benefits
2023-03-06 16:52:51 +00:00
- **Compile-time checking.** This is an aspect that is making this solution better than any other parser/pre-generated header.
- You won't be able to write to wrong register.
- You won't be able to write wrong value (i.e. 0b1011 to 3-bit field) to register.
- You can't read from write-only or write to read-only register. Any attempt to do something wrong will succeed in error at **compile-time** - no more runtime debugging to find out misspelling errors!
- **Zero-cost abstraction.** Another strong aspect of headers generated by *svd2cpp* is that using it in code will result in zero overhead because all of the checking is done at compile-time.
- **Portability.** As long as manufacturer provides .svd files in CMSIS-SVD format (and most major manufacturers of Cortex-M based chips does), you can use it with this parser.
2019-12-02 11:30:07 +00:00
2019-12-02 10:57:23 +00:00
## How to get *svd2cpp*?
2023-03-06 16:52:51 +00:00
Clone the repository, get submodules, compile.
2019-12-02 10:57:23 +00:00
2023-03-06 16:52:51 +00:00
```bash
~$ git clone https://github.com/supleed2/svd2cpp.git
~$ cd svd2cpp
~/svd2cpp$ git submodule init && git submodule update
~/svd2cpp$ mkdir build && cd build
~/svd2cpp/build$ cmake ..
~/svd2cpp/build$ make
```
2019-12-02 10:57:23 +00:00
## How to use *svd2cpp*?
2023-03-06 16:52:51 +00:00
```bash
2019-12-02 10:57:23 +00:00
./svd2cpp -i svdFile.svd -o generatedHeader.hpp
```
2019-12-02 11:11:43 +00:00
## How to use generated header?
2023-03-06 16:52:51 +00:00
2019-12-02 11:11:43 +00:00
After including header in your code, you can use all features such as *set*, *reset*, *read*.
Syntax is quite simple and easy to use:
2023-03-06 16:52:51 +00:00
2019-12-02 11:11:43 +00:00
```cpp
2019-12-02 11:33:24 +00:00
operation<PERIPHERAL::REGISTER::FIELD>();
2019-12-02 11:11:43 +00:00
```
2019-12-02 11:30:07 +00:00
### Examples:
2019-12-02 11:33:24 +00:00
In peripheral USART1: Set bit UE(USART enable) in CR1(Control Register 1):
2023-03-06 16:52:51 +00:00
2019-12-02 11:11:43 +00:00
```cpp
set<USART1::CR1::UE>();
```
2019-12-02 11:33:24 +00:00
In peripheral USART1: Reset bit UE(USART enable) in CR1(Control Register 1):
2023-03-06 16:52:51 +00:00
2019-12-02 11:11:43 +00:00
```cpp
reset<USART1::CR1::UE>();
```
2019-12-02 11:33:24 +00:00
In peripheral DMA1: Read TCIF1(Channel 1 Transfer Complete flag) in ISR:
2023-03-06 16:52:51 +00:00
2019-12-02 11:11:43 +00:00
```cpp
bool transferComplete = read<DMA1::ISR::TCIF1>();
```
2019-12-02 11:33:24 +00:00
In peripheral DMA1: Set MA(Memory address) for CMAR2(DMA channel 2 memory address register):
2023-03-06 16:52:51 +00:00
2019-12-02 11:11:43 +00:00
```cpp
set<DMA1::CMAR2::MA>(0xDEADBEEF);
```