#include <stdio.h>
#include "stm32c0xx.h"
// 簡單的延遲函式
void delay(volatile uint32_t count) {
while (count--) {
__NOP();
}
}
int main(void) {
// 1. 啟用 GPIOA 的時脈 (C0 晶片使用的是 IOPENR,而非 AHBENR)
RCC->IOPENR |= RCC_IOPENR_GPIOAEN;
// 2. 將板載 LED 引腳 (PA5) 設定為 General Purpose Output Mode
// 每個引腳佔 2 位元。PA5 對應第 10、11 位元。
GPIOA->MODER &= ~(3U << (5 * 2)); // 先將 10, 11 位元清零
GPIOA->MODER |= (1U << (5 * 2)); // 設定為 01 (通用輸出模式)
// 透過 Wokwi 下方的 Serial Monitor 印出初始化訊息
printf("STM32 C031C6 Bare-Metal System Online!\n");
while (1) {
// 3. 翻轉 PA5 引腳狀態 (Toggle LED)
GPIOA->ODR ^= (1U << 5);
// 4. 延遲 (調整數值可改變閃爍速度)
delay(100000);
}
return 0;
}