AnsweredAssumed Answered

STM32F405R won't blink.

Question asked by wolff.roger on Sep 7, 2013

Update: It blinks!

It wasn't booting at all. I had made a mistake with the boot configuration. It was booting from SRAM when I thought it would boot from flash. Now that I've patched the board to be able to boot from flash, it will run the code....

For those who want to laugh at my original message, here it is:

--------------------------

Hi,
I've desgined my own STM32F4xxR board. It currently houses an F405.

I've planned on developing through USB/DFU. That part works. I can download a program to my STM32F4 without a problem. However, the first program I tried doesn't work at all: the blink-the-leds program fails.

I have a led on PA0 (and PA1 and PA2).  I also have STM32F4DISCOVERY boards. Programs like this usually work there....

My guess is that somehow something is not getting initialized that should be initialized. (At first I had problems with GPIO ports not doing what I wanted, but that turned out to be that the GPIO module's clock wasn't running).


#include <libopencm3/stm32/f4/rcc.h>
#include <libopencm3/stm32/f4/gpio.h>

static void gpio_setup(void)
{
/* Enable GPIOD clock. */
/* Manually: */
// RCC_AHB1ENR |= RCC_AHB1ENR_IOPDEN;
/* Using API functions: */
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);

/* Set GPIO12 (in GPIO port D) to 'output push-pull'. */
/* Manually: */
// GPIOD_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
// GPIOD_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
/* Using API functions: */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO0);
}

int main(void)
{
int i;

gpio_setup();

/* Blink the LED (PC8) on the board. */
while (1) {
/* Manually: */
// GPIOD_BSRR = GPIO12;         /* LED off */
// for (i = 0; i < 1000000; i++)        /* Wait a bit. */
//      __asm__("nop");
// GPIOD_BRR = GPIO12;          /* LED on */
// for (i = 0; i < 1000000; i++)        /* Wait a bit. */
//      __asm__("nop");

/* Using API functions gpio_set()/gpio_clear(): */
// gpio_set(GPIOD, GPIO12);     /* LED off */
// for (i = 0; i < 1000000; i++)        /* Wait a bit. */
//      __asm__("nop");
// gpio_clear(GPIOD, GPIO12);   /* LED on */
// for (i = 0; i < 1000000; i++)        /* Wait a bit. */
//      __asm__("nop");

/* Using API function gpio_toggle(): */
gpio_toggle(GPIOD, GPIO12);     /* LED on/off */
gpio_toggle(GPIOA, GPIO0);      /* LED on/off */
for (i = 0; i < 1000000; i++)   /* Wait a bit. */
__asm__("nop");
}

return 0;
}


Outcomes