#include "stm32c0xx_hal.h"
void SystemClock_Config(void);
void buzz(int duration_ms);
int main(void)
{
HAL_Init();
SystemClock_Config();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; // PA0 connected to LED
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
while (1)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET); // LED ON (LOW)
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET); // LED OFF (HIGH)
HAL_Delay(500);
uint32_t cycles = 200 * 2; // Creates ~2kHz tone
for(uint32_t i = 0; i < cycles; i++)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);
HAL_Delay(1);
}
}
}