ARM Cortex M3的GNU-C工具链设置.C问题

ARM Cortex M3的GNU-C工具链设置.C问题,c,gcc,arm,texas-instruments,gnu-toolchain,C,Gcc,Arm,Texas Instruments,Gnu Toolchain,我使用的是基于ARMM3的MCU,CC2538。我使用CodeComposer Studio v6作为IDE。当我选择GNU v4.7.4 Linaro作为编译器时,我得到一条警告消息,所选设备当前未向GNU工具链提供项目初始化详细信息。我想这是由于setup.c的原因,稍后将添加它 编译器具有以下标志 `"-mcpu=cortex-m3 -mthumb -mfpu=vfp -I"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/a

我使用的是基于ARMM3的MCU,CC2538。我使用CodeComposer Studio v6作为IDE。当我选择GNU v4.7.4 Linaro作为编译器时,我得到一条警告消息,所选设备当前未向GNU工具链提供项目初始化详细信息。我想这是由于setup.c的原因,稍后将添加它

编译器具有以下标志

 `"-mcpu=cortex-m3 -mthumb -mfpu=vfp -I"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/arm-none-eabi/include" -g -gstrict-dwarf -Wall -mno -thumb-interwork -msoft-float -mfix-cortex-m3-ldrd" 
和链接器标志:-mthumb-g-gstrict dwarf-Wall-Wl-Map,cc2328em_test.Map

我使用TI提供的源文件

我将main.c、setup.c、setup_gcc.c和cc2538_512.cmd添加到一个空项目中,然后编译它。以下是编译输出:

**** Build of configuration Debug for project cc2328em_test ****

"c:\\ti\\ccsv6\\utils\\bin\\gmake" -k all 
'Building file: ../main.c'
'Invoking: GNU Compiler'
"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/arm-none-eabi-gcc.exe" -c -mcpu=cortex-m3 -mthumb -mfpu=vfp -I"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/arm-none-eabi/include" -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall -MMD -MP -MF"main.d" -MT"main.d" -mno-thumb-interwork -msoft-float -mfix-cortex-m3-ldrd -fshort-enums -fomit-frame-pointer -fno-strict-aliasing -o"main.o"  "../main.c"
'Finished building: ../main.c'
' '
'Building file: ../setup.c'
'Invoking: GNU Compiler'
"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/arm-none-eabi-gcc.exe" -c -mcpu=cortex-m3 -mthumb -mfpu=vfp -I"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/arm-none-eabi/include" -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall -MMD -MP -MF"setup.d" -MT"setup.d" -mno-thumb-interwork -msoft-float -mfix-cortex-m3-ldrd -fshort-enums -fomit-frame-pointer -fno-strict-aliasing -o"setup.o"  "../setup.c"
'Finished building: ../setup.c'
' '
'Building file: ../startup_gcc.c'
'Invoking: GNU Compiler'
"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/arm-none-eabi-gcc.exe" -c -mcpu=cortex-m3 -mthumb -mfpu=vfp -I"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/arm-none-eabi/include" -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall -MMD -MP -MF"startup_gcc.d" -MT"startup_gcc.d" -mno-thumb-interwork -msoft-float -mfix-cortex-m3-ldrd -fshort-enums -fomit-frame-pointer -fno-strict-aliasing -o"startup_gcc.o"  "../startup_gcc.c"
'Finished building: ../startup_gcc.c'
' '
'Building target: cc2328em_test.out'
'Invoking: GNU Linker'
"c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/arm-none-eabi-gcc.exe" -mthumb -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall -Wl,-Map,"cc2328em_test.map" -nostartfiles -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall -o"cc2328em_test.out" "./main.o" "./setup.o" "./startup_gcc.o" "../cc2538_512_gcc.cmd"  -Wl,--start-group -l"c" -l"gcc" -l"nosys" -Wl,--end-group 
./startup_gcc.o:(.flashcca+0x0): multiple definition of `__cca'
./setup.o:(.flashcca+0x0): first defined here
c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/bin/ld.exe: warning: ../cc2538_512_gcc.cmd contains output sections; did you forget -T?
c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/bin/ld.exe: cc2328em_test.out section `.flashcca' will not fit in region `FLASH_CCA'
c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/bin/ld.exe: region `FLASH_CCA' overflowed by 12 bytes
c:/ti/ccsv6/tools/compiler/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/bin/ld.exe: warning: cannot find entry symbol _start; defaulting to 00200000
collect2.exe: error: ld returned 1 exit status
gmake: *** [cc2328em_test.out] Error 1
gmake: Target `all' not remade because of errors.

**** Build Finished ****
这是第一个错误。/startup\u gcc.o:.flashcca+0x0:“\u cca”的多个定义

源代码有错误吗?我是否使用了错误的工具链我从TI的应用程序中心下载了GNU工具链作为带有GCC徽标的ARM GCC。或者我会错过任何配置吗

以下是TI提供的源文件:

main.c

这是一个打印屏幕,显示左侧菜单上的配置和相关文件
启动的第一行是include setup.c;你看到问题了吗?如果这样做,请不要单独构建setup.c

阅读错误消息“cca”的多个定义将有所帮助;计算机很少撒谎。你可以编译两次。此外,链接器脚本中的.flashcca输出部分没有输入文件,这应该得到修复

比如说,

.flashcca :{*(.flashcca);} > FLASH_CCA

没有*.flashcca;,.flashcca:{}>FLASH_-CCA是无用的。第一个.flashcca是一个输出部分,即最终二进制文件中的某个位置。括号内的内容是一个输入部分,即您的源/对象。链接器的一个主要选择是获取多个输入部分并将它们放置在一个输出部分中。另一项工作是旋转外部符号;如果它提供了两个同名的,它就不能这样做;没有办法知道该使用哪个。这就是为什么您对“cca”有多种定义。

@Artless noise,谢谢。我不明白什么是错误的,但它解决了问题,这可能是好的,张贴它作为一个答案。因此,我在启动时删除了include setup.c\u gcc.c,然后添加include和define SYS\u CTRL\u EMUOVR 0x400D20B4。现在,它可以正确编译,并且二进制文件在EVM上运行良好。这是默认代码,如果TI在发布代码之前编译代码,这是另一个问题:它仍然会输出两条警告消息,说明Description Resource Path Location Type../cc2538_512_gcc.cmd包含输出部分;你忘了-T吗?cc2328em_测试C/C++问题找不到输入符号_start;默认为00200000 cc2328em_测试C/C++问题您知道如何处理它们吗?不要构建setup.C。。。因为它已经包含在stup_gcc.c中。。。这样,它将被编译两次。。。或者你可以从setup\u gcc/cplace中删除include setup.c@artless。。所以你可以知道:我是在发表评论之后说的
#include <stdint.h>

#define FLASH_START_ADDR                0x00200000
#define BOOTLOADER_BACKDOOR_DISABLE     0xEFFFFFFF
#define SYS_CTRL_EMUOVR                 0x400D20B4
#define SYS_CTRL_I_MAP                  0x400D2098


//*****************************************************************************
//
// Customer Configuration Area in Lock Page
// Holds Image Vector table address (bytes 2013 - 2015) and
// Image Valid bytes (bytes 2008 -2011)
//
//*****************************************************************************
typedef struct
{
    uint32_t ui32BootldrCfg;
    uint32_t ui32ImageValid;
    uint32_t ui32ImageVectorAddr;
}
lockPageCCA_t;

#ifdef __IAR_SYSTEMS_ICC__
__root const lockPageCCA_t __cca @ ".flashcca" =
#elif __TI_COMPILER_VERSION__
#pragma DATA_SECTION(__cca, ".flashcca")
#pragma RETAIN(__cca)
const lockPageCCA_t __cca =
#else
__attribute__ ((section(".flashcca"), used))
const lockPageCCA_t __cca =
#endif
{
  BOOTLOADER_BACKDOOR_DISABLE,  // Bootloader backdoor disabled
  0,                            // Image valid bytes
  FLASH_START_ADDR              // Vector table located at flash start address
};
#include "setup.c"


//*****************************************************************************
//
// Macro for hardware access, both direct and via the bit-band region.
//
//*****************************************************************************
#ifndef HWREG
#define HWREG(x)                                                              \
        (*((volatile unsigned long *)(x)))
#endif


extern int main (void);

void ResetISR(void);
void NmiSR(void);
void FaultISR(void);
void IntDefaultHandler(void);

//*****************************************************************************
//
// Reserve space for the system stack.
//
//*****************************************************************************
static uint32_t pui32Stack[128];



__attribute__ ((section(".vectors"), used))
void (* const gVectors[])(void) =
{
   (void (*)(void))((uint32_t)pui32Stack + sizeof(pui32Stack)), // Stack pointer
   ResetISR,                               // Reset handler
   NmiSR,                                  // The NMI handler
   FaultISR,                               // The hard fault handler
   IntDefaultHandler,                      // 4 The MPU fault handler
   IntDefaultHandler,                      // 5 The bus fault handler
   IntDefaultHandler,                      // 6 The usage fault handler
   0,                                      // 7 Reserved
   0,                                      // 8 Reserved
   0,                                      // 9 Reserved
   0,                                      // 10 Reserved
   IntDefaultHandler,                      // 11 SVCall handler
   IntDefaultHandler,                      // 12 Debug monitor handler
   0,                                      // 13 Reserved
   IntDefaultHandler,                      // 14 The PendSV handler
   IntDefaultHandler,                      // 15 The SysTick handler
   IntDefaultHandler,                      // 16 GPIO Port A
   IntDefaultHandler,                      // 17 GPIO Port B
   IntDefaultHandler,                      // 18 GPIO Port C
   IntDefaultHandler,                      // 19 GPIO Port D
   0,                                      // 20 none
   IntDefaultHandler,                      // 21 UART0 Rx and Tx
   IntDefaultHandler,                      // 22 UART1 Rx and Tx
   IntDefaultHandler,                      // 23 SSI0 Rx and Tx
   IntDefaultHandler,                      // 24 I2C Master and Slave
   0,                                      // 25 Reserved
   0,                                      // 26 Reserved
   0,                                      // 27 Reserved
   0,                                      // 28 Reserved
   0,                                      // 29 Reserved
   IntDefaultHandler,                      // 30 ADC Sequence 0
   0,                                      // 31 Reserved
   0,                                      // 32 Reserved
   0,                                      // 33 Reserved
   IntDefaultHandler,                      // 34 Watchdog timer, timer 0
   IntDefaultHandler,                      // 35 Timer 0 subtimer A
   IntDefaultHandler,                      // 36 Timer 0 subtimer B
   IntDefaultHandler,                      // 37 Timer 1 subtimer A
   IntDefaultHandler,                      // 38 Timer 1 subtimer B
   IntDefaultHandler,                      // 39 Timer 2 subtimer A
   IntDefaultHandler,                      // 40 Timer 2 subtimer B
   IntDefaultHandler,                      // 41 Analog Comparator 0
   IntDefaultHandler,                      // 42 RFCore Rx/Tx
   IntDefaultHandler,                      // 43 RFCore Error
   IntDefaultHandler,                      // 44 IcePick
   IntDefaultHandler,                      // 45 FLASH Control
   IntDefaultHandler,                      // 46 AES
   IntDefaultHandler,                      // 47 PKA
   IntDefaultHandler,                      // 48 Sleep Timer
   IntDefaultHandler,                      // 49 MacTimer
   IntDefaultHandler,                      // 50 SSI1 Rx and Tx
   IntDefaultHandler,                      // 51 Timer 3 subtimer A
   IntDefaultHandler,                      // 52 Timer 3 subtimer B
   0,                                      // 53 Reserved
   0,                                      // 54 Reserved
   0,                                      // 55 Reserved
   0,                                      // 56 Reserved
   0,                                      // 57 Reserved
   0,                                      // 58 Reserved
   0,                                      // 59 Reserved
   IntDefaultHandler,                      // 60 USB 2538
   0,                                      // 61 Reserved
   IntDefaultHandler,                      // 62 uDMA
   IntDefaultHandler,                      // 63 uDMA Error
#ifndef CC2538_USE_ALTERNATE_INTERRUPT_MAP
   0,                                      // 64 64-155 are not in use
   0,                                      // 65
   0,                                      // 66
   0,                                      // 67
   0,                                      // 68
   0,                                      // 69
   0,                                      // 70
   0,                                      // 71
   0,                                      // 72
   0,                                      // 73
   0,                                      // 74
   0,                                      // 75
   0,                                      // 76
   0,                                      // 77
   0,                                      // 78
   0,                                      // 79
   0,                                      // 80
   0,                                      // 81
   0,                                      // 82
   0,                                      // 83
   0,                                      // 84
   0,                                      // 85
   0,                                      // 86
   0,                                      // 87
   0,                                      // 88
   0,                                      // 89
   0,                                      // 90
   0,                                      // 91
   0,                                      // 92
   0,                                      // 93
   0,                                      // 94
   0,                                      // 95
   0,                                      // 96
   0,                                      // 97
   0,                                      // 98
   0,                                      // 99
   0,                                      // 100
   0,                                      // 101
   0,                                      // 102
   0,                                      // 103
   0,                                      // 104
   0,                                      // 105
   0,                                      // 106
   0,                                      // 107
   0,                                      // 108
   0,                                      // 109
   0,                                      // 110
   0,                                      // 111
   0,                                      // 112
   0,                                      // 113
   0,                                      // 114
   0,                                      // 115
   0,                                      // 116
   0,                                      // 117
   0,                                      // 118
   0,                                      // 119
   0,                                      // 120
   0,                                      // 121
   0,                                      // 122
   0,                                      // 123
   0,                                      // 124
   0,                                      // 125
   0,                                      // 126
   0,                                      // 127
   0,                                      // 128
   0,                                      // 129
   0,                                      // 130
   0,                                      // 131
   0,                                      // 132
   0,                                      // 133
   0,                                      // 134
   0,                                      // 135
   0,                                      // 136
   0,                                      // 137
   0,                                      // 138
   0,                                      // 139
   0,                                      // 140
   0,                                      // 141
   0,                                      // 142
   0,                                      // 143
   0,                                      // 144
   0,                                      // 145
   0,                                      // 146
   0,                                      // 147
   0,                                      // 148
   0,                                      // 149
   0,                                      // 150
   0,                                      // 151
   0,                                      // 152
   0,                                      // 153
   0,                                      // 154
   0,                                      // 155
   IntDefaultHandler,                      // 156 USB
   IntDefaultHandler,                      // 157 RFCORE RX/TX
   IntDefaultHandler,                      // 158 RFCORE Error
   IntDefaultHandler,                      // 159 AES
   IntDefaultHandler,                      // 160 PKA
   IntDefaultHandler,                      // 161 SMTimer
   IntDefaultHandler,                      // 162 MACTimer
#endif
};

//*****************************************************************************
//
// The following are constructs created by the linker, indicating where the
// the "data" and "bss" segments reside in memory.  The initializers for the
// for the "data" segment resides immediately following the "text" segment.
//
//*****************************************************************************
extern uint32_t _etext;
extern uint32_t _data;
extern uint32_t _edata;
extern uint32_t _bss;
extern uint32_t _ebss;

//
// And here are the weak interrupt handlers.
//
void 
NmiSR (void) 
{ 
    ResetISR(); 
    while(1)
    {
    } 
}


void 
FaultISR (void) 
{ 
    while(1)
    {
    } 
}


void 
IntDefaultHandler (void) 
{ 
    while(1)
    {
    }
}

void 
ResetISR (void)
{
    uint32_t *pui32Src, *pui32Dest;

    //
    // Workaround for PM debug issue
    //
    HWREG(SYS_CTRL_EMUOVR) = 0xFF; 

    //
    // Copy the data segment initializers from flash to SRAM.
    //
    pui32Src = &_etext;
    for(pui32Dest = &_data; pui32Dest < &_edata; )
    {
        *pui32Dest++ = *pui32Src++;
    }

    //
    // Zero fill the bss segment.
    //
    __asm("    ldr     r0, =_bss\n"
          "    ldr     r1, =_ebss\n"
          "    mov     r2, #0\n"
          "    .thumb_func\n"
          "zero_loop:\n"
          "        cmp     r0, r1\n"
          "        it      lt\n"
          "        strlt   r2, [r0], #4\n"
          "        blt     zero_loop");

#ifdef CC2538_USE_ALTERNATE_INTERRUPT_MAP
    //
    // Enable alternate interrupt mapping
    //
    HWREG(SYS_CTRL_I_MAP) |= 1;
#endif

   //
   // Call the application's entry point.
   //
   main();

   //
   // End here if return from main()
   //
   while(1)
   {
   }
}
/******************************************************************************
 *
 *
 * cc2538_512_gcc.cmd - Example GCC linker configuration file for CC2538
 *
 *
 *****************************************************************************/

MEMORY
{
    FLASH (rx) : ORIGIN = 0x200000, LENGTH = 0x0007FFD4
    FLASH_CCA (RX) : ORIGIN = 0x0027FFD4, LENGTH = 12
    SRAM_NON_RETENTION (RWX) : ORIGIN =  0x20000000, LENGTH = 0x00004000
    SRAM_RETENTION (RWX) : ORIGIN = 0x20004000, LENGTH = 0x00004000
}

SECTIONS
{
    .text :
    {
        _text = .;
        KEEP(*(.vectors))
        *(.text*)
        *(.rodata*)
        _etext = .;
    } > FLASH= 0
    .data : AT(ADDR(.text) + SIZEOF(.text))
    {
        _data = .;
        *(vtable)
        *(.data*)
        _edata = .;
    } > SRAM_NON_RETENTION
    .bss :
    {
        _bss = .;
        *(.bss*)
        *(COMMON)
        _ebss = .;
    } > SRAM_NON_RETENTION
    .flashcca :
    { 
    } > FLASH_CCA   
}
.flashcca :{*(.flashcca);} > FLASH_CCA