cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

hoalc_4104386
New Contributor II

Hello,

I am using Cypress PSoC 5LP CY8C5888LT*-LP097  with PSOC 4.2

Flash used: 46204 of 262144 bytes (17.6%).

SRAM used: 60465 of 65536 bytes (92.3%). Stack: 2048 bytes. Heap: 2048 bytes.

When I enable speed optimization I get the following exception during runtime

pastedImage_0.png

I tried to Increase the Heap to 4K or 6 K but it dosn't help

How to overcome this problem?

Hossam Alzomor

0 Likes
1 Solution
Len_CONSULTRON
Honored Contributor II

Hossam Alzomor,

Nothing looks obvious however check your code for the following:

  • uint8 *rxdata points to an array of at least two bytes.  If you only have a variable with one byte the line dumping the incoming SPI data into rxdata[1] will overwrite unknown data. This unknown data could be stack or other RAM with pointer information.
  • You have a while statement that loops until at least one byte is available in the SPIM_1 Rx buffer.  You  might want to change the statement to: while(SPIM_1_GetRxBufferSize() <2);   Since the next three statements are assuming that at least two bytes are being read from the SPI, you might want to make sure at least two bytes have been received.  Your code only assumes one byte is available.

Hope this helps.

Len

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
5 Replies
Len_CONSULTRON
Honored Contributor II

Hossam,

Just to make sure.  You changed the Heap allocation to 4K or 6K using:

   pastedImage_0.png

You get a runtime error not a compile/linker error.  Are you using FreeRTOS with dynamic memory allocations?

I way to help debug where in the code there might be an issue is when you break in the IntDefaultHandler ISR look at the Call stack.  This is the debugger's best guess where you have been in the code because these are the PC values stored on the stack during a call or interrupt.

pastedImage_1.png

Sometimes I remember getting into this IntDefaultHandler when I was using FreeRTOS and didn't allocate enough stack for the task.  I used the Call Stack recommendation above to find the offending task and allocate more stack during the task initialization call.

Another suggestion is to reduce your memory requirements used by your application.   I noticed you are using 92.3% of available RAM.  Wow!  Temporarily commenting out a high RAM use function might prevent the IntDefaultHandler issue,

Let me know if any of the above suggestions work out.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
hoalc_4104386
New Contributor II

Thanks len,

I am modifying the stack in the right place

pastedImage_0.png

I am not using freertos, and not using memalloc

Dose optimized code requires such much heap/stack size?

Best Regards

Hossam Alzomor

0 Likes
Len_CONSULTRON
Honored Contributor II

Hossam,

Optimized code will generally lower FLASH and RAM requirements unless optimized for speed.

Try my debugging suggestion with the Call Stack.

If that doesn't work, you may have to share your project.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
hoalc_4104386
New Contributor II

Len,

I am optimizing for speed.

Here's a snapshot from the stack and registers just after the exception

optimized after problem.PNG

and here's just before the exception

optimized before problem.PNG

and here's the line that causes the problem

line cause problem.PNG

Do you have any recommendation?

Hossam Alzomor

0 Likes
Len_CONSULTRON
Honored Contributor II

Hossam Alzomor,

Nothing looks obvious however check your code for the following:

  • uint8 *rxdata points to an array of at least two bytes.  If you only have a variable with one byte the line dumping the incoming SPI data into rxdata[1] will overwrite unknown data. This unknown data could be stack or other RAM with pointer information.
  • You have a while statement that loops until at least one byte is available in the SPIM_1 Rx buffer.  You  might want to change the statement to: while(SPIM_1_GetRxBufferSize() <2);   Since the next three statements are assuming that at least two bytes are being read from the SPI, you might want to make sure at least two bytes have been received.  Your code only assumes one byte is available.

Hope this helps.

Len

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes