4

Hi I am using the PIC24fj128gc006. I am running out of data memory so I am trying to allocate some of my buffers using the EDS space. Here is my declaration:

#define BUF_BASE    0x010000L
__eds__ float envelopStaticBuff[envelop_size] __attribute__ ((address(BUF_BASE), space(eds))) ;

I pass it to this method as the 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 main (I set a break point just after main, it never gets there), I get an address trap. I am using getErrLoc() in the address trap interrupt.

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

and in debug mode, the errLoc returned is 0x0256 which is not even the start of my program memory, am I right to say that it is the SFR?

In my map file:

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

Why is using EDS causing 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 appreciated. Thanks!

i created a new project using the simulator just 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 thing happens, an address trap occurs with errLoc = 0x0258, and it occurs before main enters

I am quite confused could someone clarify it for me? according to the device sheet I'm using, http://ww1.microchip.com/downloads/en/DeviceDoc/30009312b.pdf, my chip has 8k Data ram, but on page 47, the 8k data ram is from 0800h to 27FEh. According to that page, i still have EDS memory from 8000h to FFFFh, that i can use for buffers right? So i am confused, am i capped to 8k data ram? or can i use the Ram from 8000-FFFFh (EDS)?

if i don't set the address for the eds and just allow the compiler to decide for me,

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

it places it at

0x1860 _array

this isn't even in the eds space which is from 8000h to FFFFh, am i getting some serious misunderstanding here?

Benjamin Hon
  • 143
  • 1
  • 11
  • 1
    According to [PIC24F Reference manual](http://ww1.microchip.com/downloads/en/DeviceDoc/39733a.pdf), the EDS is only 32K bytes, but the array you allocated is located above 0xFFFF which cannot be addressed by the chip. – SSC Oct 08 '14 at 10:16
  • I am using the second block of the eds, 10000 is the effective address after combining with dswpg am I right. – Benjamin Hon Oct 08 '14 at 10:53
  • ahh i think my MCU's eds space is only for EPMP, meaning external memory, there is no internal memory after 7FFFh am i right? Does that mean that my MCU also does not implement he PSV, since its after 7FFFh? – Benjamin Hon Oct 08 '14 at 13:42
  • I am sorry. I think my previous comment does not take DSxPAG into account. – SSC Oct 08 '14 at 14:27
  • The array is statically allocated so must be zero initialised on start-up *before* main is called. So if the space is not valid, it is not at all surprising that the exception occurs before `main()`. – Clifford Oct 08 '14 at 17:31
  • I think i only have 8k of ram space right? according to the manual http://ww1.microchip.com/downloads/en/DeviceDoc/30009312b.pdf , the EDS is only for EPMP (external memory) and is not internally implemented, am i correct? – Benjamin Hon Oct 09 '14 at 02:03
  • Also, why is it necessary to zero initialise the array on startup before main? i have other arrays declared before main without initialisation without a problem. – Benjamin Hon Oct 09 '14 at 02:10
  • EDS is address space, not memory. Your part only seems to have 8kb total memory. Then you can EDS only to map read only flash arrays. – Marco van de Voort Jan 31 '23 at 09:34

0 Answers0