標題: 利用Eclipse IDE for C/C++ Developers和GNU Tools ARM Embedded編譯器 [打印本頁] 作者: bibi 時間: 2015-4-19 00:57 標題: 利用Eclipse IDE for C/C++ Developers和GNU Tools ARM Embedded編譯器 工作環(huán)境說明:
1.硬件平臺: DX開發(fā)板主板 + 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工程模板,主函數(shù)代碼如下:
//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
// ----------------------------------------------------------------------------
//
// 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).
//
// 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)
// 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 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