在Windows下,所需软件为MDK-ARM和STLINK驱动;在Linux下,则是开源stlink工具和ARM-GCC工具链,以及VSCode。
cut-off
以Kubuntu为例:
安装ARM-GCC工具链:
sudo apt install gcc-arm-none-eabi
安装VSCode:
选择deb安装包,下载并安装

https://code.visualstudio.com/
安装ST-Link工具:
选择最新版本,下载deb安装包并安装

https://github.com/stlink-org/stlink
安装完成后,由于快捷方式文件配置信息有错误,不能启动,需要手动修改,在/usr/share/applications打开终端:
kate stlink-gui.desktop
修改为以下内容,并保存:
[Desktop Entry]
Name=stlink
GenericName=Stlink Tools
Comment=Open source STM32 MCU programming toolset
Exec=stlink-gui
Path=/usr/share/stlink
Icon=stlink-gui
Terminal=false
Type=Application
Categories=Development;Electronics;
这次再点击stlink图标,发现可以启动了:

接下来是创建工程,以正点原子阿波罗STM32F429开发板为例:
mkdir arch arch/CMSIS bsp module src
touch Makefile stm32_flash.ld stm32_sram.ld
Makefile:
根据需要,修改ld文件和float_abi(soft/softfp/hard),文件位置
#-------------------------------------------------------------------------------
# File : Makefile
# This file is compiling ARM Cortex-M project.
#
# Change Logs:
# Date Author Notes
# 2021-08-04 LinuxLife the first version
#-------------------------------------------------------------------------------
#---------------------------------------
# Compile option
#---------------------------------------
toolchain := arm-none-eabi-
target := stm32f429
CC := $(toolchain)gcc
AS := $(toolchain)as
LD := $(toolchain)ld
OBJCOPY := $(toolchain)objcopy
OBJDUMP := $(toolchain)objdump
SIZE := $(toolchain)size
archive := cortex-m4
float_abi := soft
fpu := vfpv4
CC_CONFIG := -mcpu=$(archive) -mthumb -mfpu=$(fpu) -mfloat-abi=$(float_abi) -O0 -Ic -Igcc -ffunction-sections -fdata-sections
AS_CONFIG := -mcpu=$(archive) -mthumb -mfpu=$(fpu) -mfloat-abi=$(float_abi) -W -mimplicit-it=thumb
LD_CONFIG := -T stm32_flash.ld --gc-sections
#---------------------------------------
# source path
#---------------------------------------
INCDIRS := arch
arch/CMSIS
bsp
module/STM32F4xx_StdPeriph_Driver
module/STM32F4xx_StdPeriph_Driver/inc
src
SRCDIRS := arch
arch/CMSIS
bsp
module/STM32F4xx_StdPeriph_Driver/src
src
LIBDIRS :=
#---------------------------------------
# get source file
#---------------------------------------
INCLUDE := $(patsubst %, -I %, $(INCDIRS))
# get file
SFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.s))
ASMFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.asm))
CFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))
LIBFILES := $(foreach dir, $(LIBDIRS), $(wildcard $(dir)/*.a))
# get file path
SFILENDIR := $(notdir $(SFILES))
ASMFILENDIR := $(notdir $(ASMFILES))
CFILENDIR := $(notdir $(CFILES))
LIBFILENDIR := $(notdir $(LIBFILES))
# get object file
SOBJS := $(patsubst %, %, $(SFILENDIR:.s=.o))
ASMOBJS := $(patsubst %, %, $(ASMFILENDIR:.asm=.o))
COBJS := $(patsubst %, %, $(CFILENDIR:.c=.o))
OBJS := $(SOBJS) $(COBJS) $(ASMOBJS)
VPATH := $(SRCDIRS)
.PHONY: clean
#---------------------------------------
# start compiling
#---------------------------------------
$(target).bin : $(OBJS)
$(LD) $(LD_CONFIG) -o $(target).elf $^ $(LIBFILES)
$(OBJCOPY) -O binary -S $(target).elf $@
$(OBJDUMP) -D -m armv7 $(target).elf > $(target).dis
$(SIZE) -d $(target).elf
$(SOBJS) : %.o : %.s
$(AS) $(AS_CONFIG) -o $@ $<
$(ASMOBJS) : %.o : %.asm
$(AS) $(AS_CONFIG) -o $@ $<
$(COBJS) : %.o : %.c
$(CC) $(CC_CONFIG) $(INCLUDE) -c -o $@ $<
#---------------------------------------
# clean object file
#---------------------------------------
clean:
rm *.elf *.dis *.bin *.o
ROM和RAM链接文件,使程序分别在两种存储中运行,前者用于正式产品中,后者用于调试,延长flash使用寿命,根据需要修改地址和容量即可,同时编译时可以检测程序是否过大:
/*
* file :stm32_flash.ld
*
* abstract :Linker script for STM32 Device
* Set heap size, stack size and stack location according to
* application requirements.
* Set memory bank area and size if external memory is used.
*
* environment:arm-none-eabi-
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x2001C000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = 0x800; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
/* 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) */
*(.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.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.ARM.attributes : { *(.ARM.attributes) } > 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 */
._user_heap_stack :
{
. = ALIGN(4);
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
}
}
/*
* file :stm32_sram.ld
*
* abstract :Linker script for STM32 Device
* Set heap size, stack size and stack location according to
* application requirements.
* Set memory bank area and size if external memory is used.
*
* environment:arm-none-eabi-
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x2001C000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x1000; /* required amount of heap */
_Min_Stack_Size = 0x1000; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x20000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20010000, LENGTH = 48K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
/* 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) */
上一篇:STM32CubeIDE软件下载安装、汉化、主题修改、固件下载地址设置
下一篇:STM32 嵌入式编程:一步一步走向成功
推荐阅读最新更新时间:2026-03-23 19:45
- LTC2172CUKG-12、12 位、65Msps 低功耗四通道 ADC 的典型应用电路
- 使用 ROHM Semiconductor 的 BD5339 的参考设计
- 使用 Diodes Incorporated 的 PT8A3517 的参考设计
- LT5527 400MHz 至 3.7GHz 高信号电平下变频混频器的典型应用
- AD5340 并行接口、单电压输出、12 位 DAC 的典型应用
- 30W、-27V、5.8V、5.8V、15V、24V、33V交流转直流多路输出电源
- OP213FSZ-REEL7 低噪声运算放大器电压基准的典型应用
- LT3579/LT3579-1 演示板,升压 / 反相 DC/DC 转换器
- L7815A 光控制器稳压器的典型应用 (Vo(min) = Vxx + VBE)
- 具有关断功能的 LT1086CT-5 5V 稳压器的典型应用



STM32模拟串口
dm9000cep网卡通信
非常经典的关于LLC的杨波博士论文
LMP8671MA/NOPB
1CIS223-04TG3M






京公网安备 11010802033920号