历史上的今天
今天是:2025年07月26日(星期六)
2019年07月26日 | STM32原有的MDK工程下移植到GCC环境
2019-07-26 来源:eefocus
1. 增加 STM32F429IGTx_FLASH.ld 这个文件存放芯片内存信息
STM32F429IGTx_FLASH.ld主要存放的是芯片内存的信息,堆栈大小,RAM,Flash大小, MEMORY{ }中存放的内存段,程序中有使用明确内存的地址的地方要在这里定义。
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20020000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x400; /* required amount of heap */
_Min_Stack_Size = 0x800; /* required amount of stack */
/*
RAM 内部RAM
FlASH 内部FLASH
EXTSRAM 外部SRAM
CCMSRAM 内部CCM
EXTABLE malloc.c中内存管理用
CCMTABLE malloc.c中内存管理用
LCDMEM 显存
*/
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 768K
EXTSRAM(xrw) : ORIGIN = 0XC01F4000, LENGTH = 28912K
CCMSRAM(xrw) : ORIGIN = 0X10000000, LENGTH = 60K
EXTABLE(xrw) : ORIGIN = 0xC1E30000, LENGTH = 1807K
CCMTABLE(xrw) : ORIGIN = 0x1000f000, LENGTH = 4K
LCDMEM(xrw) : ORIGIN = 0xC0000000, LENGTH = 1500K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = 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 AT> FLASH
/* 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
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
/* 可用外部内存 */
.extsram 0XC01F4000 (NOLOAD):
{
. = ALIGN(4);
*(.exsram)
*(.exsram*)
. = ALIGN(4);
} AT > EXTSRAM
/* 可用CCM内存 */
.ccmsram 0x10000000 (NOLOAD):
{
. = ALIGN(4);
*(.ccmsram)
*(.ccmsram*)
. = ALIGN(4);
} AT > CCMSRAM
/* 外部内存管理 */
.exttable 0xC1E30000 (NOLOAD):
{
. = ALIGN(4);
*(.extable)
*(.extable*)
. = ALIGN(4);
} AT > EXTABLE
/* 内部CCM内存管理 */
.ccmtable 0x1000f000 (NOLOAD):
{
. = ALIGN(4);
*(.ccmtable)
*(.ccmtable*)
. = ALIGN(4);
} AT > CCMTABLE
/* LCD显存 */
.lcdmem 0xC0000000 (NOLOAD):
{
. = ALIGN(4);
*(.lcdmem)
*(.lcdmem*)
. = ALIGN(4);
} AT > LCDMEM
}
2. 增加 Makefile 文件
Makefile 可以用STM32cubeMX直接生成,其格式也可以参考。这里放一个用STM32cubeMX生成的
######################################
# target
######################################
TARGET = 12
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -Og
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
C_SOURCES =
Src/main.c
# ASM sources
ASM_SOURCES =
startup_stm32f439xx.s
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m4
# fpu
FPU = -mfpu=fpv4-sp-d16
# float-abi
FLOAT-ABI = -mfloat-abi=hard
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# C defines
C_DEFS =
-DUSE_HAL_DRIVER
-DSTM32F439xx
# AS includes
AS_INCLUDES =
-IInc
# C includes
C_INCLUDES =
-IInc
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32F439IGTx_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
3. 替换 CORE/startup_stm32f429xx.s 文件 在STM32库中可以查到,共三个版本 GCC、MDK、IAR
4. 增加 CORE/cmsis_gcc.h 文件 GCC环境
5. 修改 SYSTEM/src/sys.c 文件 GCC环境
文件底部的汇编部分需要修改
//THUMB指令不支持汇编内联
//采用如下方法实现执行汇编指令WFI
void WFI_SET (void)
{
__asm__ __volatile__("WFI");
}
//关闭所有中断(但是不包括fault和NMI中断)
void INTX_DISABLE(void)
{
__asm__ __volatile__("CPSID I");
史海拾趣
|
高人指教下 用在8051 p0.1--p0.5口上的 光点隔离 和继电驱动 最好有99se编辑好的原理图 一般画的也行 我对单片机不太了解 所以各位高人见谅 谢谢了 &nbs ...… 查看全部问答> |
|
大侠快来救命阿,关于AM29LV320D的软件方法去除写保护问题?? 我试了很多AM29LV320D的flash,bottom boot的,都是前四个扇区写保护了?这是什么原因?手册中没有找到软件方法去除写保护的命令,那这些扇区怎么写保护的,怎么去除呢。现在其他扇区都可以正常读写… 查看全部问答> |
|
看到一种比较特殊的写法, \"0123456789abcdef\" [ i ],看起来挺神奇的,暂时理解成匿名的全局字符串变量指针吧,期待有一天能用上吧。 补充一下,还有这样写的: 5[\"hello world!\"] [ 本帖最后由 medky 于 2011-5-14 19:28 编辑 ]… 查看全部问答> |
|
在一个工程中做了些改动,其中一个函数分离出去测试,怎么测怎么通,,一点问题没有,放到大程序里就一点反应没有了,,崩溃了。。支持一下啊,希望能调通。。。 [ 本帖最后由 aahellaa 于 2011-8-16 10:29 编辑 ]… 查看全部问答> |




