HWA
Bare metal programming with style
hwa/st/stm32/examples/04-1-counter/main.c

This program blinks a LED using a counter reload event.

main.c
/* This file is part of the HWA project.
* Copyright (c) 2020 Christophe Duparquet.
* All rights reserved. Read LICENSE.TXT for details.
*/
#include BOARD_H
#define AHBHZ HW_DEVICE_HSIHZ // AHB frequency
#define COUNTER counter2
#define PERIOD 0.25 // Blinking period
/* The IRQ is used only to wake the core up.
*/
HW_ISR(COUNTER)
{
hw( clear, (COUNTER,irq) );
}
int main ( )
{
hwa( begin, reset );
/* Power the controllers we use
*/
hwa( power, (LED,port), on );
hwa( power, COUNTER, on );
hwa( commit );
/* Configure GPIOs
*/
hwa( configure, LED, mode, digital_output, frequency, lowest );
hwa( commit );
/* Configure the counter
*/
hwa( configure, COUNTER,
mode, counter,
clock, from_apb1_psc,
direction, up_loop,
prescaler, AHBHZ*0.001 - 1, // 1 ms clock period
reload, PERIOD/2 / 0.001 - 1,
run, yes );
hwa( commit );
hw( enable, (nvic,COUNTER) );
hw( enable, (COUNTER,irq) );
/* Toggle the LED between sleeps
*/
for(;;) {
hw( wait, irq );
hw( toggle, LED );
}
}
hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523
LED
#define LED
X.
Definition: bluepill.h:55
HW_ISR
#define HW_ISR(...)
Definition: hwa_interrupts.h:80