int main ( ) { hwa_begin_from_reset(); hwa( power, HW_RELATIVE(LED1,port), on ); hwa( configure, LED1, mode, digital, direction, output, frequency, 50MHz ); hwa_commit(); for(;;) { hwa( write, LED1, 1 ); hwa_commit(); hw_waste_cycles( PERIOD/2 * HW_DEVICE_HSIHZ ); hwa( write, LED1, 0 ); hwa_commit(); hw_waste_cycles( PERIOD/2 * HW_DEVICE_HSIHZ ); } }
int main ( ) { hwa_begin_from_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, source, 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( turn, 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( configure, ahb, clock, sysclk, prescaler, SYSHZ/COREHZ ); hwa_commit(); /* Configure the GPIO pin */ hwa( power, HW_RELATIVE(LED1,port), on ); hwa_commit(); hwa( configure, LED1, mode, digital, direction, output, frequency, 50MHz ); hwa_commit(); /* Wait for the HSI to actually stop. */ while ( hw(stat,hsi).ready ) {} for(;;) { hw( toggle, LED1 ); hw_waste_cycles( PERIOD*COREHZ/2 ); } }
int main ( ) { hwa( begin_from_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. * * Alternately, we could check ourselves the clocks: * while ( !hw(stat,hse).ready ) {} : waits for the HSE to be stable. * while ( !hw(stat,pll).ready ) {} : waits for the PLL to be locked. */ hwa( power, hse, on ); hwa( connect, pll, hse ); hwa( write, pll, (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( turn, pll, on ); hwa( commit ); /* Power the GPIO port */ hwa( power, (LED1,port), on ); /* Configure the GPIO pin */ hwa( configure, LED1, mode, digital_output, frequency, lowest ); hwa( commit ); for(;;) { hw( toggle, LED1 ); hw_waste_cycles( PERIOD/2 * SYSHZ ); } }