HWA
Bare metal programming with style
hwa/st/stm32/examples/02-2-clocks/main.c

This program:

main.c
/* This file is part of the HWA project.
* Copyright (c) 2017 Christophe Duparquet.
* All rights reserved. Read LICENSE.TXT for details.
*/
#include BOARD_H
#define SYSHZ (36*1000*1000) // Desired frequency for the SYSCLK signal
#define AHBHZ (9*1000*1000) // Desired frequency for the core (and systick)
#define PERIOD 0.5 // Blinking period
int main ( )
{
hwa( begin, reset );
/* Start the high-speed external oscillator.
*/
hwa( power, hse, on );
/* Configure the PLL source and multiplier (must be done before it is enabled).
*/
hwa( configure, pll,
input, hse/2,
multiplier, SYSHZ/HW_DEVICE_HSEHZ );
/* Prepare the connection of the sysclk to the pll. The hardware will wait for
* the PLL to be locked before actually switching.
*/
hwa( connect, sysclk, pll );
hwa( commit );
/* Turn the PLL on.
*/
hwa( power, pll, on );
hwa( commit );
/* Wait for the PLL to be locked.
*/
while ( ! hw(stat,pll).ready ) {}
/* Now that the SYSCLK is driven by the PLL, the HSI can be stopped.
*/
hwa( power, hsi, off );
/* Configure the AHB
*/
hwa( clock, ahb, sysclk / (SYSHZ/AHBHZ) );
hwa( commit );
/* Configure the GPIO pin
*/
hwa( power, (LED1,port), on );
hwa( commit );
hwa( configure, LED1,
mode, digital_output,
frequency, lowest );
hwa( commit );
/* Wait for the HSI to actually stop.
*/
while ( hw(stat,hsi).ready ) {}
for(;;) {
hw( toggle, LED1 );
hw_waste_cycles( PERIOD*AHBHZ/2 );
}
}
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
HW_DEVICE_HSEHZ
#define HW_DEVICE_HSEHZ
Definition: bluepill.h:38
LED1
#define LED1
X.
Definition: bluepill.h:56
hw_waste_cycles
#define hw_waste_cycles(n)
Definition: hwa_2.h:98