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

This program blinks a LED after it has configured the system clock to use the PLL driven by the HSE.

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 );
/* After RESET, the core is clocked at 8 MHz by the HSI RC oscillator.
*
* * Start the high-speed external oscillator.
* * Configure the PLL source and multiplier (must be done before it is
* enabled).
* * Prepare the connection of the sysclk to the pll. The hardware waits for
* the clocks to be stable before switching.
*/
hwa( power, hse, on );
hwa( configure, pll,
input, hse,
multiplier, SYSHZ/HW_DEVICE_HSEHZ );
hwa( connect, sysclk, pll );
hwa( commit );
/* Now turn the PLL on and the hardware will use it as sysclk when the PLL is
* locked.
*/
hwa( power, pll, on );
hwa( commit );
/* Power the GPIO port
*/
hwa( power, (LED,port), on );
/* Configure the GPIO pin
*/
hwa( configure, LED,
mode, digital_output,
frequency, lowest );
hwa( commit );
for(;;) {
hw( toggle, LED );
hw_waste_cycles( PERIOD/2 * SYSHZ );
}
}
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
LED
#define LED
X.
Definition: bluepill.h:55
hw_waste_cycles
#define hw_waste_cycles(n)
Definition: hwa_2.h:98