当前位置: 首页 > 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模型,专注于编码器…...

手撕单例模式

在Go语言中实现单例模式&#xff0c;通常需要确保一个类只有一个实例&#xff0c;并且提供一个全局访问点。Go语言本身没有类的概念&#xff0c;但可以通过结构体和函数来模拟这种行为。下面是一个简单的手撕单例模式的实现示例&#xff1a; 懒汉式&#xff08;延迟初始化&…...

UE4 材质学习笔记06(布料着色器/体积冰着色器)

一.布料着色器 要编写一个着色器首先是看一些参考图片&#xff0c;我们需要找出一些布料特有的特征&#xff0c;下面是一个棉织物&#xff0c;可以看到布料边缘的纤维可以捕捉光线使得边缘看起来更亮 下面是缎子和丝绸的图片&#xff0c;与棉织物有几乎相反的效果&#xff0c;…...

人工智能学习框架

人工智能学习框架是指用于开发和训练机器学习和深度学习模型的软件库和工具集。这些框架帮助开发者更高效地构建、训练和部署模型&#xff0c;加速人工智能应用的开发进程。 常见的人工智能学习框架 TensorFlow 由Google开发&#xff0c;是一个开源的深度学习框架&#xff0c;…...

GEE 教程:Landsat TOA数据计算地表温度(LST)

目录 简介 函数 expression(expression, map) Arguments: Returns: Image reduceRegion(reducer, geometry, scale, crs, crsTransform, bestEffort, maxPixels, tileScale) Arguments: Returns: Dictionary 代码 结果 简介 地表温度(Land Surface Temperature,LS…...

Web编程---配置Tomcat

文章目录 一、目的二、原理三、过程1. 解压“apache-tomcat-10.0.27-windows-x64.zip”文件到指定文件夹。2. 配置环境变量3.修改编码方式&#xff0c;防止 Tomcat 控制台出现乱码。4.启动 Tmocat5.打开浏览器&#xff0c;地址栏输入 http://localhost:8080 &#xff0c;如果看…...

物联网5G模块WIFI模块调式记录(Pico)

调试环境 MCU&#xff1a;Pico1&#xff08;无wifi版&#xff09;5G模块&#xff1a;EC800K&#xff08;iot专用4g卡&#xff09;WIFI模块&#xff1a;ESP01s&#xff08;Esp8266芯片&#xff09;、DX-WF24开发环境&#xff1a;MacBook Pro Sonoma 14.5开发工具&#xff1a;Th…...

中国平安蝉联2024“金融业先锋30”第一名 获金融业ESG最高五星评级

2024年10月15日&#xff0c;中央广播电视总台正式对外发布《金融业ESG行动报告&#xff08;2024&#xff09;》&#xff08;以下简称"《报告》"&#xff09;&#xff0c;并公布了"中国ESG上市公司金融业先锋30"榜单。中国平安凭借在绿色金融、普惠金融、养…...

[图解]题目解析:财务人员最有可能成为业务执行者的是

1 00:00:00,420 --> 00:00:04,760 接下来&#xff0c;是第3章自测题第1部分的第8题 2 00:00:05,090 --> 00:00:08,120 单选&#xff0c;针对以下研究对象 3 00:00:08,900 --> 00:00:11,530 财务人员最有可能成为业务执行者的是 4 00:00:12,800 --> 00:00:15,280…...

零基础学大模型——大模型技术学习过程梳理

“学习是一个从围观到宏观&#xff0c;从宏观到微观的一个过程” 学习大模型技术也有几个月的时间了&#xff0c;之前的学习一直是东一榔头&#xff0c;西一棒槌&#xff0c;这学一点那学一点&#xff0c;虽然弄的乱七八糟&#xff0c;但对大模型技术也算有了一个初步的认识。…...

匹配全国地址的正则表达式工具类

正则表达式&#xff0c;匹配全国五级地址工具类&#xff0c;可以直接放在项目中使用~ 1级&#xff1a;国 &#xff08;可忽略不填&#xff09; 2级&#xff1a;**省、**自治区、**直辖市、**特别行政区、&#xff08;四个直辖市可忽略不填&#xff09; 3级&#xff1a;**市、**…...