c-调用ARM工具链和eclipse



我在Linuxmint Nadia MATE中花了很多时间让调用臂工具链与eclipse一起工作。我正试图编译一个简单的LED闪光灯的例子。我已经将STM32F4的所有目录添加到include路径中,并解析了#include语句,但我得到了各种未解析的引用~/bin/sat在我的$PATH中,并且很明显可以找到工具链。我还得到了一个有趣的未定义引用"_exit",它指向我的下载目录中的某个地方,我根本不明白Eclipse为什么会在那里查看。

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

我有一种感觉,我错过了一些相当简单的事情(除了"__exit"这件事),但我还没有在SO找到启发性的时刻(尽管同样类型的问题不断出现,但我似乎找不到解决方案)。我想在尝试库考克斯之前再问一次。

#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库,这种灵活性是通过允许您定义库中的一些函数来实现的。这些函数被称为"stub"。有关一些newlib stub的示例实现,请参阅本网站。例如,通过定义这些功能,您可以使用UART、USB等具有printf

在您的案例中,文件exit.c正在调用存根_exit的实现。您可以实现一个伪存根,因为您通常不需要在嵌入式系统上进行此系统调用。

编辑:

您可能使用此处提供的构建脚本构建了调用臂工具链。此脚本下载newlib,并在GCC安装文件夹中添加一个指向newlib下载位置的符号链接:

# 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库现在位于该路径的子文件夹中,构建脚本就是在该子文件夹中下载它的

最新更新