keil 中添加gcc编译 stmf207
一、安装下载arm-gcc 编译器:
二、在keil中配置gcc:

三、配置工程选项
1.配置gcc编译规则:
Misc Controls : -mcpu=cortex-m3 -mthumb -fdata-sections -ffunction-sections
注:
1.这里我用的cortex-m3,如果你是m4内核就改成4)
2.-mthumb的意义是:使用这个编译选项生成的目标文件是Thumb的
3.-fdata-sections和-ffunction-sections (-ffunction-sections 和 -fdata-sections 将每个函数或符号创建为一个sections,其中每个sections名与function或data名保持一致)

2.配置汇编规则:
Misc Controls : -mcpu=cortex-m3 -mthumb

3配置链接规则:
这里要添加链接脚本,一般可以在官方提供的固件库包找到类似的(链接规则)
Misc Controls : -Wl,--gc-sections
注:
1.-wl, 表示后面的参数 --gc-sections 传递给链接器( -Wl,--gc-sections 指示链接器去掉不用的section(其中-wl, 表示后面的参数 --gc-sections 传递给链接器),这样就能减少最终的可执行程序的大小了。)

4.找到适合自己芯片的链接文件(在官方例程有):

其内容:
/*
*****************************************************************************
**
** File : stm32_flash.ld
**
** Abstract : Linker script for STM32F207IG Device with
** 1MByte FLASH, 128KByte SRAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
** Environment : Atollic TrueSTUDIO(R)
**
** Distribution: The file is distributed “as is,” without any warranty
** of any kind.
**
** (c)Copyright Atollic AB.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the Atollic TrueSTUDIO(R) toolchain.
**
*****************************************************************************
*//* Entry Point */
ENTRY(Reset_Handler)/* Highest address of the user mode stack */
_estack = 0x20020000; /* end of 128K SRAM *//* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = 0x200; /* required amount of stack *//* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
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 */
*(.eh_frame)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.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 (*(.fini_array*))
KEEP (*(SORT(.fini_array.*)))
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;
} >RAMPROVIDE ( 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/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}.ARM.attributes 0 : { *(.ARM.attributes) }
}
注意:
编译报错
ld.exe: section .ARM.exidx LMA [08009914,0800991b] overlaps section .data LMA [08009914,08009fe3]
/* 添加.ARM.exidx段 */
.ARM.exidx : {
. = ALIGN(4);
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
. = ALIGN(4);
} >FLASH能解决报错问题,运行不了程序(需要找到自己的链接文件)
四、启动代码,使用GCC专用的.S文件
使用GCC编译器需要的启动代码不同与AMRCC,不过官方已经有提供了相关代码,如下图:

五、解决编译报错:
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'

添加 syscall.c
/**
*****************************************************************************
**
** File : syscalls.c
**
** Abstract : System Workbench Minimal System calls file
**
** For more information about which c-functions
** need which of these lowlevel functions
** please consult the Newlib libc-manual
**
** Environment : System Workbench for MCU
**
** Distribution: The file is distributed ¡°as is,¡± without any warranty
** of any kind.
**
** (c)Copyright System Workbench for MCU.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. System Workbench for MCU permit registered System Workbench(R) users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the System Workbench for MCU toolchain.
**
*****************************************************************************
*//* Includes */
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
/* Variables */
//#undef errno
extern int errno;
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));register char * stack_ptr asm("sp");
char *__env[1] = { 0 };
char **environ = __env;
/* Functions */
void initialise_monitor_handles()
{
}int _getpid(void)
{
return 1;
}int _kill(int pid, int sig)
{
errno = EINVAL;
return -1;
}void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}int _read (int file, char *ptr, int len)
{
int DataIdx;for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}return len;
}int _write(int file, char *ptr, int len)
{
int DataIdx;for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}caddr_t _sbrk(int incr)
{
extern char end asm("end");
static char *heap_end;
char *prev_heap_end;if (heap_end == 0)
heap_end = &end;prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
// write(1, "Heap and stack collision\n", 25);
// abort();
errno = ENOMEM;
return (caddr_t) -1;
}heap_end += incr;
return (caddr_t) prev_heap_end;
}int _close(int file)
{
return -1;
}
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}int _isatty(int file)
{
return 1;
}int _lseek(int file, int ptr, int dir)
{
return 0;
}int _open(char *path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
}int _wait(int *status)
{
errno = ECHILD;
return -1;
}int _unlink(char *name)
{
errno = ENOENT;
return -1;
}int _times(struct tms *buf)
{
return -1;
}int _stat(char *file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}int _link(char *old, char *new)
{
errno = EMLINK;
return -1;
}int _fork(void)
{
errno = EAGAIN;
return -1;
}int _execve(char *name, char **argv, char **env)
{
errno = ENOMEM;
return -1;
}
编译通过,成功运行:

相关文章:
keil 中添加gcc编译 stmf207
一、安装下载arm-gcc 编译器: 二、在keil中配置gcc: 三、配置工程选项 1.配置gcc编译规则: Misc Controls : -mcpucortex-m3 -mthumb -fdata-sections -ffunction-sections 注: 1.这里我用的cortex-m3,如果你是m4内核…...
BEV相关
1.deformable DETR是在DETR基础上做了什么 Deformable DETR 是对经典 DETR(Detection Transformer)进行的改进,旨在解决 DETR 训练速度慢、对大目标的定位不精确等问题。它主要在以下几个方面做了优化: 稀疏的多尺度注意力机制&a…...
nodepad++带时间段的关键字搜索筛选
10:11:[2-3][0-9].(com.asus.rogforum) 如图:冒号后面的[2-3]表示秒的十位20秒到30秒之间,如果想筛选多个则(com.asus.rogforum)中的多个关键字之间用|分隔...
【理论笔记】网工基础知识 1 —— 计算机网络基础知识
提示:学习网络工程师基础理论知识 计算机网络相关的基础知识 包括计算机网络的基本概念、组成部分、主要功能、分类、性能、常见术语、以及网络标准化组织 一、计算机网络的概述 1、计算机网络的基本概念 把分布在不同地理区域具有独立工作能力的计算机、终端&am…...
Z 字形变换
题目 将一个给定字符串 s 根据给定的行数 numRows ,以从上往下、从左到右进行 Z 字形排列。 比如输入字符串为 “PAYPALISHIRING” 行数为 3 时,排列如下: P A H N A P L S I I G Y I R之后,你的输出需要从左往右逐行…...
在JasperReports中自动生成序列号
前言 JasperReports是一个强大的Java报表工具,可以生成PDF、Excel、HTML等多种格式的报表。在设计报表时,我们经常需要为每条记录添加一个唯一的序号。本文将详细介绍如何在JasperReports中实现这一功能。 准备工作 在开始之前,请确保您已…...
SpringBoot3 + MyBatisPlus 快速整合
一、前言 MyBatis 最佳搭档,只做增强不做改变,为简化开发、提高效率而生。 这个发展到目前阶段已经很成熟了,社区也比较活跃,可以放心使用。官网地址:https://baomidou.com 二、快速开始 引入依赖 这里我引入了核心…...
单片机(学习)2024.10.9
目录 汇编整体分类 1.指令 2.伪操作 3.伪指令 汇编代码 汇编初始化 数据搬运指令 算术运算指令 加法 减法 乘法 比较指令 跳转指令 逻辑运算指令 与或,异或 左移右移 内存操作 LOAD/STORE 指令 写 读 CPU的栈机制 栈的概念 栈的种类 1.空栈(…...
操作符详解(C 语言)
目录 一、操作符的分类二、算数操作符1. 除法操作符2. 取余操作符 三、位移操作符1. 进制2. 原码、反码和补码3. 左移操作符(<<)和右移操作符(>>) 四、位操作符1. 按位与 &2. 按位或 |3. 按位异或 ^4. 按位取反 ~…...
自动化测试数据:如何正确地选择不同格式文件「详细介绍」?
自动化测试数据:如何正确地选择不同格式文件「详细介绍」? 前言1. 不同的格式文件对比2. 读取文件2.1 读取Excel文件2.2 读取CSV文件2.3 读取YAML文件2.3.1 字典2.3.2 列表2.3.3 混合类型2.3.4 包含列表的字典2.3.5 包含字典的列表2.3.6 复杂嵌套 2.4 读…...
OceanBase中扩容OCP节点step by step
许多用户在开始使用OceanBase时部署OCP,通常选择单节点部署。但随着后续业务规模的不断扩大,会开始担忧单节点OCP在面对故障时可能丧失对集群运维管控的连续性。鉴于此,会将现有的单节点OCP扩展至多节点部署,以此来确保OCP服务的高…...
国家人工智能创新应用先导区数据及城市人工智能先导区准自然实验数据(2006-2023年)
一、测算方式:参考C刊《当代财经》冯婉昕(2024)老师的做法,本文的核心解释变量为国家人工智能创新应用先导区政策 (AI)。企业的金融资产配置是企业生产经营的内生变量,因此,如果选择…...
搜维尔科技:感受、握持、推动、连接和挤压虚拟物体,SenseGlove触觉反馈手套拥有先进的触觉技术、一流的可用性和功能
感受、握持、推动、连接和挤压虚拟物体,SenseGlove触觉反馈手套拥有先进的触觉技术、一流的可用性和功能 感受、握持、推动、连接和挤压虚拟物体,SenseGlove触觉反馈手套拥有先进的触觉技术、一流的可用性和功能...
C++中的引用详解
C中的引用详解 什么是引用 引用是一种取别名的机制,用于为变量提供一个新的名字。在C中,引用的语法使用&符号。引用允许我们以一种更安全和直观的方式来操作变量。 为什么要使用指针 在C中,虽然引用提供了一些优势,但指针仍…...
软考中级 - 软件设计师学习笔记 - 1.3 计算机安全
1.3.1 安全威胁 计算安全:指的是计算机资产安全,是要保证这些计算机资产不受自然和人为的有害因素的威胁和危害。 1.3.2 加密技术和认证技术 加密技术:对称加密(私有密钥加密)、非对称加密(公开密钥加密)。对称加密(私钥/私有密…...
Unity3D相关知识点总结
Unity3D使用的是笛卡尔三维坐标系,并且是以左手坐标系进行展示的。 1.全局坐标系(global) 全局坐标系描述的是游戏对象在整个世界(场景)中的相对于坐标原点(0,0,0)的位置…...
牛顿迭代多维+原理推导
这是两个函数了两个变量的情况,对于三个函数两个变量,牛顿迭代的雅可比矩阵不能求逆, 右边的增量的求解就不能用这个公式了呢。对于有逆矩阵但不能求逆的公式,这个逆矩阵是求解线性方程时出现的,就可用不求逆的方法解…...
[自然语言处理]RNN
1 传统RNN模型与LSTM import torch import torch.nn as nntorch.manual_seed(6)# todo:基础RNN模型 def dem01():参数1:input_size 每个词的词向量维度(输入层神经元的个数)参数2:hidden_size 隐藏层神经元的个数参数3:…...
MySQL(B站CodeWithMosh)——2024.10.11(14)
ZZZZZZ目的ZZZZZZ代码ZZZZZZ重点ZZZZZZ操作(非代码,需要自己手动) 8- CASE运算符The CASE Operator_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1UE41147KC?p62&vd_sourceeaeec77dfceb13d96cce76cc299fdd08 在sql_store中&am…...
Transformer的预训练模型
Transformer的预训练模型有很多,其中一些在自然语言处理(NLP)和计算机视觉等领域取得了巨大成功。以下是一些主要的Transformer预训练模型: 1. BERT (Bidirectional Encoder Representations from Transformers) 简介: BERT 是谷歌推出的双向Transformer模型,专注于编码器…...
学校招生小程序源码介绍
基于ThinkPHPFastAdminUniApp开发的学校招生小程序源码,专为学校招生场景量身打造,功能实用且操作便捷。 从技术架构来看,ThinkPHP提供稳定可靠的后台服务,FastAdmin加速开发流程,UniApp则保障小程序在多端有良好的兼…...
屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!
5月28日,中天合创屋面分布式光伏发电项目顺利并网发电,该项目位于内蒙古自治区鄂尔多斯市乌审旗,项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站,总装机容量为9.96MWp。 项目投运后,每年可节约标煤3670…...
Keil 中设置 STM32 Flash 和 RAM 地址详解
文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...
Java入门学习详细版(一)
大家好,Java 学习是一个系统学习的过程,核心原则就是“理论 实践 坚持”,并且需循序渐进,不可过于着急,本篇文章推出的这份详细入门学习资料将带大家从零基础开始,逐步掌握 Java 的核心概念和编程技能。 …...
Unit 1 深度强化学习简介
Deep RL Course ——Unit 1 Introduction 从理论和实践层面深入学习深度强化学习。学会使用知名的深度强化学习库,例如 Stable Baselines3、RL Baselines3 Zoo、Sample Factory 和 CleanRL。在独特的环境中训练智能体,比如 SnowballFight、Huggy the Do…...
SiFli 52把Imagie图片,Font字体资源放在指定位置,编译成指定img.bin和font.bin的问题
分区配置 (ptab.json) img 属性介绍: img 属性指定分区存放的 image 名称,指定的 image 名称必须是当前工程生成的 binary 。 如果 binary 有多个文件,则以 proj_name:binary_name 格式指定文件名, proj_name 为工程 名&…...
【Go语言基础【12】】指针:声明、取地址、解引用
文章目录 零、概述:指针 vs. 引用(类比其他语言)一、指针基础概念二、指针声明与初始化三、指针操作符1. &:取地址(拿到内存地址)2. *:解引用(拿到值) 四、空指针&am…...
Go 并发编程基础:通道(Channel)的使用
在 Go 中,Channel 是 Goroutine 之间通信的核心机制。它提供了一个线程安全的通信方式,用于在多个 Goroutine 之间传递数据,从而实现高效的并发编程。 本章将介绍 Channel 的基本概念、用法、缓冲、关闭机制以及 select 的使用。 一、Channel…...
智警杯备赛--excel模块
数据透视与图表制作 创建步骤 创建 1.在Excel的插入或者数据标签页下找到数据透视表的按钮 2.将数据放进“请选择单元格区域“中,点击确定 这是最终结果,但是由于环境启不了,这里用的是自己的excel,真实的环境中的excel根据实训…...
【多线程初阶】单例模式 指令重排序问题
文章目录 1.单例模式1)饿汉模式2)懒汉模式①.单线程版本②.多线程版本 2.分析单例模式里的线程安全问题1)饿汉模式2)懒汉模式懒汉模式是如何出现线程安全问题的 3.解决问题进一步优化加锁导致的执行效率优化预防内存可见性问题 4.解决指令重排序问题 1.单例模式 单例模式确保某…...
