GNU-C toolchain task for ARM Cortex M3
I am using an ARM M3 based MCU, CC2538. I am using Code Composer Studio v6 as my IDE. When I select GNU v4.7.4 (Linaro) as my compiler, a warning message appears that "the selected device does not currently provide project initialization details into the GNU toolchain." I guess it has something to do with setup.c
(?) Which will be added later.
the compiler has the following flags
`"-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"
and linker flags: -mthumb -g -gstrict-dwarf -Wall -Wl,-Map,"cc2328em_test.map"
I am using the source files provided by TI http://www.ti.com/lit/zip/swra443
I add main.c, setup.c, setup_gcc.c and cc2538_512.cmd to an empty project and then compile it. here is the compilation result:
**** 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 ****
here is the first error " ./startup_gcc.o :(. flashcca + 0x0): multiple definition of` __cca ' "
Is the source code fixed? I'm using the wrong toolchain (did I download the GNU toolchain from the TI APP center as "ARM GCC" with the GCC logo, or did I miss any config?
Here are the source files that TI provides:
main.c
#define GPIO_C_DIR 0x400DB400
#define GPIO_C_DATA 0x400DB000
#define HWREG(x) \
(*((volatile unsigned long *)(x)))
int main(void)
{
volatile unsigned long ulLoopCount;
// Set direction output and initial value for PC2 and PC0
// Greed LED on PC2
// Red LED on PC0
HWREG(GPIO_C_DIR) |= 0x05;
HWREG(GPIO_C_DATA + (0x05 << 2)) = 0;
// Loop forever.
while(1)
{
// Turn on both LED's.
HWREG(GPIO_C_DATA + (0x05 << 2)) ^= 0x05;
// Delay for a bit
for(ulLoopCount = 200000; ulLoopCount > 0; ulLoopCount--)
{
}
}
return 0;
}
setup.c
#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
};
startup_gcc.c
#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 entry point.
//
main();
//
// End here if return from main()
//
while(1)
{
}
}
cc2538_512_gcc.cmd
/******************************************************************************
*
*
* 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
}
Here is the print screen that shows the configurations and associated files in the menu on the left
source to share
First line startup_gcc.c #include "setup.c"
; do you see the problem? Don't create setup.c separately if you do.
Reading the error message will help a few definitions of "__cca"; computers rarely lie. You can compile this twice. Also, there are no input files in the .flashcca output section in the linker script and this should be fixed.
For example,
.flashcca :{*(.flashcca);} > FLASH_CCA
No *(.flashcca);
, .flashcca :{} > FLASH_CCA
useless. The first .flashcca is the output section (i.e. the location in the final binary). The stuff inside the brackets represents the input section (i.e. your source / object). The main chorus of the linker is to take multiple input sections and place them in output sections. Another task is to rotate external symbols; he cannot do this when he has two of the same name; there is no way to know which one to use. This is why you have multiple definitions for "__cca".
source to share