PIC24F EDS array causing address trap

Hi I am using PIC24fj128gc006. I am running out of data memory, so I am trying to allocate some of my buffers using EDS space. Here is my expression:
#define BUF_BASE    0x010000L
__eds__ float envelopStaticBuff[envelop_size] __attribute__ ((address(BUF_BASE), space(eds))) ;

      

I am passing it to this method as an argument eds float * staticBuffer "

bool ProcessDataToEnvelop_StaticMem(int16_t *data, int dataLength, __eds__ float *staticBuffer, int staticBufferLength, int *staticBufferCounter)
{
    uint16_t numShifts = (dataLength - _energyWindow) / _energyWindowShift;
    uint32_t newEnergySegment;

    //get first energy point
    newEnergySegment = calculate_energy_absolute(data, _energyWindowShift, _energyWindow - 1);
    staticBuffer[(*staticBufferCounter)++] = (float)(newEnergySegment + _prevEnergyShiftSegment) / (dataLength * 2);
    _prevEnergyShiftSegment = newEnergySegment;

    //return true if full
    if ((*staticBufferCounter) >= staticBufferLength) return true;

    //get energy points of remaining shifts
    for (int i=0; i<numShifts; i++) {
        newEnergySegment = calculate_energy_absolute(data,
                                               _energyWindow + i * _energyWindowShift,
                                               _energyWindow + (i + 1) * _energyWindowShift - 1);
        staticBuffer[(*staticBufferCounter)++] = (float)(_prevEnergyShiftSegment + newEnergySegment) / (dataLength * 2);
        _prevEnergyShiftSegment = newEnergySegment;

        //return true if full
        if ((*staticBufferCounter) >= staticBufferLength) return true;
    }

    //return false if not full yet
    return false;
}

      

But even before the program reaches the main one (I set a breakpoint right after main, it never gets there), I get an address trap. I am using getErrLoc()

interrupt address traps.

void __attribute__((interrupt, no_auto_psv)) _AddressError(void)
{
        errLoc=getErrLoc();
        INTCON1bits.ADDRERR = 0; //Clear the trap flag
// while (1);
}

      

and in debug mode, the returned errLoc is 0x0256, which is not even the beginning of my program memory, can I say it is SFR?

In the map file:

0x0256 U3RXREG = 0x256
0x0256 _U3RXREG = 0x256

      

Why is using EDS causing an address error in my SFR?

Here is my map:

Program Memory [Origin = 0x200, Length = 0x155f6]

section address length (PC units) length (bytes) (dec)
------- ------- ----------------- --------------------
.text 0x200 0x2696 0x39e1 (14817)
.const 0x2896 0x1f4 0x2ee (750)
.text 0x2a8a 0x42a4 0x63f6 (25590)
.dinit 0x6d2e 0x2ba 0x417 (1047)
.text 0x6fe8 0x19a 0x267 (615)
.init.delay32 0x7182 0x1c 0x2a (42)

                     Total program memory used (bytes): 0xa76d (42861) 32%


Data Memory [Origin = 0x800, Length = 0x2000]

section address alignment gaps total length (dec)
------- ------- -------------- -------------------
.nbss 0x800 0 0xcec (3308)
.nbss 0x14ec 0 0xac (172)
.ndata 0x1598 0 0x20 (32)
.nbss 0x15b8 0 0x22 (34)
.data._iob 0x15da 0 0x26 (38)
_0x19b0f185435011c 0x1600 0 0x30 (48)
.data._powers_ 0x1630 0 0x160 (352)
.data.dpowers 0x1790 0 0x140 (320)
.bss 0x18d0 0 0x8a (138)
.data 0x195a 0 0x54 (84)
.bss 0x19ae 0 0x16 (22)
.data.__C30_UART 0x19c4 0 0x2 (2)
.bss 0x19c6 0 0x2 (2)
.heap 0x19c8 0 0xa00 (2560)

                        Total data memory used (bytes): 0x1bc8 (7112) 86%


Dynamic Memory Usage

region address maximum length (dec)
------ ------- ---------------------
heap 0x19c8 0xa00 (2560)
stack 0x23c8 0x438 (1080)

                        Maximum dynamic memory (bytes): 0xe38 (3640)

      

Here is the address of the array in EDS space

0x8000 _PMCMD
0x8001 _PMALIGN
0x8002 _PMDATA
0x10000 _envelopStaticBuff <--this one

      

Please explain why this is happening. Any help would be greatly appreciated. Thank!

i created a new project using a simulator to isolate the problem

/******************************************************************************/
/* Global Variable Declaration                                                */
/******************************************************************************/
#define BUF_BASE    0x008000L   //PIC24F uses 24bit address
__eds__ float array[100] __attribute__((section("internal_array"), address(BUF_BASE), eds));

/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/

int16_t main(void)
{

    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize IO ports and peripherals */
    InitApp();

    /* TODO <INSERT USER APPLICATION CODE HERE> */
    int i;
    for(i=0;i<100;i++){
        array[i] = (float)i/100;
    }

    while(1)
    {

    }
}

      

The same happens, an address trap happens with errLoc = 0x0258 and this happens before main enters

I am very confused, can someone please clarify this for me? according to the device sheet I am using http://ww1.microchip.com/downloads/en/DeviceDoc/30009312b.pdf my chip has 8k Data ram but on page 47, 8k data byte from 08:00 up to 27FEh. According to this page, I still have EDS memory from 8000 hours to FFFFh, what can I use for the buffers correctly? So I'm confused, did I close up to 8k data bar? or can I use Ram from 8000-FFFFh (EDS)?

If I don't set the address for eds and just let the compiler solve for me,

eds int array [2000] attribute ((space (eds)));

he puts it in

0x1860 _array

is it not even in eds space which is from 8000h to FFFFh, am I getting some serious misunderstanding here?

+3


source to share





All Articles