LPC1769内存分配硬错误

时间:2016-05-12 16:19:56

标签: c++ arm lpc

我正在使用LPC1769开发板并使用免费版LPCXpresso。我正在编写用于数据收集的代码,当我尝试为此项目分配所需数量的变量时,我遇到了一个硬错误错误。代码完全在编译器允许的范围内(允许的256 kb的120 kb),但是如果我尝试初始化我需要的变量数量,我会得到硬故障错误,我已经知道这是一个与之相关的错误尝试将内存分配给不可寻址的地址。

我的很多代码与此错误无关,因此下面的文字是相关代码。 的初始化:

#include "glob.h"
#include "mbed.h"
#include "Ticker.h"
#include "rtc_time.h"
#include "time.h"
#include <cmath>
#include <string>
static void flip(void);
extern void po(CANMessage);             // handle 0x79X and 0x79X
extern void dime(CANMessage);           // handle 0x1FXXXXXX messages
extern void stage(CANMessage);          // handle 0x1DXXXXXX messages
extern void authen(CANMessage);         // handle 0x1BXXXXXX messages
extern void ParseInhibit(CANMessage);   // handle 0x0C14XXXX messages
extern void ParseLED(CANMessage);       // handle sounder 0x0C14XXXX messages
extern int last_data[3];                // used in gotoAsleep and gotoAwake
extern void service_switch(void);
extern void init(void);
extern void abtimeoutfunc(void);
static InterruptIn sdip(P0_4);
DigitalIn buzz(P1_15);                  // hardware pin for buzzer
extern void downloadmem(void);          // loads POs
extern void LEDset(int);                // sets the LEDs
extern int kickcan(long, char, char, char, char, char, char, char, char, int);

//CanMessage Variables
int joystickx, joysticky;
int axishandler, axistemp, axis;

//Battery Monitor variables
int datesetter;
int second, minute, hour, month, year, dayofweek, day, datehandler, hour2, day2, minute2, second2;
double ADCvoltage; //Converts the float percentage back into the value being read into the ADC pin
double batteryvoltage, chargelow;

//Cycle log variables
int chargeid;
int cyclesecond[5], cyclemonth[5], cycleminute[5], cyclehour[5], cycleday[5], cycledayofweek[5], cycleyear[5], cycle;

//Max and Min variables
double voltmaxlife, voltmaxminute, batterynibble; //Max voltage variable
double voltminlife = 30, voltminmonth = 30, voltminday = 30, voltminminute = 30; //Min voltage variable
int timedmaxsecond, timedmaxminute, timedmaxhour, timedmaxmonth, timedmaxday, timedmaxdayofweek, timedmaxyear, first = 1;
int timedminsecond, timedminminute, timedminhour, timedminmonth, timedminday, timedmindayofweek, timedminyear;
int lifemaxsecond, lifemaxminute, lifemaxhour, lifemaxmonth, lifemaxyear, lifemaxdayofweek, lifemaxday; //Time variables used to store the time of the most recent max charge across the chair's lifetime
int lifeminsecond, lifeminminute, lifeminhour, lifeminmonth, lifeminyear, lifemindayofweek, lifeminday; //Time variables used to store the time of the most recent min charge
int dailymaxsecond, dailymaxminute, dailymaxhour, dailymaxmonth, dailymaxday, dailymaxdayofweek, dailymaxyear;
int dailyminsecond, dailyminminute, dailyminhour, dailyminmonth, dailyminday, dailymindayofweek, dailyminyear;
double voltagereadweek1[12], voltagereadweek2[12], voltagereadweek3[12], voltagereadweek4[12], voltagereadweek5[12], voltagereadweek6[12], voltagereadweek7[12], voltagereadweek8[12], voltagereadweek9[12], voltagereadweek10[12], voltagereadweek11[12], voltagereadweek12[12], voltagereadweek13[12], voltagereadweek14[12];
double voltagereadday[5], voltagereadmonth[5];
double dailymaxvolt, monthlymaxvolt, dailyminvolt = 30, monthlyminvolt = 30;
int monthlymaxsecond, monthlymaxminute, monthlymaxhour, monthlymaxmonth, monthlymaxday, monthlymaxdayofweek, monthlymaxyear;
int monthlyminsecond, monthlyminminute, monthlyminhour, monthlyminmonth, monthlyminday, monthlymindayofweek, monthlyminyear;
bool hourset = true;

//Inhibit variables
int inhibit4second, inhibit4minute, inhibit4hour, inhibit4month, inhibit4day, inhibit4dayofweek, inhibit4year, inhibit4band;
int inhibit5second, inhibit5minute, inhibit5hour, inhibit5month, inhibit5day, inhibit5dayofweek, inhibit5year, inhibit5band;
int inhibit2second, inhibit2minute, inhibit2hour, inhibit2month, inhibit2day, inhibit2dayofweek, inhibit2year, inhibit2band;
int inhibit3second, inhibit3minute, inhibit3hour, inhibit3month, inhibit3day, inhibit3dayofweek, inhibit3year, inhibit3band;
int inhibitdata, inhibitcan;
extern int inhibits[4];
extern int tempinhibit, tempband;

//Error variables
int errordata1[50], errordata2[50], batteryhandler;
int batteryerror1, batteryerror2, batteryerrorsecond, batteryerrorminute, batteryerrorhour, batteryerrorday, batteryerrordayofweek, batteryerrormonth, batteryerroryear;
double batteryerrorvoltage;
int errorsecond[5], errorminute[5], errorhour[5], errorday[5], errordayofweek[5], errormonth[5], erroryear[5];

//Event variables
int programchangecount, programsecond[5], programminute[5], programhour[5], programday[5], programdayofweek[5], programmonth[5], programyear[5];
int eventkind, eventlog[5], eventsecond[5], eventminute[5], eventhour[5], eventday[5], eventdayofweek[5], eventmonth[5], eventyear[5];
int profile, prosecond[5], prominute[5], prohour[5], promonth[5], proday[5], proyear[5], prodayofweek[5];
int OBP, cd, mode, previousmode, inhibitreset, previousevent, eventhappen, charging;

//Memory Variables
I2C i2c(P0_10, P0_11); //Establish the I2C protocol
int typevalue, readlength, ackholder, readwrite, secondreturn, minutereturn,     hourreturn, monthreturn, dayreturn, dayofweekreturn, yearreturn, cyclereturn;
double batteryreturn;
double doubleconvert;
char readdata;
int addressholder1, addressholder2, addresshandle;
char temp1, temp2;
char yraddress1[124], yraddress2[124], secaddress1[618], secaddress2[618], minaddress1[618], minaddress2[618], hraddress1[618], hraddress2[618], monaddress1[618], monaddress2[618], daddress1[618], daddress2[618];
char dowaddress1[309], dowaddress2[309];
/*char * writeaddress = (char *) malloc(1);
char * readaddress = (char *) malloc(1);
char * readout = (char *) malloc(1);
char * newholder = (char *) malloc(1);
char * writedata = (char *) malloc(1);
char * convertholder = (char *) malloc(5);
char * doubleconvertbuffer = (char *) malloc(5);*/


char wait_msg[8] = {0,0, 0,0, 0,0, 0,0};// Used for Queued messages
char DimeID[8] =  {1,2, 3,4, 5,6, 7,8}; // Appendex A B.1 Protocol Spec.
char auth[8]   =  {0,0, 0,0, 0,0, 0,0};
int AvailProfiles, AvailModes, CurrentPro, CurrentMo, ProMask[8];
int MyNode, repo, CxSM;                 // everybody uses these
int modulenumber = 1;
int flag;                               // assigned by LAST can.write
extern int realspeed;                   // used by set speed
enum BusState {Asleep, Awake};          // state of the bus
BusState MyState=Asleep;
Timeout timeout;                        // use to goto Sleep -- used for SCID
extern Timeout abTimer;                 // when calling gotoAsleep, detach latched actuators
extern int color5[10];  // init
extern Ticker LEDticker;

变量分配

void addressing(){
int add = 1;
secaddress1[0] = ' ';
secaddress2[0] = ' ';
minaddress1[0] = '&';
minaddress2[0] = 'P';
hraddress1[0] = '-';
hraddress2[0] = '!';
monaddress1[0] = '3';
monaddress2[0] = 'Q';
daddress1[0] = ':';
daddress2[0] = '"';
dowaddress1[0] = '@';
dowaddress2[0] = 'R';
yraddress1[0] = 'C';
yraddress2[0] = 'j';
while(add < sizeof(secaddress1))
{
    temp1 = secaddress1[add-1];
    temp2 = secaddress2[add-1];
    addressholder1 = temp1;
    addressholder2 = temp2;
    if(secaddress2[add-1] != '~'){
        secaddress1[add] = secaddress1[add-1];
        addresshandle = addressholder2 + 1;
        secaddress2[add] = addresshandle;

    }
    if(secaddress2[add-1] == '~'){
        addresshandle = addressholder1 + 1;
        secaddress1[add] = addresshandle;
        secaddress2[add] = ' ';
    }
    add++;
}
add = 1;
while(add < sizeof(minaddress1))
{
    temp1 = minaddress1[add-1];
    temp2 = minaddress2[add-1];
    addressholder1 = temp1;
    addressholder2 = temp2;
    if(minaddress2[add-1] != '~'){
        minaddress1[add] = minaddress1[add-1];
        addresshandle = addressholder2 + 1;
        minaddress2[add] = addresshandle;

    }
    if(minaddress2[add-1] == '~'){
        addresshandle = addressholder1 + 1;
        minaddress1[add] = addresshandle;
        minaddress2[add] = ' ';
    }
    add++;
}
add = 1;
while(add < sizeof(hraddress1))
{
    temp1 = hraddress1[add-1];
    temp2 = hraddress2[add-1];
    addressholder1 = temp1;
    addressholder2 = temp2;
    if(hraddress2[add-1] != '~'){
        hraddress1[add] = hraddress1[add-1];
        addresshandle = addressholder2 + 1;
        hraddress2[add] = addresshandle;

    }
    if(hraddress2[add-1] == '~'){
        addresshandle = addressholder1 + 1;
        hraddress1[add] = addresshandle;
        hraddress2[add] = ' ';
    }
    add++;
}
add = 1;
while(add < sizeof(monaddress1))
{
    temp1 = monaddress1[add-1];
    temp2 = monaddress2[add-1];
    addressholder1 = temp1;
    addressholder2 = temp2;
    if(monaddress2[add-1] != '~'){
        monaddress1[add] = monaddress1[add-1];
        addresshandle = addressholder2 + 1;
        monaddress2[add] = addresshandle;

    }
    if(monaddress2[add-1] == '~'){
        addresshandle = addressholder1 + 1;
        monaddress1[add] = addresshandle;
        monaddress2[add] = ' ';
    }
    add++;
}
add = 1;
while(add < sizeof(daddress1))
{
    temp1 = daddress1[add-1];
    temp2 = daddress2[add-1];
    addressholder1 = temp1;
    addressholder2 = temp2;
    if(daddress2[add-1] != '~'){
        daddress1[add] = daddress1[add-1];
        addresshandle = addressholder2 + 1;
        daddress2[add] = addresshandle;

    }
    if(daddress2[add-1] == '~'){
        addresshandle = addressholder1 + 1;
        daddress1[add] = addresshandle;
        daddress2[add] = ' ';
    }
    add++;
}
add = 1;
while(add < sizeof(dowaddress1))
{
    temp1 = dowaddress1[add-1];
    temp2 = dowaddress2[add-1];
    addressholder1 = temp1;
    addressholder2 = temp2;
    if(dowaddress2[add-1] != '~'){
        dowaddress1[add] = dowaddress1[add-1];
        addresshandle = addressholder2 + 1;
        dowaddress2[add] = addresshandle;

    }
    if(dowaddress2[add-1] == '~'){
        addresshandle = addressholder1 + 1;
        dowaddress1[add] = addresshandle;
        dowaddress2[add] = ' ';
    }
    add++;
}
add = 1;
while(add < sizeof(yraddress1))
{
    temp1 = yraddress1[add-1];
    temp2 = yraddress2[add-1];
    addressholder1 = temp1;
    addressholder2 = temp2;
    if(yraddress2[add-1] != '~'){
        yraddress1[add] = yraddress1[add-1];
        addresshandle = addressholder2 + 1;
        yraddress2[add] = addresshandle;

    }
    if(yraddress2[add-1] == '~'){
        addresshandle = addressholder1 + 1;
        yraddress1[add] = addresshandle;
        yraddress2[add] = ' ';
    }
    add++;
}
addressholder1 = addressholder2;
}

当我最后删除年份地址部分时,代码工作正常,并且硬故障不会显示。如果我将年份地址的数量减少到1-50之间,它可以工作,但当它超过100年地址时,我会收到如下所示的硬故障。

调试

硬故障错误消息:

HardFault_Handler() at 0xf8 
() at 0xfffffff9    
_free_r() at 0xcfb2 
__sflush_r() at 0xcb56  
setvbuf() at 0xe6b6 
mbed::Stream::Stream() at 0x9be2    
mbed::Serial::Serial() at 0x968a    
__static_initialization_and_destruction_0() at glob.h:24 0x7ee8 
_GLOBAL__sub_I_map() at stage.cpp:568 0x7fd6    
__libc_init_array() at 0xd81a   
ResetISR() at 0x16c

如果我还需要发布任何其他内容,请询问。谢谢!

0 个答案:

没有答案