- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个很奇怪的问题。在我看来,这是一个已知问题,但我找不到任何实际的解决方案,也找不到任何可靠的解释。
这是我的设置:
主机: Win7 电脑,内存充足。
目标:STM32F303RE Cortex M4 @ 64 MHz,在带有集成 ST-LINK 2.1 的 Nucleo32 板上
工具链:uVision V5.16
预处理器符号:USE_STDPERIPH_DRIVER,STM32F303xE,__CPLUSPLUS__FPU_PRESENT,__FPU_USED
杂项控制:--C99 --cpp
一切都很好。关闭所有优化。
问题出在运行时。在一些 C++ 对象实例化之后,处理器最终进入硬故障处理程序。具体在哪里?我通过拆分我的代码片段来标记这一点。现在,我对 C++ 细节和内部工作原理有点陌生,但听起来我和这个家伙有同样的问题:Segmentation fault caused/avoided by changing source file order in Makefile
而且,解释不清楚的解决方案。也许这不是错误的 C++ 实例化。虽然没有找到解决方案。这是我的程序的要点,它演示了这个问题:代码的第一部分“看起来”运行良好,直到我分离出部分块以供您注意。
#include "main.h" #include "stm32f30x.h" #include "stdint.h" #include "stdio.h" #include "string.h" #include "math.h" #include "usart.h" #include "can.h" #include "utils.h" #include "led.h" #include "i2c.h" #include "sabertooth.h" #include "FuzzyRule.h" #include "FuzzyComposition.h" #include "Fuzzy.h" #include "FuzzyRuleConsequent.h" #include "FuzzyOutput.h" #include "FuzzyInput.h" #include "FuzzyIO.h" #include "FuzzySet.h" #include "FuzzyRuleAntecedent.h" Fuzzy* fuzzy = new Fuzzy(); int main(void) { /************************************* * Input 1 ************************************/ // Two "crossing ramp" sets for rowWidth i.e. "tolerance" of the row FuzzyInput* rowWidth = new FuzzyInput(1); FuzzySet* lowTolerance = new FuzzySet(0.0f, 0.0f, 0.0f, 120.0f); rowWidth->addFuzzySet(lowTolerance); FuzzySet* highTolerance = new FuzzySet(0.0f, 120.0f, 120.0f, 120.0f); rowWidth->addFuzzySet(highTolerance); fuzzy->addFuzzyInput(rowWidth); USART1_puts("row width added as fuzzy input.."); /************************************* * Input 2 ************************************/ // Five Sets for "difference between R and L distances" FuzzyInput* distDiff = new FuzzyInput(2); FuzzySet* tooFarRight = new FuzzySet(-60.0f, -60.0f, -54.0f, -30.0f); distDiff->addFuzzySet(tooFarRight); FuzzySet* right = new FuzzySet(-54.0f, -30.0f, -30.0f, 0.0f); distDiff->addFuzzySet(right); FuzzySet* centered = new FuzzySet(-30.0f, 0.0f, 0.0f, 30.0f); distDiff->addFuzzySet(centered); FuzzySet* left = new FuzzySet(0.0f, 30.0f, 30.0f, 54.0f); distDiff->addFuzzySet(left); FuzzySet* tooFarLeft = new FuzzySet(30.0f, 54.0f, 60.0f, 60.0f); distDiff->addFuzzySet(tooFarLeft); fuzzy->addFuzzyInput(distDiff); USART1_puts("centering dist added as fuzzy input..."); /************************************* * Output 1 ************************************/ FuzzyOutput* motorSpeedDiff = new FuzzyOutput(1); // Seven sets for steering modes to take (close ones narrow far ones wider) FuzzySet* hardRight = new FuzzySet(-30.0f, -30.0f, -30.0f, -15.0f); motorSpeedDiff->addFuzzySet(hardRight); USART1_puts("\thardRight"); FuzzySet* lightRight = new FuzzySet(-15.0f, -5.0f, -5.0f, 0.0f); motorSpeedDiff->addFuzzySet(lightRight); USART1_puts("\tlightRight");
This is the last serial message I see in the terminal "lightRight"Hard fault occurs in next call to new FuzzySet()below this line.
FuzzySet* nomRight = new FuzzySet(-30.0f, -15.0f, -15.0f, -5.0f); motorSpeedDiff->addFuzzySet(nomRight); USART1_puts("\tnomRight"); FuzzySet* lightLeft = new FuzzySet(0.0f, 5.0f, 5.0f, 15.0f); motorSpeedDiff->addFuzzySet(lightLeft); USART1_puts("\tlightLeft"); FuzzySet* goStraight = new FuzzySet(-5.0f, 0.0f, 0.0f, 5.0f); motorSpeedDiff->addFuzzySet(goStraight); USART1_puts("\tgoStraight"); FuzzySet* nomLeft = new FuzzySet(5.0f, 15.0f, 15.0f, 30.0f); motorSpeedDiff->addFuzzySet(nomLeft); USART1_puts("\tnomLeft"); FuzzySet* hardLeft = new FuzzySet(15.0f, 30.0f, 30.0f, 30.0f); motorSpeedDiff->addFuzzySet(hardLeft); USART1_puts("\thardLeft"); fuzzy->addFuzzyOutput(motorSpeedDiff); USART1_puts("motor steering added as fuzzy output"); lotsMoreSetupCode(); while(1) { USART1_puts("Done!"); stop(1); // Blink LED forever } }
So clearly, I am just making a bunch of these fuzzy sets, which are each a collection of 4 floats, but somewhere a le-wild pointer flies?
Here is the constructor found in FuzzySet.cpp: (Part of a fuzzy logic library I did not write) This SAME program runs well on an Arduino, but not this processor. Compiler difference?
<p></p>
<pre><code>FuzzySet::FuzzySet(){
}
FuzzySet::FuzzySet(float a, float b, float c, float d){
this->a = a;
this->b = b;
this->c = c;
this->d = d;
this->pertinence = 0.0;
}
</code></pre>
<p></p>
这听起来像是与在其他上下文中被其他静态声明的函数访问的静态变量有关。
但我没有声明为静态的。
堆栈交换链接中有人说这可能是链接器错误。你同意?如何修复?
对实际发生的事情有什么想法吗?
我已经设置了一个很好的硬故障处理程序来打印寄存器信息,但显然错误甚至发生在 main() 之前。所以当事情变得困惑时去汇编代码似乎没有用。
如何修复这个?感谢您的 C++ 专业知识!
最佳答案
尝试根据您使用的微 Controller 从 startup_stm32fxxx.s 文件更改代码的堆和堆栈大小
这是例子
;******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
;* File Name : startup_stm32f407xx.s
;* Author : MCD Application Team
;* Version : V2.4.3
;* Date : 22-January-2016
;* Description : STM32F407xx devices vector table for MDK-ARM toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM4 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
;
;* Redistribution and use in source and binary forms, with or without modification,
;* are permitted provided that the following conditions are met:
;* 1. Redistributions of source code must retain the above copyright notice,
;* this list of conditions and the following disclaimer.
;* 2. Redistributions in binary form must reproduce the above copyright notice,
;* this list of conditions and the following disclaimer in the documentation
;* and/or other materials provided with the distribution.
;* 3. Neither the name of STMicroelectronics nor the names of its contributors
;* may be used to endorse or promote products derived from this software
;* without specific prior written permission.
;*
;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
;* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
;*******************************************************************************
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x200 ; <your stack size>
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x400 ; <your heap size>
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
栈的值由那一行设置
Stack_Size EQU 0x200 ; <your stack size>
和堆
Heap_Size EQU 0x400 ; <your heap size>
在 Keil uVision 中,您在左下角还有 2 个选项卡,您可以在其中切换“文本编辑器”和“配置向导”以更改代码堆和堆栈大小。
关于c++ - C++ 初始化器上的 Cortex M4 硬故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36581923/
我之前让 dll 注入(inject)器变得简单,但我有 Windows 7,我用 C# 和 C++ 做了它,它工作得很好!但是现在当我在 Windows 8 中尝试相同的代码时,它似乎没有以正确的方
我正在尝试制作一个名为 core-splitter 的元素,该元素在 1.0 中已弃用,因为它在我们的项目中起着关键作用。 如果您不知道 core-splitter 的作用,我可以提供一个简短的描述。
我有几个不同的蜘蛛,想一次运行所有它们。基于 this和 this ,我可以在同一个进程中运行多个蜘蛛。但是,我不知道如何设计一个信号系统来在所有蜘蛛都完成后停止 react 器。 我试过了: cra
有没有办法在达到特定条件时停止扭曲 react 器。例如,如果一个变量被设置为某个值,那么 react 器应该停止吗? 最佳答案 理想情况下,您不会将变量设置为一个值并停止 react 器,而是调用
https://code.angularjs.org/1.0.0rc9/angular-1.0.0rc9.js 上面的链接定义了外部js文件,我不知道Angular-1.0.0rc9.js的注入(in
我正在尝试运行一个函数并将服务注入(inject)其中。我认为这可以使用 $injector 轻松完成.所以我尝试了以下(简化示例): angular.injector().invoke( [ "$q
在 google Guice 中,我可以使用函数 createInjector 创建基于多个模块的注入(inject)器。 因为我使用 GWT.create 在 GoogleGin 中实例化注入(in
我在 ASP.NET Core 1.1 解决方案中使用配置绑定(bind)。基本上,我在“ConfigureServices Startup”部分中有一些用于绑定(bind)的简单代码,如下所示: s
我在 Spring MVC 中设置 initBinder 时遇到一些问题。我有一个 ModelAttribute,它有一个有时会显示的字段。 public class Model { privat
我正在尝试通过jquery post发布knockoutjs View 模型 var $form = $('#barcodeTemplate form'); var data = ko.toJS(vm
如何为包含多态对象集合的复杂模型编写自定义模型绑定(bind)程序? 我有下一个模型结构: public class CustomAttributeValueViewModel { publi
您好,我正在尝试实现我在 this article 中找到的扩展方法对于简单的注入(inject)器,因为它不支持开箱即用的特定构造函数的注册。 根据这篇文章,我需要用一个假的委托(delegate)
你好,我想自动注册我的依赖项。 我现在拥有的是: public interface IRepository where T : class public interface IFolderReposi
我正在使用 Jasmine 测试一些 Angular.js 代码。为此,我需要一个 Angular 注入(inject)器: var injector = angular.injector(['ng'
我正在使用 Matlab 代码生成器。不可能包含代码风格指南。这就是为什么我正在寻找一个工具来“ reshape ”、重命名和重新格式化生成的代码,根据我的: 功能横幅约定 文件横幅约定 命名约定 等
这个问题在这里已经有了答案: Where and why do I have to put the "template" and "typename" keywords? (8 个答案) 关闭 8
我开发了一种工具,可以更改某些程序的外观。为此,我需要在某些进程中注入(inject)一个 dll。 现在我基本上使用这个 approach .问题通常是人们无法注入(inject) dll,因为他们
我想使用 swing、spring 和 hibernate 编写一个 java 应用程序。 我想使用数据绑定(bind)器用 bean 的值填充 gui,并且我还希望它反射(reflect) gui
我有这段代码,当两个蜘蛛完成后,程序仍在运行。 #!C:\Python27\python.exe from twisted.internet import reactor from scrapy.cr
要点是 Spring Batch (v2) 测试框架具有带有 @Autowired 注释的 JobLauncherTestUtils.setJob。我们的测试套件有多个 Job 类提供者。因为这个类不
我是一名优秀的程序员,十分优秀!