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

从怀疑到真香!2026我日常办公离不开的这款在线文字转换器太好用了

刚入职那半年我踩过太多坑&#xff1a;一周三次新人培训&#xff0c;怕漏记知识点全程录音&#xff0c;下课手动整理1小时录音要熬3小时&#xff0c;知识点散得根本没法复习&#xff1b;部门周会做完记录&#xff0c;散会就要我出整理好的纪要&#xff0c;赶工赶得饭都吃不上&a…...

从Gamma函数到泊松分布:一个概率论中的含参量积分实用案例解析

Gamma函数与泊松分布&#xff1a;概率论中的数学之美 在数据科学和机器学习的实践中&#xff0c;概率分布构成了建模的基石。当我们深入探究这些分布背后的数学原理时&#xff0c;Gamma函数以其优雅的性质和广泛的应用脱颖而出。它不仅连接了离散与连续概率世界&#xff0c;更在…...

量子软件测试的挑战与优化策略

1. 量子软件测试的挑战与机遇量子计算正在从实验室走向实际应用&#xff0c;随之而来的是对可靠量子软件的需求激增。与传统软件不同&#xff0c;量子程序面临三大独特挑战&#xff1a;首先&#xff0c;量子态的叠加性和纠缠性使得测试变得异常复杂。一个n量子比特系统可以同时…...

基于声卡与电流互感器的安全交流功率测量系统设计与实践

1. 项目概述&#xff1a;用声卡安全测量交流功率我一直对各种测量技术抱有浓厚的兴趣&#xff0c;毕竟“测量即认知”这句老话在今天依然适用。对于电力消耗和产出&#xff0c;没有什么比直接测量更能说明问题了。交流功率的测量&#xff0c;核心在于同时获取电压和电流的瞬时值…...

Raspberry Pi Debug Probe:RP2040嵌入式开发的调试利器与实战指南

1. 项目概述&#xff1a;为什么你需要一个Raspberry Pi Debug Probe&#xff1f;如果你玩过树莓派Pico或者任何基于RP2040芯片的开发板&#xff0c;肯定遇到过这样的场景&#xff1a;写好的代码&#xff0c;点一下“上传”&#xff0c;然后……就没有然后了。板子上的LED没按你…...

告别DLL缺失烦恼!Visual C++运行库合集一键搞定Windows应用依赖问题

告别DLL缺失烦恼&#xff01;Visual C运行库合集一键搞定Windows应用依赖问题 【免费下载链接】vcredist AIO Repack for latest Microsoft Visual C Redistributable Runtimes 项目地址: https://gitcode.com/gh_mirrors/vc/vcredist 你是否曾经在打开某个软件或游戏时…...

java项目011-ssm 宠物医院系统

java项目011-ssm 宠物医院系统 是一款基于springspringmvcmybatis的宠物系统&#xff0c; 包含界面布局、医生信息管理、客户信息管理、宠物管理、浏览管理、 诊断管理、医生管理、用户管理 其中医生管理、用户管理只能管理员有权限进行操作。 采用spingboot方式启动 运行截图...

【Veo 2提示词SOP白皮书】:从模糊意图到像素级输出的8步标准化工作流(附NASA级测试用例库)

更多请点击&#xff1a; https://intelliparadigm.com 第一章&#xff1a;Veo 2提示词工程的本质与范式跃迁 Veo 2并非单纯升级的视频生成模型&#xff0c;而是一次提示词工程范式的根本性重构——它将传统“指令式提示”&#xff08;prompt-as-command&#xff09;转向“意图…...

NHSE终极教程:5分钟掌握动物森友会存档编辑技巧

NHSE终极教程&#xff1a;5分钟掌握动物森友会存档编辑技巧 【免费下载链接】NHSE Animal Crossing: New Horizons save editor 项目地址: https://gitcode.com/gh_mirrors/nh/NHSE 还在为《集合啦&#xff01;动物森友会》的收集烦恼吗&#xff1f;想快速打造梦想岛屿却…...

如何优化 MySQL 千万级数据分页查询的性能?

它的本质是&#xff1a;**传统 LIMIT offset, size 在大数据量下性能急剧下降&#xff0c;是因为 MySQL 必须 扫描并丢弃 前 offset 行数据。当 offset 很大时&#xff08;如 LIMIT 1000000, 10&#xff09;&#xff0c;MySQL 需要读取 1,000,010 行记录&#xff0c;执行 1,000…...