cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Memory Corruption in output_class_buffer - Adjacent Registers Affected

ACP
Associate

 

Hello,

I am facing a serious issue in my STM32 project related to the neai_classification function. Here's the context of my code:

 
float output_class_buffer[CLASS_NUMBER] __attribute__((aligned(4))); uint16_t id_class = 0;

When calling the function neai_classification(inst_current, output_class_buffer, &id_class);, I observe that the output_class_buffer contains very strange values (such as 0.72333524e-24), which don't make sense. More troubling, however, is that not only does output_class_buffer contain these weird values, but adjacent variables and registers are also being corrupted in the process.

In particular, variables that are adjacent to output_class_buffer are getting overwritten with unexpected values. This corruption extends to other variables in the program, causing them to hold invalid data, which in turn disrupts the application’s logic.

Details:

  • The output_class_buffer is aligned with __attribute__((aligned(4))), to ensure proper memory alignment.
  • The issue seems to be directly linked to the classification function modifying adjacent memory regions, leading to corruption of other variables.
  • The corrupted values in the output_class_buffer include values like 0.72333524e-24, which are not expected in the context of the data being handled.
  • It seems that the adjacent registers or memory locations are being incorrectly modified, affecting not just the buffer but also other program variables.

Questions:

  • Is there a possibility of a memory overflow or corruption happening due to incorrect buffer size or alignment?
  • Could this be related to the alignment of output_class_buffer or how memory is managed in the STM32 environment?
  • How can I debug or prevent this issue of adjacent memory corruption?
  • Has anyone encountered similar problems with buffer corruption in STM32, especially when working with classification functions?

I would greatly appreciate any insights or suggestions on how to resolve this issue.

1 REPLY 1
Julian E.
ST Employee

Hello @ACP ,

 

Could you share your libneai.a and knowledge (in a zip fie).

 

  • Is there a possibility of a memory overflow or corruption happening due to incorrect buffer size or alignment?

Yes, it is possible, you need to check on your own the buffer size and alignment

  • Could this be related to the alignment of output_class_buffer or how memory is managed in the STM32 environment?

It is unlikely but maybe

  • How can I debug or prevent this issue of adjacent memory corruption?

I would suggest putting hardware breakpoints (memory access) on the variables that are corrupted and check for the backtrace.

  • Has anyone encountered similar problems with buffer corruption in STM32, especially when working with classification functions?

No, it is the first time we encounter such an issue

 

Could you share more details: data type, board used etc

 

Also what do you mean by " I observe that the output_class_buffer contains very strange values (such as 0.72333524e-24), which don't make sense".?

What make you think that these values are incorrect?

 

And: "adjacent variables and registers are also being corrupted in the process."

Do you mean your own variables are being corrupted?

 

Can you provide us with a memory map describing variables and allocated buffers?

 

Have a good day,

Julian

 


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.