cancel
Showing results for 
Search instead for 
Did you mean: 

Support for JPEG Encoding / SD Card storage Integration in STM32N6 Object Detection Firmware

pikud
Associate II

Dear ST Community,

I have successfully run the Object Detection Application on the STM32N6 Discovery Kit using the reference firmware from the STM32AI ModelZoo.

As part of extending its functionality, I am looking to implement the following two features:

  1. Convert the captured RGB frame to JPEG format
  2. Store the JPEG image onto the SD card available on the Discovery Kit

For the RGB-to-JPEG conversion, I have referred to this JPEF Encoder example and integrated this JPEG encoding logic into the object detection firmware. Specifically, I am feeding the nn_in buffer (used as neural network input) to the JPEG encoder. However, during execution, the program gets stuck at this line:

jpeg_encode_processing_end = JPEG_EncodeOutputHandler(&hjpeg);

The jpeg_encode_processing_end flag is not being set to 1, indicating that the encoding process does not complete. I suspect either the JPEG input handling is not progressing, or the DMA isn't properly triggering the required callbacks.

Could you kindly review the approach and suggest the correct way to integrate JPEG encoding into the object detection pipeline?

I have attached my modified main.c file for your reference.

Appreciate your guidance on this.

4 REPLIES 4
Saket_Om
ST Employee

Hello @pikud 

Could you try to put as input the image in the JPEG encoder example. 

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.
Saket_Om

Hi @Saket_Om 
Following your suggestion, I tried using the static test image from the JPEG encoder example (image_320_240_rgb.h) as the input to the JPEG encoder of object detection firmware. However, upon doing so, the build fails with a linker error due to .rodata exceeding the available memory in the AXISRAM1_S region:

.section `.rodata' will not fit in region `AXISRAM1_S'
region `AXISRAM1_S' overflowed by 660280 bytes

To work around this, I moved large .rodata arrays (such as the test image or other large const buffers) into PSRAM using custom section attributes and appropriate linker script modifications. But by doing that I am unable to Run the program, but can build it.

Can you suggest what else needs to be done here?

 

Hello @pikud 

 


@pikud wrote:

 But by doing that I am unable to Run the program, but can build it.

Can you suggest what else needs to be done here?

 


What is the problem that appear when you run the program?

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.
Saket_Om
pikud
Associate II

Hi @Saket_Om 
1.) I’ve attached the problem log image below. Could you help identify what this might be related to?

 

2.) Also, the earlier issue of the program getting stuck at jpeg_encode_processing_end = JPEG_EncodeOutputHandler(&hjpeg) is resolved now 

It seems the JPEG encoding was getting stuck because the required interrupt handlers for JPEG and DMA were missing. I added them in stm32n6xx_it.x and it was fixed


3.)Currently, JPEG encoding is running, but I’m seeing corrupted or unexpected byte data in the encoded jpeg output. I've attached the updated main.c file for reference.

My question is: since nn_in is the pointer to the camera's output buffer (used as the NN input), is it safe and valid to pass it directly into the JPEG encoder like this?

JPEG_Encode_DMA(&hjpeg, (uint32_t)nn_in, RGB_IMAGE_SIZE_1, jpgBuffer);

Would appreciate any guidance on whether the nn_in buffer requires any format conversion or cache handling before passing it to the JPEG encoder.