请选择 进入手机版 | 继续访问电脑版

EDABOSS电子论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1090|回复: 0

[转帖] 利用Eclipse IDE for C/C++ Developers和GNU Tools ARM Embedded编译器

[复制链接]

79

主题

20

回帖

375

E币

技术员

Rank: 2

积分
178
发表于 2017-4-20 15:16:43 | 显示全部楼层 |阅读模式
工作环境说明:

1.硬件平台: DX开发板主板 + DX103核心板

2.硬件平台: Eclipse IDE for C/C++ Developers + GNU Tools ARM Embedded
  (1) IDE:    Eclipse IDE for C/C++ Developers
  (2) 编译器: GNU Tools ARM Embedded编译器,支持STM32F407最新的HAL驱动库


用Eclipse IDE for C/C++ Developers新建一个C工程模板,主函数代码如下:

//
// 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 "BlinkLed.h"

// ----------------------------------------------------------------------------
//
// STM32F4 led blink sample (trace via ITM).
//
// 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 a.n.d STDERR to the
// trace device a.n.d display messages on both of them.
//
// Then demonstrates how to blink a led with 1Hz, using a
// continuous loop a.n.d 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 ITM output,
// but can be rerouted to any device o.r 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 -------------------------------------------------

// Keep the LED on for 2/3 of a second.
#define BLINK_ON_TICKS  (TIMER_FREQUENCY_HZ * 2 / 3)
#define BLINK_OFF_TICKS (TIMER_FREQUENCY_HZ - BLINK_ON_TICKS)

// ----- 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"

/*
* 大虾开发板的5个LED指示灯对应的GPIO
* PA0:  LED1
* PB0:  LED2
* PB14: LED3
* PD13: LED4
* PD12: LED5
*
* 大虾开发板的按键对应的GPIO
* PB10: K1
* PC2:  K2
*
* */

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 a.n.d 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.");

  // At this stage the system clock should have already been configured
  // at high speed.
  trace_printf("System clock: %uHz", SystemCoreClock);

  timer_start();

  blink_led_init();
  


  uint32_t seconds = 0;

  while (1)
    {
//      blink_led_on();
      timer_sleep(BLINK_ON_TICKS);

//      blink_led_off();
      timer_sleep(BLINK_OFF_TICKS);

      ++seconds;
      HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);
      HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
      HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);
      HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
      HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
      // Count seconds on the trace device.
      trace_printf("Second %u", seconds);
    }
}
#pragma GCC diagnostic pop


// 在BlinkLed.c中初始化DX开发板的5个LED指示灯,以及K1、K2键对应的GPIO
// 用STM32CubeMX生成的两个中断函数整个拷贝过来

void blink_led_init()
{
  // Enable GPIO Peripheral clock
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;

  GPIO_InitTypeDef GPIO_InitStructure;

  // Configure pin in output push/pull mode
  GPIO_InitStructure.Pin  = GPIO_PIN_0;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
  GPIO_InitStructure.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.Pin  = GPIO_PIN_14;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.Pin  = GPIO_PIN_13 | GPIO_PIN_12;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);


  /*Configure GPIO pin : PB10 */
  GPIO_InitStructure.Pin = GPIO_PIN_10;
  GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; /* 下降沿中断 */
  GPIO_InitStructure.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* EXTI interrupt init */
  HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

}

// 以下两个中断函数由stm32cubemx软件自动生成,很方便

/**
* @brief This function handles EXTI Line[15:10] interrupts.
*/
void EXTI15_10_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI15_10_IRQn 0 */

  /* USER CODE END EXTI15_10_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10); /* 此处设置断点,全速运行,然后按下K1,就能到达这里 */
  /* USER CODE BEGIN EXTI15_10_IRQn 1 */
   
  /* USER CODE END EXTI15_10_IRQn 1 */
}

/**
* @brief This function handles EXTI Line2 interrupt.
*/
void EXTI2_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI2_IRQn 0 */

  /* USER CODE END EXTI2_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); /* 此处设置断点,全速运行,然后按下K2,就能到达这里 */
  /* USER CODE BEGIN EXTI2_IRQn 1 */

  /* USER CODE END EXTI2_IRQn 1 */
}


010153ftmizbgnbdczbcgf.jpg

【图片】进入KEY1按键中断(PB10).jpg,在中断函数中设置断点,全速运行,然后按开发板的K1键
积分规则
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|EDABOSS电子论坛

GMT+8, 2024-3-29 19:40 , Processed in 0.041736 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表