The .bin built by arm-none-eabi-gcc cannot execute on stm32f2xx
I built a stm32f2xx project with BSP and uCOS by arm-none-eabi-gcc on both windows and ubuntu. But both binaries cannot be executed on the board. I don't know what's wrong with it. The project can be built by Keil, and the binary can be executed on the board. Could anyone help me? Thank you very much!
I have no error in compiling and linking on Ubuntu. But the binary cannot be executed. Here is the makefile.
-------
DEFS += -DUSE_STDPERIPH
INCS += -I./BSP/
# 使用其他外设在这里添加
OBJS += startup_stm32f2xx.o
OBJS += BSP/CMSIS/
OBJS += User/main.o
OBJS += User/app_hooks.o
OBJS += BSP/BSP_ELF.o
OBJS += BSP/BSP_ELF_GPIO.o
OBJS += BSP/BSP_ELF_CAN.o
OBJS += BSP/BSP_ELF_Disp.o
OBJS += BSP/BSP_ELF_RTC.o
OBJS += BSP/BSP_
OBJS += BSP/BSP_
OBJS += BSP/BSP_ELF_SPI.o
OBJS += BSP/BSP_
OBJS += BSP/BSP_ELF_UART.o
OBJS += BSP/BSP_ELF_MAC.o
OBJS += BSP/BSP_
OBJS += uC-CPU/cpu_core.o
OBJS += uC-CPU/
OBJS += uC-CPU/
OBJS += uC-LIB/lib_ascii.o
OBJS += uC-LIB/lib_math.o
OBJS += uC-LIB/lib_mem.o
OBJS += uC-LIB/lib_str.o
OBJS += uC-LIB/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += uCOS-II/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += BSP/STM32F2xx/
OBJS += ComponentLib/
OBJS += ComponentLib/
OBJS += ComponentLib/
OBJS += ComponentLib/
# 使用了编译优化和硬件浮点数
CFLAGS += -Wall -mthumb -g -O0 -ffunction-sections -fdata-sections -g3 -mcpu=cortex-m3
LFLAGS += -mthumb -Wl,--gc-sections -mcpu=cortex-m3
# 最后生成的bin文件
all:blink.bin
clean:
@rm -f $(OBJS) $(OBJ_FLASH) $(OBJ_SRAM)
@rm -f blink.bin blink.elf
blink.bin:blink.elf
@arm-none-
blink.elf:$(OBJS) $(OBJ_FLASH)
@arm-none-eabi-gcc $(LFLAGS) $^ -TSTM32_Flash.ld -o $@
@arm-none-
#burn:blink.bin
# @st-flash write $< 0x08000000
%.o:%.S
@echo cc: $<
@arm-none-eabi-gcc $(CFLAGS) -c $< -o $@
%.o:%.c
@echo cc: $<
@arm-none-eabi-gcc $(CFLAGS) $(DEFS) $(INCS) -c $< -o $@
-------
I met an error in linking on windows, undefined reference to _sbrk. So I add --specs=nosys.specs option in the linking step and add symbol "end" in the .ld file, the linking succeed. However, the binary cannot be executed. Here is the .bat file.
-------
@echo off
SET CPU_TYPE=
SET CPU_VENDOR=
SET UV2_TARGET=
SET CPU_CLOCK=
SET INCLUDE_
SET OUTPUT=batoutput
SET G++=arm-
SET CC=arm-
SET OBJCPY=
SET DEF=-DUSE_
SET CFLAGS=-Wall -mthumb -g -O0 -ffunction-sections -fdata-sections -g3 -mcpu=cortex-m3
SET LFLAGS=-mthumb -Wl,--gc-sections -mcpu=cortex-m3
%CC% %CFLAGS% -c startup_stm32f2xx.S -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\CMSIS\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c User\main.c -o %OUTPUT%\main.o
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c User\app_hooks.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF.c -o %OUTPUT%\BSP_ELF.o
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF_GPIO.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF_CAN.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF_Disp.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF_RTC.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF_SPI.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF_UART.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_ELF_MAC.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\BSP_
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uC-CPU\cpu_core.c -o %OUTPUT%\cpu_core.o
%CC% %CFLAGS% -c uC-CPU\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uC-CPU\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uC-LIB\lib_ascii.c -o %OUTPUT%
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uC-LIB\lib_math.c -o %OUTPUT%\lib_math.o
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uC-LIB\lib_mem.c -o %OUTPUT%\lib_mem.o
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uC-LIB\lib_str.c -o %OUTPUT%\lib_str.o
%CC% %CFLAGS% -c uC-LIB\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %CFLAGS% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c uCOS-II\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c BSP\STM32F2xx\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c ComponentLib\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c ComponentLib\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c ComponentLib\
%CC% %DEF% %CFLAGS% %INCLUDE_DIR% -c ComponentLib\
%CC% -o %OUTPUT%
%OBJCPY% -O binary %OUTPUT%
-------
Here is the .ld file. I should copy the .bin to 0x08040000 address to startup. This address is tested by the .bin file created by Keil.
-------
/* Entry Point */
ENTRY(Reset_
/* Highest address of the user mode stack */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x1000; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 100K
/* PARAM_SECTOR (rx) : ORIGIN = 0x08008000, LENGTH = 16K */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 40K
/* MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K */
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.
.ARM : {
__exidx_start = .;
*
__exidx_end = .;
} >FLASH
.ARM.attributes : { *(.ARM.attributes) } > FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_
KEEP (*(.preinit_
PROVIDE_HIDDEN (__preinit_
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array*))
KEEP (*(SORT(
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = .;
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT ( _sidata )
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* PROVIDE ( end = _ebss ); */
/* PROVIDE ( _end = _ebss ); */
/* User_heap_stack section, used to check that there is enough RAM left */
/* embOS needs some dedicated labels for heap- and stack-check */
/* The heap has to start with the label __heap_start__ */
/* The heap has to end with the label __heap_end__ */
/* The stack has to start with the label __stack_start__ */
/* The stack has to end with the label __stack_end__ */
._user_heap_stack :
{
. = ALIGN(8);
__heap_start__ = .;
end = __heap_start__;
. = . + _Min_Heap_Size;
__heap_end__ = .;
. = ALIGN(8);
__stack_start__ = .;
. = . + _Min_Stack_Size;
__stack_end__ = .;
_estack = .;
. = ALIGN(8);
} >RAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
/* libg.a ( * ) */
/* libnosys.a ( * ) */
}
}
-------
Question information
- Language:
- English Edit question
- Status:
- Expired
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: