我花了不少时间让召唤臂工具链在Linuxmint Nadia MATE和eclipse一起工作我正试图编译一个简单的LED闪光灯的例子我已经将STM32F4的所有目录添加到include路径,并解析了include语句,但是我得到了各种未解析的引用~/bin/sat在我的$路径中,很明显找到了工具链我还得到了一个有趣的未定义的引用,指向我的下载目录中的某个地方,我不明白为什么Eclipse会在那里看。
我对Eclipse和ARM平台很熟悉(可能很明显),但对windows环境下的pic编程相当有经验。
我有一种感觉,我错过了相当简单的事情(除了那个“退出”),但我还没有找到这样的启发时刻(即使同一类型的问题不断涌现,我似乎找不到解决方案)。我想在试考克斯之前再问一次。

#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库NeLIB是一个非常灵活的最小C库,这种灵活性是通过定义一些函数来实现的,这些函数是库的一部分。这些函数称为“stub”参见this site以获取一些newlib stub的示例实现例如,通过定义这些函数,您可以使用UART、USB等具有printf功能。
在您的案例中,文件exit.c正在调用存根_exit的实现您可以实现一个虚拟存根,因为在嵌入式系统上通常不需要这个系统调用。
编辑:
您可能使用here提供的构建脚本构建了召唤臂工具链此脚本下载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库现在位于此路径的子文件夹中,生成脚本在其中下载了它。

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

10-11 18:52