LPC1769 Memory Assignment

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1769 Memory Assignment

317 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by andrewaggie on Wed May 11 14:34:24 MST 2016
Hello!

I am working with an LPC1769 development board and working with the free version of LPCXpresso. I am writing code that is being used for data collection and I am getting a hard fault error when I try to assign the needed number of variables for this project. The code is well within the size allowable for the compiler (120 kb of the 256 kb allowable), but if I try to initialize the number of variables I need, I get the hard fault error, which I already know is an error related to trying to assign memory to an address that is not addressable. Is this an error that can be solved while still using the free version of Xpresso or will upgrading allow me to assign to more memory?
0 Kudos
4 Replies

237 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos

237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu May 12 09:14:48 MST 2016
Could be useful to post a complete debuggable project...
0 Kudos

237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by andrewaggie on Thu May 12 08:57:56 MST 2016
A lot of my code is working, so I'll post the relevant parts in the text here:

Initialization:
#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;

Addressing Variables:
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;
}
When I remove the section for year address at the end, the code works fine and the hard fault does not show up. If I reduce the amount of year addresses to between 1-50, it works, but when it goes above 100 year address, I get the hard fault shown below.

Hard Fault error message from debug:
HardFault_Handler() at 0xf8
<signal handler called>() 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

If there is anything else I can post, just ask.

0 Kudos

237 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vtw.433e on Wed May 11 14:43:41 MST 2016
From your description this has nothing to do with free vs paid. You would get linker errors if you exceeded the size limit.

Post your project so we can see what you are doing and suggest what you're doing wrong
0 Kudos