当前位置: 首页 > news >正文

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;
  } >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/ :
  {
    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 编译器&#xff1a; 二、在keil中配置gcc&#xff1a; 三、配置工程选项 1.配置gcc编译规则&#xff1a; Misc Controls : -mcpucortex-m3 -mthumb -fdata-sections -ffunction-sections 注&#xff1a; 1.这里我用的cortex-m3&#xff0c;如果你是m4内核…...

BEV相关

1.deformable DETR是在DETR基础上做了什么 Deformable DETR 是对经典 DETR&#xff08;Detection Transformer&#xff09;进行的改进&#xff0c;旨在解决 DETR 训练速度慢、对大目标的定位不精确等问题。它主要在以下几个方面做了优化&#xff1a; 稀疏的多尺度注意力机制&a…...

nodepad++带时间段的关键字搜索筛选

10:11:[2-3][0-9].(com.asus.rogforum) 如图&#xff1a;冒号后面的[2-3]表示秒的十位20秒到30秒之间&#xff0c;如果想筛选多个则(com.asus.rogforum)中的多个关键字之间用|分隔...

【理论笔记】网工基础知识 1 —— 计算机网络基础知识

提示&#xff1a;学习网络工程师基础理论知识 计算机网络相关的基础知识 包括计算机网络的基本概念、组成部分、主要功能、分类、性能、常见术语、以及网络标准化组织 一、计算机网络的概述 1、计算机网络的基本概念 把分布在不同地理区域具有独立工作能力的计算机、终端&am…...

Z 字形变换

题目 将一个给定字符串 s 根据给定的行数 numRows &#xff0c;以从上往下、从左到右进行 Z 字形排列。 比如输入字符串为 “PAYPALISHIRING” 行数为 3 时&#xff0c;排列如下&#xff1a; P A H N A P L S I I G Y I R之后&#xff0c;你的输出需要从左往右逐行…...

在JasperReports中自动生成序列号

前言 JasperReports是一个强大的Java报表工具&#xff0c;可以生成PDF、Excel、HTML等多种格式的报表。在设计报表时&#xff0c;我们经常需要为每条记录添加一个唯一的序号。本文将详细介绍如何在JasperReports中实现这一功能。 准备工作 在开始之前&#xff0c;请确保您已…...

SpringBoot3 + MyBatisPlus 快速整合

一、前言 MyBatis 最佳搭档&#xff0c;只做增强不做改变&#xff0c;为简化开发、提高效率而生。 这个发展到目前阶段已经很成熟了&#xff0c;社区也比较活跃&#xff0c;可以放心使用。官网地址&#xff1a;https://baomidou.com 二、快速开始 引入依赖 这里我引入了核心…...

单片机(学习)2024.10.9

目录 汇编整体分类 1.指令 2.伪操作 3.伪指令 汇编代码 汇编初始化 数据搬运指令 算术运算指令 加法 减法 乘法 比较指令 跳转指令 逻辑运算指令 与或&#xff0c;异或 左移右移 内存操作 LOAD/STORE 指令 写 读 CPU的栈机制 栈的概念 栈的种类 1.空栈(…...

操作符详解(C 语言)

目录 一、操作符的分类二、算数操作符1. 除法操作符2. 取余操作符 三、位移操作符1. 进制2. 原码、反码和补码3. 左移操作符&#xff08;<<&#xff09;和右移操作符&#xff08;>>&#xff09; 四、位操作符1. 按位与 &2. 按位或 |3. 按位异或 ^4. 按位取反 ~…...

自动化测试数据:如何正确地选择不同格式文件「详细介绍」?

自动化测试数据&#xff1a;如何正确地选择不同格式文件「详细介绍」&#xff1f; 前言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&#xff0c;通常选择单节点部署。但随着后续业务规模的不断扩大&#xff0c;会开始担忧单节点OCP在面对故障时可能丧失对集群运维管控的连续性。鉴于此&#xff0c;会将现有的单节点OCP扩展至多节点部署&#xff0c;以此来确保OCP服务的高…...

国家人工智能创新应用先导区数据及城市人工智能先导区准自然实验数据(2006-2023年)

一、测算方式&#xff1a;参考C刊《当代财经》冯婉昕&#xff08;2024&#xff09;老师的做法&#xff0c;本文的核心解释变量为国家人工智能创新应用先导区政策 &#xff08;AI&#xff09;。企业的金融资产配置是企业生产经营的内生变量&#xff0c;因此&#xff0c;如果选择…...

搜维尔科技:感受、握持、推动、连接和挤压虚拟物体,SenseGlove触觉反馈手套拥有先进的触觉技术、一流的可用性和功能

感受、握持、推动、连接和挤压虚拟物体&#xff0c;SenseGlove触觉反馈手套拥有先进的触觉技术、一流的可用性和功能 感受、握持、推动、连接和挤压虚拟物体&#xff0c;SenseGlove触觉反馈手套拥有先进的触觉技术、一流的可用性和功能...

C++中的引用详解

C中的引用详解 什么是引用 引用是一种取别名的机制&#xff0c;用于为变量提供一个新的名字。在C中&#xff0c;引用的语法使用&符号。引用允许我们以一种更安全和直观的方式来操作变量。 为什么要使用指针 在C中&#xff0c;虽然引用提供了一些优势&#xff0c;但指针仍…...

软考中级 - 软件设计师学习笔记 - 1.3 计算机安全

1.3.1 安全威胁 计算安全&#xff1a;指的是计算机资产安全&#xff0c;是要保证这些计算机资产不受自然和人为的有害因素的威胁和危害。 1.3.2 加密技术和认证技术 加密技术&#xff1a;对称加密(私有密钥加密)、非对称加密(公开密钥加密)。对称加密&#xff08;私钥/私有密…...

Unity3D相关知识点总结

Unity3D使用的是笛卡尔三维坐标系&#xff0c;并且是以左手坐标系进行展示的。 1.全局坐标系&#xff08;global&#xff09; 全局坐标系描述的是游戏对象在整个世界&#xff08;场景&#xff09;中的相对于坐标原点&#xff08;0&#xff0c;0&#xff0c;0&#xff09;的位置…...

牛顿迭代多维+原理推导

这是两个函数了两个变量的情况&#xff0c;对于三个函数两个变量&#xff0c;牛顿迭代的雅可比矩阵不能求逆&#xff0c; 右边的增量的求解就不能用这个公式了呢。对于有逆矩阵但不能求逆的公式&#xff0c;这个逆矩阵是求解线性方程时出现的&#xff0c;就可用不求逆的方法解…...

[自然语言处理]RNN

1 传统RNN模型与LSTM import torch import torch.nn as nntorch.manual_seed(6)# todo:基础RNN模型 def dem01():参数1&#xff1a;input_size 每个词的词向量维度&#xff08;输入层神经元的个数&#xff09;参数2&#xff1a;hidden_size 隐藏层神经元的个数参数3&#xff1a…...

MySQL(B站CodeWithMosh)——2024.10.11(14)

ZZZZZZ目的ZZZZZZ代码ZZZZZZ重点ZZZZZZ操作&#xff08;非代码&#xff0c;需要自己手动&#xff09; 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模型,专注于编码器…...

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…...

多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度​

一、引言&#xff1a;多云环境的技术复杂性本质​​ 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时&#xff0c;​​基础设施的技术债呈现指数级积累​​。网络连接、身份认证、成本管理这三大核心挑战相互嵌套&#xff1a;跨云网络构建数据…...

ubuntu搭建nfs服务centos挂载访问

在Ubuntu上设置NFS服务器 在Ubuntu上&#xff0c;你可以使用apt包管理器来安装NFS服务器。打开终端并运行&#xff1a; sudo apt update sudo apt install nfs-kernel-server创建共享目录 创建一个目录用于共享&#xff0c;例如/shared&#xff1a; sudo mkdir /shared sud…...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

反向工程与模型迁移:打造未来商品详情API的可持续创新体系

在电商行业蓬勃发展的当下&#xff0c;商品详情API作为连接电商平台与开发者、商家及用户的关键纽带&#xff0c;其重要性日益凸显。传统商品详情API主要聚焦于商品基本信息&#xff08;如名称、价格、库存等&#xff09;的获取与展示&#xff0c;已难以满足市场对个性化、智能…...

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする 1、前言(1)情况说明(2)工程师的信仰2、知识点(1) にする1,接续:名词+にする2,接续:疑问词+にする3,(A)は(B)にする。(2)復習:(1)复习句子(2)ために & ように(3)そう(4)にする3、…...

2025年能源电力系统与流体力学国际会议 (EPSFD 2025)

2025年能源电力系统与流体力学国际会议&#xff08;EPSFD 2025&#xff09;将于本年度在美丽的杭州盛大召开。作为全球能源、电力系统以及流体力学领域的顶级盛会&#xff0c;EPSFD 2025旨在为来自世界各地的科学家、工程师和研究人员提供一个展示最新研究成果、分享实践经验及…...

【Java学习笔记】Arrays类

Arrays 类 1. 导入包&#xff1a;import java.util.Arrays 2. 常用方法一览表 方法描述Arrays.toString()返回数组的字符串形式Arrays.sort()排序&#xff08;自然排序和定制排序&#xff09;Arrays.binarySearch()通过二分搜索法进行查找&#xff08;前提&#xff1a;数组是…...

汽车生产虚拟实训中的技能提升与生产优化​

在制造业蓬勃发展的大背景下&#xff0c;虚拟教学实训宛如一颗璀璨的新星&#xff0c;正发挥着不可或缺且日益凸显的关键作用&#xff0c;源源不断地为企业的稳健前行与创新发展注入磅礴强大的动力。就以汽车制造企业这一极具代表性的行业主体为例&#xff0c;汽车生产线上各类…...

[10-3]软件I2C读写MPU6050 江协科技学习笔记(16个知识点)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...