Created
July 14, 2015 18:50
-
-
Save WoodyWoodsta/8562c5c83bd199776597 to your computer and use it in GitHub Desktop.
LED Blink example using register accessing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paste this at the top of your main file | |
#define EVER ;; | |
#define RCC_PERHIPHBASE 0x40021000 | |
#define RCC_AHBENR (RCC_PERHIPHBASE + 0x14) | |
#define GPIOB_PERIPHBASE 0x48000400 | |
#define GPIOB_MODER (GPIOB_PERIPHBASE + 0x00) | |
#define GPIO_ODR (GPIOB_PERIPHBASE + 0x14) | |
// Paste this in your main() function | |
*((uint32_t *)RCC_AHBENR) |= 0b1000000000000000000; // Enable the GPIO Peripheral Clock (AHB Bus) | |
*((uint32_t *)GPIOB_MODER) |= 0b01; // Set the pin mode of port B pin 1 to GENERAL PURPOSE OUTPUT MODE | |
for (EVER) { | |
*((uint32_t *)GPIO_ODR) ^= 0b1; // Toggle port B pin 1 by XOR-ing it | |
// Pause for a bit by looping | |
uint32_t i; | |
for (i = 0; i < 100000; i++) { | |
__asm("nop"); // This is the "correct" way to do nothing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment