Skip to content

Instantly share code, notes, and snippets.

@reportingsjr
Created October 16, 2014 04:14
Show Gist options
  • Save reportingsjr/4e3696c565000a31bd0c to your computer and use it in GitHub Desktop.
Save reportingsjr/4e3696c565000a31bd0c to your computer and use it in GitHub Desktop.
STM32 hello world
#include "stm32f10x.h"
int main(void) {
int delay;
// Enable the clock for port C gpio
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
// Configure port C, pin 8 as a push pull output
GPIOC->CRH = (GPIOC->CRH & 0xFFFFFFF0) | 0x00000002;
for(;;){
// Set the LED as on for 500k cycles
for(delay = 0; delay < 500000; delay++) {
GPIOC->BSRR = (1 << 8);
}
// Set the LED as off for 500k cycles
for(delay = 0; delay < 500000; delay++) {
GPIOC->BRR = (1 << 8);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment