Clean the blinky sample

This commit is contained in:
Romain Goyet
2015-05-03 12:51:30 +02:00
parent 00dc4f263a
commit 9e64008a69

View File

@@ -10,58 +10,28 @@ int main(int argc, char * argv[]) {
// GPIO are grouped by letter, and GPIO "G" live on the "AHB1" bus
// (this is documented in the STM32F4 reference mnual, page 65)
// More specifically, the boundary addresses for GPIOC are
// 0x4002 1800 - 0x4002 1BFF
//
// Step 1 : Enable clock in RCC_AHBxENR
RCC_AHB1ENR->GPIOGEN = 1;
// Step 2 : Configure the GPIO pin
// Set the mode to general purpose output
// GPIOG_MODER, bit 26 and 27 = pin13
// GPIOG_MODER, bit 28 and 29 = pin14
// A value of 0,0 for these two bits means input (reset state)
// and 0,1 for these two bits means output (which we want)
long * GPIOG_MODER = (long *)0x40021800; // GPIOC register
*GPIOG_MODER &= ~(1 << 27); // Clear bit 27 of GPIOG_MODER
*GPIOG_MODER |= (1 << 26); // Set bit 26 of RCCAHB1ENR
*GPIOG_MODER &= ~(1 << 29); // Clear bit 29 of GPIOG_MODER
*GPIOG_MODER |= (1 << 28); // Set bit 28 of RCCAHB1ENR
// Step 2 : Configure the GPIO pin to "general purpose output
GPIO_MODER(GPIOG)->MODER13 = GPIO_MODE_OUTPUT;
GPIO_MODER(GPIOG)->MODER14 = GPIO_MODE_OUTPUT;
// Per doc, the output is push-pull by default (yay)
// And we should also set the output speed, but really
// we don't care (we're doing something super slow)
long delay = 10000;
long * GPIOG_PUPDR = (long *)(0x40021800 + 0xC); // Per doc, ref man page 283
long * GPIOG_ODR = (long *)(0x40021800 + 0x14); // per doc, data register of GPIO G
while (1) {
/*
// Pull-up pin 13
*GPIOG_PUPDR &= ~(1 << 27);
*GPIOG_PUPDR |= (1 << 26);
// Pull-up pin 14
*GPIOG_PUPDR &= ~(1 << 29);
*GPIOG_PUPDR |= (1 << 28);
*/
*GPIOG_ODR = 0x2000;
GPIO_ODR(GPIOG)->ODR13 = 0;
GPIO_ODR(GPIOG)->ODR14 = 1;
sleep(100000);
*GPIOG_ODR = 0x4000;
/*
// Pull-down pin 13
*GPIOG_PUPDR &= ~(1 << 26);
*GPIOG_PUPDR |= (1 << 27);
// Pull-down pin 14
*GPIOG_PUPDR &= ~(1 << 28);
*GPIOG_PUPDR |= (1 << 29);
*/
GPIO_ODR(GPIOG)->ODR13 = 1;
GPIO_ODR(GPIOG)->ODR14 = 0;
sleep(100000);
}