Skip to main content
AWent
Associate II
August 9, 2019
Solved

JPEG Codec Decoding does not end/complete

  • August 9, 2019
  • 7 replies
  • 4731 views

Hey,

I transfered the JPEG_DecodingFromFLASH_DMA example code into program, where I try to decode and display a JPEG image which I receive via SPI (thus, the image data is storred in the Flash as well).

Board: STM32F769I-DISCO

The code is unchanged except of the parameters pointing to the data to be decoded and respectively its length in the JPEG_Decode_DMA function:

JPEG_Decode_DMA(&JPEG_Handle, (uint32_t)frame_buffer, frame_size, JPEG_OUTPUT_DATA_BUFFER);

However, when I wait for the JpegProcessingEnd, the JPEG_OutputHandler never returns a ProcessDoneFlag ('1').

do 
 {
 JpegProcessing_End = JPEG_OutputHandler(&JPEG_Handle);
 }while(JpegProcessing_End == 0);

From Debugging, I know this is because the state

Jpeg_OUT_BufferTab[JPEG_OUT_Read_BufferIndex].State == JPEG_BUFFER_FULL

will never be reaced.

Respectively, the HAL_JPEG_DataReadyCallback will bever be called wich should set the JPEG_BUFFER_FULL state.

And the JPEG_Process will not be executed which would call the Callback, if I got that correctly.

Any idea where and what I need to check to find out why the Decoding won't work?

(I wasn't able to test the original example code, because its too large for my uVision Licence)

This topic has been closed for replies.
Best answer by oleksandr.karbivsky

Check that you copy HAL_JPEG_MspInit function to your project (from file stm32h7xx_hal_msp.c in JPEG Example project)

7 replies

oleksandr.karbivsky
Senior II
August 9, 2019

Hi. Did you transfer example code to your own project? Did you also transfer MDMA configuration?

AWent
AWentAuthor
Associate II
August 9, 2019

Hi. Thanks for your hint.

I inserted the JPEG code into my project, yes.

My project is modified SPI_Full_Duplex_Com example. And I took the JPEG_Decoding code from the main, inserted the hal_jpeg driver, the decode_dma module and jpeg_utils plus all header files. Till I got no error messeges anymore.

But I am not quite sure about a MDMA? What is that? I couldn't find anything named MDMA in the JPEG_DecodingFromFLASH_DMA project?

oleksandr.karbivsky
Senior II
August 9, 2019

Check that you copy HAL_JPEG_MspInit function to your project (from file stm32h7xx_hal_msp.c in JPEG Example project)

AWent
AWentAuthor
Associate II
August 9, 2019

You are right, that is probably the solution! I missed the HAL_JPEG_MspInit function in the stm32f7xx_hal_msp.c, and the Compiler hasn't claimed it, beause its alredy defined as a __WEAK function in the hal_jpeg driver.

Unfortunately, I couldn't test right now, because the project just got to large for the 32K licence, but I will check soon and I am optimistic, that this was the missing point.

oleksandr.karbivsky
Senior II
August 9, 2019

Good luck)

AWent
AWentAuthor
Associate II
August 9, 2019

Thanks a lot again.

Besdies the HAL_JPEG_MspInit function, I also missed to copy some JPEG and DMA IRQHandler in stm32f7xx_it.c.

AWent
AWentAuthor
Associate II
August 12, 2019

However, the JPEG_Decode process still does not succeed. It will be aorted by a JPEG_DMAErrorCallback and I cannot figure out why.

To the JPEG_DMAErrorCallback it will be referred as "hjpeg->hdmain->XferErrorCallback" and "hjpeg->hdmaout->XferErrorCallback", but I cannot find the condition for their calls.

Does anyone have a idea or hint?

oleksandr.karbivsky
Senior II
August 12, 2019

Hi. What is MDMA Error Code Index?

AWent
AWentAuthor
Associate II
August 12, 2019

The hjpeg->ErrorCode is 4 (HAL_JPEG_ERROR_DMA, DMA transfer error)

Or is there something more detailed available?

oleksandr.karbivsky
Senior II
August 12, 2019

Where is output buffer placed?

AWent
AWentAuthor
Associate II
August 13, 2019

JPEG_OUTPUT_DATA_BUFFER is placed at address 0xC0200000.

/* Exported constants --------------------------------------------------------*/
#define LCD_FRAME_BUFFER 0xC0000000
#define JPEG_OUTPUT_DATA_BUFFER 0xC0200000 

The Jpeg_OUT_BufferTab(s) are located starting at 0x20000000 (stated by the debugger)

ROM/RAM configurations are:

ROM1: Start: 0x8000000, Size: 0x200000

RAM1: Start: 0x20000000, Size: 0x80000

Should be all similar to all the JPEG Decoding examples.

Charlie CHEN
Associate III
December 5, 2019

Hi @AWent​ ,

I got the same problem, can you share how you resolve it?

I`m stock in the code,and can`t get out.

do 
 {
 JpegProcessing_End = JPEG_OutputHandler(&JPEG_Handle);
 }while(JpegProcessing_End == 0);

hope you can see this!!

Thank you!

RGari
Associate II
January 2, 2020

I had the same problem, as well. In my case, I was decoding from RAM rather than a file directly... Make sure that the length of the data you pass to the Decode function is an even multiple of 32 bytes (the size of the MDMA transfer). Otherwise, it will get stuck trying to read an additional block of data before decoding the last few bytes, leaving you stuck forever. In my case, I just padded the length using

padding = FileSize % 32;

(and adding padding to the length)

Charlie CHEN
Associate III
January 2, 2020

Hi @RGari​ ,

Thanks for your reply!

The MDMA length like this one?

void HAL_JPEG_MspInit(JPEG_HandleTypeDef* hjpeg)
{
 if(hjpeg->Instance==JPEG)
 {
 /* USER CODE BEGIN JPEG_MspInit 0 */
 
 /* USER CODE END JPEG_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_JPEG_CLK_ENABLE();
 
 /* JPEG MDMA Init */
 /* JPEG_OUTFIFO_TH Init */
 hmdma_jpeg_outfifo_th.Instance = MDMA_Channel1;
 hmdma_jpeg_outfifo_th.Init.Request = MDMA_REQUEST_JPEG_OUTFIFO_TH;
 hmdma_jpeg_outfifo_th.Init.TransferTriggerMode = MDMA_BUFFER_TRANSFER;
 hmdma_jpeg_outfifo_th.Init.Priority = MDMA_PRIORITY_HIGH;
 hmdma_jpeg_outfifo_th.Init.Endianness = MDMA_LITTLE_ENDIANNESS_PRESERVE;
 hmdma_jpeg_outfifo_th.Init.SourceInc = MDMA_SRC_INC_DISABLE;
 hmdma_jpeg_outfifo_th.Init.DestinationInc = MDMA_DEST_INC_BYTE;
 hmdma_jpeg_outfifo_th.Init.SourceDataSize = MDMA_SRC_DATASIZE_WORD;
 hmdma_jpeg_outfifo_th.Init.DestDataSize = MDMA_DEST_DATASIZE_BYTE;
 hmdma_jpeg_outfifo_th.Init.DataAlignment = MDMA_DATAALIGN_PACKENABLE;
 hmdma_jpeg_outfifo_th.Init.BufferTransferLength = 32;
 hmdma_jpeg_outfifo_th.Init.SourceBurst = MDMA_SOURCE_BURST_32BEATS;
 hmdma_jpeg_outfifo_th.Init.DestBurst = MDMA_DEST_BURST_32BEATS;
 hmdma_jpeg_outfifo_th.Init.SourceBlockAddressOffset = 0;
 hmdma_jpeg_outfifo_th.Init.DestBlockAddressOffset = 0;
 if (HAL_MDMA_Init(&hmdma_jpeg_outfifo_th) != HAL_OK)
 {
 Error_Handler();
 }
 
 __HAL_LINKDMA(hjpeg,hdmaout,hmdma_jpeg_outfifo_th);
 
 /* JPEG_INFIFO_TH Init */
 hmdma_jpeg_infifo_th.Instance = MDMA_Channel0;
 hmdma_jpeg_infifo_th.Init.Request = MDMA_REQUEST_JPEG_INFIFO_TH;
 hmdma_jpeg_infifo_th.Init.TransferTriggerMode = MDMA_BUFFER_TRANSFER;
 hmdma_jpeg_infifo_th.Init.Priority = MDMA_PRIORITY_HIGH;
 hmdma_jpeg_infifo_th.Init.Endianness = MDMA_LITTLE_ENDIANNESS_PRESERVE;
 hmdma_jpeg_infifo_th.Init.SourceInc = MDMA_SRC_INC_BYTE;
 hmdma_jpeg_infifo_th.Init.DestinationInc = MDMA_DEST_INC_DISABLE;
 hmdma_jpeg_infifo_th.Init.SourceDataSize = MDMA_SRC_DATASIZE_BYTE;
 hmdma_jpeg_infifo_th.Init.DestDataSize = MDMA_DEST_DATASIZE_WORD;
 hmdma_jpeg_infifo_th.Init.DataAlignment = MDMA_DATAALIGN_PACKENABLE;
 hmdma_jpeg_infifo_th.Init.BufferTransferLength = 16;
 hmdma_jpeg_infifo_th.Init.SourceBurst = MDMA_SOURCE_BURST_32BEATS;
 hmdma_jpeg_infifo_th.Init.DestBurst = MDMA_DEST_BURST_32BEATS;
 hmdma_jpeg_infifo_th.Init.SourceBlockAddressOffset = 0;
 hmdma_jpeg_infifo_th.Init.DestBlockAddressOffset = 0;
 if (HAL_MDMA_Init(&hmdma_jpeg_infifo_th) != HAL_OK)
 {
 Error_Handler();
 }
 
 __HAL_LINKDMA(hjpeg,hdmain,hmdma_jpeg_infifo_th);
 
 /* JPEG interrupt Init */
 HAL_NVIC_SetPriority(JPEG_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(JPEG_IRQn);
 /* USER CODE BEGIN JPEG_MspInit 1 */
 
 /* USER CODE END JPEG_MspInit 1 */
 }
 
}

Where the padding can I add in?

By the way ,Is the function do..while needed?

Cause I face the new problem without the function.

New topic I post :https://community.st.com/s/question/0D50X0000Bucts0SQA/using-fatfs-with-jpeg-codec-and-show-on-lcd-panel

Hope you can help!

Appreciate that!