Skip to main content

D-RAL - Device Register Access Layer

Project description

Logo

D-RAL - Device Register Access Layer

PyPI PyPI - License Supported Python Versions PyPI - Format PyPI - Wheel


What is it?

D-RAL is a register access code generator for any device, chip or embedded system. The goal is to provide a simple and consistent way to access the internal registers of the device. Every embedded project requires the programmer to manipulate registers. D-RAL is trying to address this and provide an easy way to access registers. The main motivation for creating this project was to design a register access layer for modern C++ programming language.

Main functionality

Main functionality is to generate a register access layer based on the device register description input for the C++ programming language. Currently, D-RAL only supports the SVD format as an input file with a description of the registers. SVD is an ARM-created format that formalizes the description of the system inside microcontrollers based on Arm Cortex-M processors, specifically the memory mapped registers of peripherals. It is a widely used format by many companies. It is also possible to use your own register description format in D-RAL by writing an adapter that translates it to know for the D-RAL form. More about this on the wiki page. D-RAL generates a set of header files that you can simply copy and paste into your existing project.

Example

Let's take the STM32F411 microcontroller and its general-purpose timers as an example. We want to configure the TIM2 timer as a countdown timer. To do this, we need to set the direction bit in one of the timer's control registers.

STM32F411 Tim2 Control Register

We can accomplish this in C++ by utilizing raw pointers:

constexpr uint32_t Tim2Cr1Address = 0x4000'0000;
constexpr uint32_t Tim2Cr1DirPos = 4;
constexpr uint32_t Tim2Cr1DirMask = 0x1;

volatile uint32_t* Tim2Cr1Reg = reinterpret_cast<volatile uint32_t*>(Tim2Cr1Address);
*Tim2Cr1Reg = (*Tim2Cr1Reg & ~(Tim2Cr1DirMask << Tim2Cr1DirPos)) | ((1 & Tim2Cr1DirMask) << Tim2Cr1DirPos);

Or we can use D-RAL:

dral::stm32f411::tim2::cr1::dir::write(1);

This is a brief example to demonstrate D-RAL's purpose. More information can be found on the Wiki page.

Main benefits of using D-RAL:

  • Simple and clean syntax,
  • Less code,
  • No need to warry about bit shifting and masking,
  • No run-time overhead

Installing

The easiest way to install D-RAL is with pipx.

pipx install dral

You can also install D-RAL with pip:

pip install dral

Whichever method you use, you should have a dral command on your path.

Usage

D-RAL is a CLI tool that takes two positional arguments

dral [OPTIONS] INPUT OUTPUT
  • INPUT - path to external device description file
  • OUTPUT - a path where D-RAL files will be generated.

Extra functionality

The D-RAL generator is flexible enough to be easily adapted to generate register access layers for other programming languages or for other use cases. More about it on the Wiki page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dral-0.5.2.tar.gz (140.7 kB view hashes)

Uploaded Source

Built Distribution

dral-0.5.2-py3-none-any.whl (164.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page