[bsp] add gcc support

This commit is contained in:
tanek liang 2017-11-14 11:09:46 +08:00 committed by Bernard Xiong
parent 234c6113ed
commit dcce8489db
5 changed files with 89 additions and 42 deletions

View File

@ -8,20 +8,22 @@ Import('rtconfig')
cwd = GetCurrentDir() cwd = GetCurrentDir()
objs = [] objs = []
list = os.listdir(cwd) list = os.listdir(cwd)
CPPDEFINES = []
objs = objs + SConscript(os.path.join('drivers', 'SConscript')) objs = objs + SConscript(os.path.join('drivers', 'SConscript'))
objs = objs + SConscript(os.path.join('utilities', 'SConscript')) objs = objs + SConscript(os.path.join('utilities', 'SConscript'))
if rtconfig.CROSS_TOOL == 'gcc': if rtconfig.CROSS_TOOL == 'gcc':
objs = objs + SConscript(os.path.join('mcuxpresso', 'SConscript')) objs = objs + SConscript(os.path.join('mcuxpresso', 'SConscript'))
CPPDEFINES += ['__USE_CMSIS']
elif rtconfig.CROSS_TOOL == 'keil': elif rtconfig.CROSS_TOOL == 'keil':
objs = objs + SConscript(os.path.join('arm', 'SConscript')) objs = objs + SConscript(os.path.join('arm', 'SConscript'))
elif rtconfig.CROSS_TOOL == 'iar': elif rtconfig.CROSS_TOOL == 'iar':
objs = objs + SConscript(os.path.join('iar', 'SConscript')) objs = objs + SConscript(os.path.join('iar', 'SConscript'))
src = Glob('*.c') src = Glob('*.c')
CPPPATH = [cwd] CPPPATH = [cwd]
CPPDEFINES = ['CORE_M4', 'CPU_LPC54608', 'CPU_LPC54608J512ET180=1'] CPPDEFINES += ['CORE_M4', 'CPU_LPC54608', 'CPU_LPC54608J512ET180=1']
group = DefineGroup('CMSIS', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) group = DefineGroup('CMSIS', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)

View File

@ -82,7 +82,7 @@ extern void SystemInit(void);
// When the application defines a handler (with the same name), this will // When the application defines a handler (with the same name), this will
// automatically take precedence over these weak definitions // automatically take precedence over these weak definitions
//***************************************************************************** //*****************************************************************************
void ResetISR(void); void Reset_Handler(void);
WEAK void NMI_Handler(void); WEAK void NMI_Handler(void);
WEAK void HardFault_Handler(void); WEAK void HardFault_Handler(void);
WEAK void MemManage_Handler(void); WEAK void MemManage_Handler(void);
@ -234,7 +234,7 @@ extern int main(void);
//***************************************************************************** //*****************************************************************************
// External declaration for the pointer to the stack top from the Linker Script // External declaration for the pointer to the stack top from the Linker Script
//***************************************************************************** //*****************************************************************************
extern void _vStackTop(void); extern void _estack(void);
//***************************************************************************** //*****************************************************************************
// External declaration for LPC MCU vector table checksum from Linker Script // External declaration for LPC MCU vector table checksum from Linker Script
@ -256,8 +256,8 @@ extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
__attribute__ ((used, section(".isr_vector"))) __attribute__ ((used, section(".isr_vector")))
void (* const g_pfnVectors[])(void) = { void (* const g_pfnVectors[])(void) = {
// Core Level - CM4 // Core Level - CM4
&_vStackTop, // The initial stack pointer &_estack, // The initial stack pointer
ResetISR, // The reset handler Reset_Handler, // The reset handler
NMI_Handler, // The NMI handler NMI_Handler, // The NMI handler
HardFault_Handler, // The hard fault handler HardFault_Handler, // The hard fault handler
MemManage_Handler, // The MPU fault handler MemManage_Handler, // The MPU fault handler
@ -336,7 +336,7 @@ void (* const g_pfnVectors[])(void) = {
//***************************************************************************** //*****************************************************************************
// Functions to carry out the initialization of RW and BSS data sections. These // Functions to carry out the initialization of RW and BSS data sections. These
// are written as separate functions rather than being inlined within the // are written as separate functions rather than being inlined within the
// ResetISR() function in order to cope with MCUs with multiple banks of // Reset_Handler() function in order to cope with MCUs with multiple banks of
// memory. // memory.
//***************************************************************************** //*****************************************************************************
__attribute__ ((section(".after_vectors.init_data"))) __attribute__ ((section(".after_vectors.init_data")))
@ -363,19 +363,23 @@ void bss_init(unsigned int start, unsigned int len) {
// contains the load address, execution address and length of each RW data // contains the load address, execution address and length of each RW data
// section and the execution and length of each BSS (zero initialized) section. // section and the execution and length of each BSS (zero initialized) section.
//***************************************************************************** //*****************************************************************************
extern unsigned int __data_section_table; extern unsigned int _sdata;
extern unsigned int __data_section_table_end; extern unsigned int _edata;
extern unsigned int __bss_section_table; extern unsigned int _sidata;
extern unsigned int __bss_section_table_end;
extern unsigned int _sbss;
extern unsigned int _ebss;
//***************************************************************************** //*****************************************************************************
// Reset entry point for your code. //Reset entry point for your code.
// Sets up a simple runtime environment and initializes the C/C++ //Sets up a simple runtime environment and initializes the C/C++
// library. //library.
//***************************************************************************** //*****************************************************************************
__attribute__ ((section(".after_vectors.reset"))) __attribute__ ((section(".after_vectors.reset")))
void ResetISR(void) { void Reset_Handler(void) {
/* Data and BSS variables */
unsigned int *srcdata, *dstdata, *sbss;
// Disable interrupts // Disable interrupts
__asm volatile ("cpsid i"); __asm volatile ("cpsid i");
@ -383,36 +387,41 @@ void ResetISR(void) {
__asm volatile ("LDR R0, =0x40000220\n\t" __asm volatile ("LDR R0, =0x40000220\n\t"
"MOV R1, #56\n\t" "MOV R1, #56\n\t"
"STR R1, [R0]"); "STR R1, [R0]");
// extern void Reset_ASM_Handler();
// Reset_ASM_Handler();
srcdata = &_sidata;
dstdata = &_sdata;
sbss = &_sbss;
/* Copy data */
while(dstdata != &_edata)
{
*(dstdata++) = *(srcdata++);
}
/* Clear BSS */
while(sbss != &_ebss)
{
*(sbss++) = '\0';
}
#if defined (__USE_CMSIS) #if defined (__USE_CMSIS)
// If __USE_CMSIS defined, then call CMSIS SystemInit code // If __USE_CMSIS defined, then call CMSIS SystemInit code
SystemInit(); SystemInit();
#endif // (__USE_CMSIS) #endif // (__USE_CMSIS)
// // //
// Copy the data sections from flash to SRAM. // // Copy the data sections from flash to SRAM.
// // //
unsigned int LoadAddr, ExeAddr, SectionLen; // //data_init(_sidata, _sdata, _edata - _sdata);
unsigned int *SectionTableAddr;
// Load base address of Global Section Table // // At this point, SectionTableAddr = &__bss_section_table;
SectionTableAddr = &__data_section_table; // // Zero fill the bss segment
// //bss_init(_sbss, _ebss - _sbss);
//bss_init(_sbss, _ebss - _sbss);
// Copy the data sections from flash to SRAM.
while (SectionTableAddr < &__data_section_table_end) {
LoadAddr = *SectionTableAddr++;
ExeAddr = *SectionTableAddr++;
SectionLen = *SectionTableAddr++;
data_init(LoadAddr, ExeAddr, SectionLen);
}
// At this point, SectionTableAddr = &__bss_section_table;
// Zero fill the bss segment
while (SectionTableAddr < &__bss_section_table_end) {
ExeAddr = *SectionTableAddr++;
SectionLen = *SectionTableAddr++;
bss_init(ExeAddr, SectionLen);
}
#if !defined (__USE_CMSIS) #if !defined (__USE_CMSIS)
// Assume that if __USE_CMSIS defined, then CMSIS SystemInit code // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code

View File

@ -38,9 +38,45 @@ void rt_init_thread_entry(void *parameter)
#endif #endif
} }
void build_dump(void)
{
#if defined(__CC_ARM)
rt_kprintf("using MDK\n");
#elif defined(__IAR_SYSTEMS_ICC__)
rt_kprintf("using IAR\n");
#elif defined(__GNUC__)
rt_kprintf("using GCC\n");
#else
rt_kprintf("unkown Compiler\n");
#endif
}
void link_dump(void)
{
extern unsigned int _sdata;
extern unsigned int _edata;
extern unsigned int _sidata;
extern unsigned int _sbss;
extern unsigned int _ebss;
#define DUMP_VAR(__VAR) \
rt_kprintf("%-20s %p\n", #__VAR, &__VAR)
DUMP_VAR(_sdata);
DUMP_VAR(_edata);
DUMP_VAR(_sidata);
DUMP_VAR(_sbss);
DUMP_VAR(_ebss);
}
int rt_application_init(void) int rt_application_init(void)
{ {
rt_thread_t tid; rt_thread_t tid;
build_dump();
link_dump();
tid = rt_thread_create("init", tid = rt_thread_create("init",
rt_init_thread_entry, RT_NULL, rt_init_thread_entry, RT_NULL,
2048, RT_THREAD_PRIORITY_MAX / 3, 20); 2048, RT_THREAD_PRIORITY_MAX / 3, 20);

View File

@ -7,7 +7,7 @@
MEMORY MEMORY
{ {
CODE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000 CODE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
DATA (rw) : ORIGIN = 0x10000000, LENGTH = 0x00010000 DATA (rw) : ORIGIN = 0x20000000, LENGTH = 0x00028000
} }
ENTRY(Reset_Handler) ENTRY(Reset_Handler)
_system_stack_size = 0x200; _system_stack_size = 0x200;
@ -17,7 +17,7 @@ SECTIONS
.text : .text :
{ {
. = ALIGN(4); . = ALIGN(4);
KEEP(*(.interrupt_vector)) /* Startup code */ KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4); . = ALIGN(4);
*(.text) /* remaining code */ *(.text) /* remaining code */
*(.text.*) /* remaining code */ *(.text.*) /* remaining code */

View File

@ -55,7 +55,7 @@ if PLATFORM == 'gcc':
CXXFLAGS = CFLAGS CXXFLAGS = CFLAGS
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' POST_ACTION = OBJCPY + ' -O ihex $TARGET rtthread.hex\n' + SIZE + ' $TARGET \n'
elif PLATFORM == 'armcc': elif PLATFORM == 'armcc':
# toolchains # toolchains