|
|
View previous topic :: View next topic |
Author |
Message |
Vinod.chinthoti
Joined: 28 Jun 2024 Posts: 10
|
TRAP Memory Error issue in dsPIC33EP256GP504 |
Posted: Thu Aug 01, 2024 10:52 pm |
|
|
Hi all,
I used the below code to check where the Memory Trap occurred in the code
compiler version:- CCS V5.117 & MPLAB IDE 8.92
#INT_ADDRERR
void ADDRERR_isr(void)
{
char u8PrintBuffer[128];
unsigned long trapaddr;
#asm
mov w15, w0
sub #38, w0
mov [w0++], w1
mov w1, trapaddr
mov [w0], w1
and #0x7f, w1
mov w1, trapaddr+2
#endasm
sprintf(u8PrintBuffer, "\r\n\r\n ----- TRAP - ADDRERR Error Occured = 0x%08lX -----\r\n",trapaddr);
Service_WriteDebugString(u8PrintBuffer, strlen(u8PrintBuffer));
}
The output was shown like below
" ----- TRAP - ADDRERR Error Occured = 0x000192D4 -----"
The then I add the FAST type decleration like below
#INT_ADDRERR FAST
void ADDRERR_isr(void)
{
char u8PrintBuffer[128];
unsigned long trapaddr;
#asm
mov w15, w0
sub #38, w0
mov [w0++], w1
mov w1, trapaddr
mov [w0], w1
and #0x7f, w1
mov w1, trapaddr+2
#endasm
sprintf(u8PrintBuffer, "\r\n\r\n ----- TRAP - ADDRERR Error Occured = 0x%08lX -----\r\n",trapaddr);
Service_WriteDebugString(u8PrintBuffer, strlen(u8PrintBuffer));
}
I got the output like below
" ----- TRAP - ADDRERR Error Occured = 0x00000000 -----"
In the above 2 output's which one I need to follow _________________ Thanks,
Vinod |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Aug 02, 2024 1:06 am |
|
|
The first one.
If you use FAST, you only need to subtract 2.
Remember it is the instruction in front of this address where the problem
has occurred. |
|
|
Vinod.chinthoti
Joined: 28 Jun 2024 Posts: 10
|
|
Posted: Fri Aug 02, 2024 3:04 am |
|
|
Ttelmah wrote: | The first one.
If you use FAST, you only need to subtract 2.
Remember it is the instruction in front of this address where the problem
has occurred. |
Okay, Thank you.
RegMeasuredValue1 is a structure.
in that MeasuredValuePointer is unsigned int structure member. The problem I am facing is highlighted below.
The Memory Error occurring during incrementing of MeasuredValuePointer. How this could be leads to Memory Trap.
// Save measured value
RegMeasuredValue1.Value[RegMeasuredValue1.MeasuredValuePointer]=AnalogValue;
// Set MeasuredValuePointer to next memory location
RegMeasuredValue1.MeasuredValuePointer++;
// Check measured value range
if (RegMeasuredValue1.MeasuredValuePointer>=RegMeasuredValue1.NumberOfMeasuredValues)
RegMeasuredValue1.MeasuredValuePointer=0;
InputValueCalculate(&RegMeasuredValue1); // convert to unit _________________ Thanks,
Vinod |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Aug 02, 2024 8:08 am |
|
|
Totally to be expected.....
Key point is how large are the structure elements, and how is the pointer
declared?.
Key point is this. If (for example), I declare an int16, and then declare
a _byte_ pointer and point this at the int16. If I increment the pointer,
and try to read an int16 from this, I will get an address error. int16 elements
can only be read from even addresses. If you have a pointer declared as
a pointer to an int16, and increment it, it will increment by two, so it points
to the next int16. However copy that pointer to a byte pointer, and do the
same and you will get an address error.
You can specify a structure so that all it's elements are aligned to int16
boundaries, and use an int16 pointer to this, or you have to retrieve the
elements as bytes and put these back together into an int16 (or int32, float
etc.).
Do a web search on structure alignment and you will find a lot about this.
Historically the old PIC's were 8bit chips, so had no alignment issues.
However with the PIC23/30/32 etc., word alignment must be used when
working with pointers. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|