我有一段时间让一个召唤臂工具链在Linuxmint Nadia MATE中使用eclipse。我正在尝试编译一个简单的LED闪烁示例。我已经将STM32F4的所有目录添加到包含路径,并且#include语句解析了,但是我得到了各种未解析的引用。 〜/ bin / sat在我的$ PATH中,显然正在找到工具链。我也得到一个有趣的未定义的引用`_exit',它指向我的Downloads目录中的某个地方,我无法理解为什么Eclipse会在那里看。
我是Eclipse(可能是显而易见的)和ARM平台的真正新手,但是从Windows环境中编程PIC的经验非常丰富。
我有一种感觉我错过了一些相当简单的东西(除了那个'__exit'的东西),但是我没有找到那个有启发性的时刻(尽管相同类型的问题不断出现,我可以'似乎找到了解决方案)。以为在尝试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)
答案 0 :(得分:2)
您的工具链正在使用newlib C库。 Newlib是一个非常灵活的最小C库,通过让您定义属于库的一些函数来实现这种灵活性。这些函数称为“存根”,请参阅this site以获取某些newlib存根的示例实现。例如,通过使用UART,USB等定义那些函数printf
您的案例中的文件exit.c
正在调用存根_exit
的实现。您可以实现虚拟存根,因为您通常不需要在嵌入式系统上进行此系统调用。
编辑:
您可能使用提供的构建脚本here构建了summon-arm-toolchain。此脚本下载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库现在位于此路径的子文件夹中,构建脚本将在该子文件夹中下载它。