Skip to content

Commit

Permalink
#tinygpmp: tinkering with STM32
Browse files Browse the repository at this point in the history
  • Loading branch information
akielaries committed Apr 1, 2024
1 parent b21809f commit 8600808
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tinygpmp/BLINK_WKG.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This is the symbol defined in the linker script.
extern unsigned long _end_of_ram;

// We'll implement main a bit further down but we need the symbol for
// the initial program counter / start address.
void main();

// This is our interrupt vector table that goes in the dedicated section.
__attribute__ ((section(".interrupt_vectors"), used))
void (* const interrupt_vectors[])(void) = {
// The first 32bit value is actually the initial stack pointer.
// We have to cast it to a function pointer since the rest of the array
// would all be function pointers to interrupt handlers.
(void (*)(void))((unsigned long)&_end_of_ram),

// The second 32bit value is the initial program counter aka. the
// function you want to run first.
main
};

void wait() {
// Do some NOPs for a while to pass some time.
for (unsigned int i = 0; i < 2000000; ++i) __asm__ volatile ("nop");
}

void main() {
// Enable port C clock gate.
*((volatile unsigned int *)0x40021018) |= (1 << 4);

// Configure GPIO C pin 13 as output.
*((volatile unsigned int *)0x40011004) = ((0x44444444 // The reset value
& ~(0xfU << 20)) // Clear out the bits for pin 13
| (0x3U << 20)); // Set both MODE bits, leave CNF at 0

while (1) {
// Set the output bit.
*((volatile unsigned int *)0x40011010) = (1U << 13);
wait();
// Reset it again.
*((volatile unsigned int *)0x40011010) = (1U << 29);
wait();
}
}

0 comments on commit 8600808

Please sign in to comment.