c - summon-ARM 工具链和 eclipse

标签 c eclipse arm stm32

让 summon-arm 工具链在 Linuxmint Nadia MATE 中与 eclipse 一起工作,我花了很长时间。我正在尝试编译一个简单的 LED 指示灯示例。我已将 STM32F4 的所有目录添加到包含路径,并且 #include 语句已解析,但我得到了各种未解析的引用。 ~/bin/sat 在我的 $PATH 中,很明显可以找到工具链。我还得到一个有趣的 undefined reference ,它指向我的下载目录中的某处,我完全不明白为什么 Eclipse 会在那里查找。

我是 Eclipse(可能很明显)和 ARM 平台的真正新手,但在 Windows 环境中对 PIC 进行编程方面经验丰富。

我觉得我遗漏了一些相当简单的东西(除了那个'__exit'东西),但我还没有找到 SO 的启发性时刻(即使相同类型的问题不断出现,我可以'似乎找不到解决方案)。我想在尝试 CooCox 之前再问一遍。

#include <stm32f4xx_conf.h>
#include "stm32f4xx_gpio.h"
#include "stm32f4_discovery.h"
#include "stm32f4xx_rcc.h"

void Delay(__IO uint32_t nCount) {
  while(nCount--) {
  }
}

void init_GPIO(void){
    GPIO_InitTypeDef GPIO_InitStruct;
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOD, &GPIO_InitStruct);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);


    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;        // we want to configure PA0
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;     // we want it to be an input
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;//this sets the GPIO modules clock speed
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;   // this sets the pin type to push / pull (as opposed to open drain)
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;   // this enables the pulldown resistor --> we want to detect a high level
    GPIO_Init(GPIOA, &GPIO_InitStruct);           // this passes the configuration to the Init function which takes care of the low level stuff
}



void main(){
    init_GPIO();
    GPIOD->BSRRL = 0xF000; // set PD12 thru PD15
    Delay(1000000L);         // wait a short period of time
    GPIOD->BSRRH = 0xF000; // reset PD12 thru PD15
    uint8_t i = 0;


while(1){
    /* Every GPIO port has an input and
     * output data register, ODR and IDR
     * respectively, which hold the status of the pin
     *
     * Here the IDR of GPIOA is checked whether bit 0 is
     * set or not. If it's set the button is pressed
     */
    if(GPIOA->IDR & 0x0001){
        // if the number of button presses is greater than 4, reset the counter (we start counting from 0!)
        if(i > 3){
            i = 0;
        }
        else{ // if it's smaller than 4, switch the LEDs

            switch(i){

                case 0:
                    GPIOD->BSRRL = 0x1000; // this sets LED1 (green)
                    GPIOD->BSRRH = 0x8000; // this resets LED4 (blue)
                    break;

                case 1:
                    GPIOD->BSRRL = 0x2000; // this sets LED2 (orange)
                    GPIOD->BSRRH = 0x1000; // this resets LED1
                    break;

                case 2:
                    GPIOD->BSRRL = 0x4000; // this sets LED3 (red)
                    GPIOD->BSRRH = 0x2000; // this resets LED2
                    break;

                case 3:
                    GPIOD->BSRRL = 0x8000; // this sets LED4
                    GPIOD->BSRRH = 0x4000; // this resets LED3
                    break;
                }

            i++; // increase the counter every time the switch is pressed
        }
        Delay(3000000L); // add a small delay to debounce the switch
    }
    }


}

当我构建时,我得到

make all 
Building file: ../src/main.c
Invoking: Cross ARM C Compiler
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall  -g3 -I"/home/scott/workspace/STM32 libraries/CMSIS/Include" -I"/home/scott/workspace/STM32 libraries/CMSIS/ST/STM32F4xx/Include" -I"/home/scott/workspace/STM32 libraries/STM32F4xx_StdPeriph_Driver/inc" -I"/home/scott/workspace/STM32 libraries/STM32F4-Discovery" -I/home/scott/workspace/blinky2/src -MMD -MP -MF"src/main.d" -MT"src/main.d" -c -o "src/main.o" "../src/main.c"
../src/main.c:41:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main(){
      ^
Finished building: ../src/main.c

Building target: blinky2.elf
Invoking: Cross ARM C Linker
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall  -g3 -Xlinker --gc-sections -Wl,-Map,"blinky2.map" -o "blinky2.elf"  ./src/main.o   
./src/main.o: In function `init_GPIO':
/home/scott/workspace/blinky2/Debug/../src/main.c:21: undefined reference to `RCC_AHB1PeriphClockCmd'
/home/scott/workspace/blinky2/Debug/../src/main.c:27: undefined reference to `GPIO_Init'
/home/scott/workspace/blinky2/Debug/../src/main.c:28: undefined reference to `RCC_AHB1PeriphClockCmd'
/home/scott/workspace/blinky2/Debug/../src/main.c:36: undefined reference to `GPIO_Init'
/home/scott/sat/lib/gcc/arm-none-eabi/4.8.2/../../../../arm-none-eabi/lib/thumb/cortex-m4/libg.a(lib_a-exit.o): In function `exit':
/home/scott/Downloads/summon-arm-toolchain-master/build/arm-none-eabi/thumb/cortex-m4/newlib/libc/stdlib/../../../../../../../gcc-linaro-4.8-2013.07-1/newlib/libc/stdlib/exit.c:65: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
make: *** [blinky2.elf] Error 1

11:39:28 Build Finished (took 3s.124ms)

最佳答案

您的工具链正在使用 newlib C 库。 Newlib 是一个非常灵活的最小 C 库,这种灵 active 是通过让您定义库中的一些函数来实现的。这些函数称为“ stub ”,请参阅 this site有关一些 newlib stub 的示例实现。例如,通过定义这些函数,您可以使用 UART、USB 等来实现 printf

在您的案例中,文件 exit.c 正在调用 stub _exit 的实现。您可以实现虚拟 stub ,因为在嵌入式系统上您通常不需要此系统调用。

编辑:

您可能使用提供的构建脚本构建了 summon-arm-toolchain here .此脚本下载 newlib 并在 GCC 安装文件夹中添加指向 newlib 下载位置的符号链接(symbolic link):

# line 420 and 421 of the script:
log "Adding newlib symlink to gcc"
ln -f -s `pwd`/${NEWLIB}/newlib ${GCC}

由于您可能在文件夹 /home/scott/Downloads/summon-arm-toolchain-master/ 中构建了工具链,newlib 库现在位于该路径的子文件夹中,构建脚本下载它的地方。

关于c - summon-ARM 工具链和 eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20314654/

相关文章:

c - 错误: lvalue required as left operand of assignment (swrots)

java - Eclipse cash 项目并没有看到代码更改

php - 如何在eclipse中附加php文档

linux - 如何在 Linux 下使用 SWD 对 ARM MCU 进行编程?

c - "Magic ring buffer"在Linux内核空间的实现?

c - 尝试在 c 中创建基于区域的内存池

c - 如何在源代码级别自动展开源代码中的循环?

c - 二维数组,按总和对行进行排序

eclipse - 加速 Eclipse Web 浏览器中的代码更改?

arm - 使用来自目标 ARM 板的 rootfs 的内核头文件交叉编译内核模块