/hwa

HWA is a set of C definitions designed for bare metal programming with a pleasant style.

Primary LanguageCOtherNOASSERTION

HardWare Advanced

HWA stands for HardWare Advanced. HWA is a set of C definitions designed for bare metal programming with a pleasant style.

To give you an idea, the following code blinks a LED connected to an STM32F103RBT6 using Systick interrupts and sleeping mode:

#include <hwa/stm32f103rbt6.h>

#define AHBHZ   HW_DEVICE_HSIHZ         // The HSI frequency (8 MHz)
#define LED     pa2
#define PERIOD  0.5                     // Blinking period in seconds

HW_ISR( (systick,irq) ) {}              // The IRQ is used only to wake the core up.

int main ( )
{
  hwa( begin, reset );                  // Record the configuration in a context

  hwa( power, (LED,port), on );         // Power the LED port
  hwa( commit );                        // Write the context in the hardware

  hwa( configure, LED,                  // Configure the LED pin
       function,  gpio,                 //   Optional argument
       mode,      digital_output,       //   Mandatory argument
       frequency, lowest );             //   Optional argument

  hwa( configure, systick,              // Configure the system tick timer
       clock,     ahb/8,                //   Clock it at 1/8th the AHB frequency
       reload,    PERIOD/2*AHBHZ/8-1,
       run,       yes );

  hwa( enable, (systick,irq) );         // Enable Systick IRQs (to wake the core up)

  hwa( commit );                        // Write all that into the hardware

  for(;;) {
    hw( wait, irq );                    // wait event is OK too.
    hw( toggle, LED );                  // Toggle the LED at wake-up
  }
}

The resulting binary is 402 bytes long: 94 bytes of code + 308 bytes of vectors.

HWA in short

HWA provides:

  • a set of objects that represent the hardware,
  • the generic instruction, hw(...), that acts on these objects using various types and numbers of mandatory and optionnal symbolic arguments,
  • the generic instruction, hwa(...), that provides a transactional processing mechanism that allows further optimization of the binary code produced,
  • an error-checking mechanism that produces meaningful messages to help the developer quickly solve the problems.

Performances and compatibility

Any C compiler compatible with the C11 standard should be able to compile HWA code.

Because it is not a library, using HWA does not affect negatively the efficiency of the binary code produced either in terms of size, execution speed, or memory used. HWA helps the compiler's optimizers produce a binary that is as efficient as if the developer had written smart accesses to hardware registers himself.

HWA relies heavily on macro definitions to implement object-oriented generic instructions. As the C preprocessor can be used to parse assembly language code, a few features of HWA can be used for assembly programming. The implementation of a software UART for Atmel AVR microcontrollers (see atmel/avr/swuarta/) and the Diabolo bootloader (see atmel/avr/examples/diabolo) are examples of such a usage.

Examples

A set of commented examples is provided. You'll find example projects in each vendor/architecture/examples/ directory (e.g. atmel/avr/examples/) where a README.md file that explains how to compile the projects.

Documentation

A ready-made documentation is available here. You can start with the Using HWA page or browse the examples.

Building your own copy of the documentation from the sources requires Doxygen and Gnu Make. Run make doc in the HWA directory, then open the doxygen/html/index.html page.

Supported hardware

  • HWA supports almost fully:

    • Atmel AVR:
      • ATtinyX4: ATtiny24, ATtiny24A, ATtiny44, ATtiny44A, ATtiny84, ATtiny84A
      • ATtinyX5: ATtiny25, ATtiny45, ATtiny85,
      • ATmegaX8: ATmega328P
  • Very partially supported:

    • Atmel AVR:
      • ATmega32U4: ATmega32U4 needs probably a few updates
    • ST STM32:
      • STM32F103: STM32F103C8T6, STM32F103RBT6, STM32F103VCT6
    • Espressif
  • Support for a few "external" devices has been started:

Status

WARNING! The development of HWA is very chaotic and this project is subject to heavy changes of the code base.

Hosting, feedback

HWA is hosted on Github.

Feedbacks will be greatly appreciated. For any bug report, question or suggestion, please open a new issue on Github, or use my gmail address (duparq) and put HWA in the object.

License

HWA is free software. See the license page for license information.