#include <stdint.h>
// Base addresses for RCC and GPIOA
#define RCC_BASE 0x40021000
#define GPIOA_BASE 0x40010800
// RCC Registers
#define RCC_APB2ENR *(volatile uint32_t *)(RCC_BASE + 0x18)
// GPIOA Registers
#define GPIOA_CRL *(volatile uint32_t *)(GPIOA_BASE + 0x00)
#define GPIOA_ODR *(volatile uint32_t *)(GPIOA_BASE + 0x0C)
void delay(volatile uint32_t count) {
while (count--) {
// Simple delay loop
}
}
int main(void) {
// 1. Enable clock for GPIOA
RCC_APB2ENR |= (1 << 2); // Set bit 2 to enable GPIOA clock
// 2. Configure PA0 as output (General purpose output push-pull, max speed 2 MHz)
GPIOA_CRL &= ~(0xF << (0 * 4)); // Clear configuration for PA0
GPIOA_CRL |= (0x2 << (0 * 4)); // Set PA0 to output mode, max speed 2 MHz
while (1) {
// 3. Toggle PA0
GPIOA_ODR ^= (1 << 0); // Toggle bit 0 (PA0)
// 4. Add delay
delay(1000000); // Adjust the value for desired delay duration
}
return 0;
}
Loading
stm32-bluepill
stm32-bluepill