AnsweredAssumed Answered

stm32f429-disco and beginners question

Question asked by hwe on Jun 20, 2014
Latest reply on Jun 23, 2014 by hwe
Hi,
as a beginner I am starting freshly with stm32 programming on a stm32f429-disco board using eclipse with the gnu-arm-plugin and the gnu-arm-eabi toolchain in linux (toolchain is working - the simple LED-blinky example works).


Problem:
When I modify the source-code of the blinky example (condensing all settings into the "main.c" for better understanding) and  trying to blink a LED, the "while(1)" loop seems to run only once and is not repeated - Why ?
I also have this problem with other examples trying to read/write GPIOs.
Is it a problem of the eclipse-toolchain or a programming issue ?


Here the modified blinky-code:

//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
 
// ----------------------------------------------------------------------------
 
#include <stdio.h>
#include "diag/Trace.h"
 
 
 
 
 
//#include "Timer.h"
#include "cmsis_device.h"
#include "cortexm/ExceptionHandlers.h"
//#include "BlinkLed.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
 
// ----------------------------------------------------------------------------
//
// STM32F4 led blink sample (trace via NONE).
//
// In debug configurations, demonstrate how to print a greeting message
// on the trace device. In release configurations the message is
// simply discarded.
//
// To demonstrate POSIX retargetting, reroute the STDOUT and STDERR to the
// trace device and display messages on both of them.
//
// Then demonstrates how to blink a led with 1Hz, using a
// continuous loop and SysTick delays.
//
// On DEBUG, the uptime in seconds is also displayed on the trace device.
//
// Trace support is enabled by adding the TRACE macro definition.
// By default the trace messages are forwarded to the NONE output,
// but can be rerouted to any device or completely suppressed, by
// changing the definitions required in system/src/diag/trace_impl.c
// (currently OS_USE_TRACE_ITM, OS_USE_TRACE_SEMIHOSTING_DEBUG/_STDOUT).
//
 
// ----- Timing definitions -------------------------------------------------
 
 
#define BLINK_PORT_NUMBER               (6)
#define BLINK_PIN_NUMBER                (13)
#define BLINK_ACTIVE_LOW                (0)
 
#define BLINK_GPIOx(_N)                 ((GPIO_TypeDef *)(GPIOA_BASE + (GPIOB_BASE-GPIOA_BASE)*(_N)))
#define BLINK_PIN_MASK(_N)              (1 << (_N))
#define BLINK_RCC_MASKx(_N)             (RCC_AHB1ENR_GPIOAEN << (_N))
 
// Keep the LED on for 2/3 of a second.
#define TIMER_FREQUENCY_HZ (1000u)
#define BLINK_ON_TICKS  (TIMER_FREQUENCY_HZ * 2 / 3)
#define BLINK_OFF_TICKS (TIMER_FREQUENCY_HZ - BLINK_ON_TICKS)
 
typedef uint32_t timer_ticks_t;
volatile timer_ticks_t timer_delayCount;
 
// ----- main() ---------------------------------------------------------------
 
// Sample pragmas to cope with warnings. Please note the related line at
// the end of this function, used to pop the compiler diagnostics status.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"
 
int
main(int argc, char* argv[])
{
  // By customising __initialize_args() it is possible to pass arguments,
  // for example when running tests with semihosting you can pass various
  // options to the test.
  // trace_dump_args(argc, argv);
 
  // Send a greeting to the trace device (skipped on Release).
  //trace_puts("Hello ARM World!");
 
  // The standard output and the standard error should be forwarded to
  // the trace device. For this to work, a redirection in _write.c is
  // required.
  //puts("Standard output message.");
  //fprintf(stderr, "Standard error message.\n");
 
  // At this stage the system clock should have already been configured
  // at high speed.
  //trace_printf("System clock: %uHz\n", SystemCoreClock);
 
  //timer_start();
  SysTick_Config(SystemCoreClock / TIMER_FREQUENCY_HZ);
 
  //blink_led_init();
  // Enable GPIO Peripheral clock
    RCC->AHB1ENR |= BLINK_RCC_MASKx(BLINK_PORT_NUMBER);
 
    GPIO_InitTypeDef GPIO_InitStructure;
 
    // Configure pin in output push/pull mode
    GPIO_InitStructure.Pin = BLINK_PIN_MASK(BLINK_PIN_NUMBER);
    GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
    GPIO_InitStructure.Pull = GPIO_PULLUP;
    HAL_GPIO_Init(BLINK_GPIOx(BLINK_PORT_NUMBER), &GPIO_InitStructure);
 
   
  //uint32_t seconds = 0;
 
 
 
 
  // Infinite loop
  while (1)
    {
      //blink_led_on();
      HAL_GPIO_WritePin(BLINK_GPIOx(BLINK_PORT_NUMBER),
              BLINK_PIN_MASK(BLINK_PIN_NUMBER), GPIO_PIN_SET);
 
      //timer_sleep(BLINK_ON_TICKS);
      timer_delayCount = 1000u;
      while (timer_delayCount != 0u)
          ;
 
      //blink_led_off();
      HAL_GPIO_WritePin(BLINK_GPIOx(BLINK_PORT_NUMBER),
              BLINK_PIN_MASK(BLINK_PIN_NUMBER), GPIO_PIN_RESET);
 
 
      //timer_sleep(BLINK_OFF_TICKS);
      timer_delayCount = 1000u;
      while (BLINK_OFF_TICKS != 0u)
          ;
      //++seconds;
 
      // Count seconds on the trace device.
      //trace_printf("Second %u\n", seconds);
    }
  // Infinite loop, never return.
}
 
 
// ----- SysTick_Handler() ----------------------------------------------------
 
void
SysTick_Handler (void)
{
    if (timer_delayCount != 0u)
        {
          --timer_delayCount;
        }
}
 
// ----------------------------------------------------------------------------
 
 
#pragma GCC diagnostic pop
 
// ----------------------------------------------------------------------------

Outcomes