/* * Sound the speaker at 440Hz * * The speaker is connected to PB2. * Default clock 16 MHz is used. * Delay loop is used for time interval. The number * of delay cycles is determined empirically. */ #include "stm32f4xx.h" void delay(void); int main(void) { RCC->AHB1ENR |= 2; /* enable GPIOB clock */ GPIOB->MODER &= ~0x00000030; /* clear pin mode */ GPIOB->MODER |= 0x00000010; /* set pins to output mode */ while (1) { GPIOB->BSRR = 0x00000004; /* turn on */ delay(); GPIOB->BSRR = 0x00040000; /* turn off */ delay(); } } /* 16 MHz SYSCLK */ void delay(void) { int i; for (i = 0; i < 3630; i++) ; }