Configuración de GPIO y reloj de STM32F427VG

Soy muy nuevo en proyectos STM32 y es la primera vez que escribo un programa con STM32. Solía ​​programar con AVR y ahora debo progresar a STM32. Tengo una placa con STM32F427VG sin ningún XTAL externo. Escribí el siguiente código para hacer que un simple LED parpadee:

#include "stm32f4xx_conf.h"
#include "stm32f4xx.h"
int main(void)
{
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    GPIO_InitTypeDef GPIO_InitDef; //Where GPIO_InitDef is variable to work with struct
    GPIO_InitDef.GPIO_Pin = GPIO_Pin_4 ;
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitDef.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitDef);
    GPIO_SetBits(GPIOA, GPIO_Pin_4);
    GPIO_ResetBits(GPIOA, GPIO_Pin_4);
    int i;


  while(1)
  {
    GPIO_SetBits(GPIOA, GPIO_Pin_4);
    for (i = 0; i < 500000; i++);
    GPIO_ResetBits(GPIOA, GPIO_Pin_4);
    for (i = 0; i < 500000; i++);

  }
}

Uso Embitz para compilar mi código. Para configurar el reloj interno utilizo la siguiente configuración:

ingrese la descripción de la imagen aquí

Luego presiono ejecutar y luego generar. Luego copio el system_stm32f4xxarchivo generado y lo reemplazo con el archivo predeterminado system_stm32f4xxen el proyecto.

Aún así, no puedo ver ningún cambio en el LED.

Sé que soy muy nuevo en los proyectos STM32, así que lo más probable es que esta pregunta sea muy simple para cualquiera. Gracias si alguien me ayuda a encontrar el problema.

No tengo suficiente representante para comentar aquí, pero ¿está seguro de que el compilador no está optimizando sus 'bucles de retardo' para que no existan con el resultado de que el LED parpadea más rápido de lo que puede ver?
La optimización es probablemente el problema, esto debería codificarse con llamadas de suspensión para que sea independiente de la velocidad del procesador de todos modos.
No veo en el código donde inicializa el reloj del sistema, usando Systeminituna llamada o similar, entonces necesita manejar el controlador Systick; de lo contrario, puede esperar hasta Navidad y no sucederá nada. :)

Respuestas (2)

Debe hacer más que reemplazar el archivo stm32f4xx. Consulte http://clockspeeds.blogspot.com/2013/01/stm32f4-discovery-clock-frequency.html . En particular, debe trabajar un poco en el archivo startup_stm32f4xx.c.

Desde ese sitio:

> STEP 3: In stm32f4xx.h file ensure HSE (external clock) value is 8 MHz
> 
> 
> #if !defined  (HSE_VALUE)   #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
> #endif /* HSE_VALUE */
> 
> 
> STEP 4: In startup_stm32f4xx.c file change comment on SystemInit()
> function
> 
> 
> /*----------Function
> prototypes-----------------------------------------------*/ extern int
> main(void);           /*!< The entry point for the application.    */
> //extern void SystemInit(void);    /*!< Setup the microcontroller
> system(CMSIS) */ void Default_Reset_Handler(void);   /*!< Default
> reset handler                */ static void Default_Handler(void); 
> /*!< Default exception handler            */
> 
> to
> 
> /*----------Function
> prototypes-----------------------------------------------*/ extern int
> main(void);           /*!< The entry point for the application.    */
> extern void SystemInit(void);    /*!< Setup the microcontroller
> system(CMSIS) */ void Default_Reset_Handler(void);   /*!< Default
> reset handler                */ static void Default_Handler(void); 
> /*!< Default exception handler            */
> 
> STEP 5: On the same file down under there will be a function
> 
> void Default_Reset_Handler(void)
> 
> after assembly code towards the end add a line of code calling
> SystemInit() BEFORE calling main() ie, change to
> 
> SystemInit(); main();
> 
> That`s it! now in main function we can add 
> 
> RCC_HSEConfig(RCC_HSE_ON); while(!RCC_WaitForHSEStartUp()) { }
¿Dónde está "startup_stm32f4xx.c"? No puedo encontrarlo en Embitz. Sé que este archivo estaba en Keil pero no puedo encontrarlo en Embitz
no se embitz

Debe usar el software CubeMX, fue diseñado para la generación de código de hardware para la familia de mcu STM32. Puede configurar fácilmente el reloj del sistema, gpio, spi, ethernet, etc. con su GUI.

http://www.st.com/en/desarrollo-herramientas/stm32cubemx.html