cancel
Showing results for 
Search instead for 
Did you mean: 

f_write dropped 3 bytes

mthanh2602
Associate II

Hello, sorry for posting this post again.

I have a problem with my code. I'm trying to write a program to take picture from camera and save it as motion jpeg video (MJPEG) in to USB. I build already the header and the structure of MJPEG file but it's really weird when I try to run that avi file. Also with the source code was provided by STM, I finished to create the JPEG file.

I had checked and found out that the output data of frames and the idx1 is written by f_write was incorrect. Sometime 2 byte were written again. Someone told me maybe this problems is [3 bytes were dropped].

The header data I wrote to the begin of file is always right, but the data that I wrote to frame place and idx1 place usually has problem.

I want to write data like this below

01 02 03 04 05

01 02 03 04 05

01 02 03 04 05

01 02 03 04 05

but the output was like this

01 02 03 04 05

*01 02 01 02* 03

04 05 01 02 03

04 05 01 02 03

This link below simply show some information about MJPEG construction https://blog.goo.ne.jp/sirius506/e/442f430a1531c018a32471f1ecd4ae77

This is the f_write function I used

UINT frame_count = 0;
f_write (&JPEG_File, Frame, sizeof(Frame), &frame_count);
 
FRESULT f_write (
FIL* fp,            /* Pointer to the file object */
const void* buff,   /* Pointer to the data to be written */
UINT btw,           /* Number of bytes to write */
UINT* bw            /* Pointer to number of bytes written */
)
 
//USB init
 USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost)
{
#ifdef USE_USB_HS  
  /* Set the LL driver parameters */
  hhcd.Instance = USB_OTG_HS;
  hhcd.Init.Host_channels = 11; 
  hhcd.Init.dma_enable = 1;
  hhcd.Init.low_power_enable = 0;
#ifdef USE_USB_HS_IN_FS
  hhcd.Init.phy_itface = HCD_PHY_EMBEDDED; //This is not
#else  
  hhcd.Init.phy_itface = HCD_PHY_ULPI; //This ok
#endif  
  hhcd.Init.Sof_enable = 0;
  hhcd.Init.speed = HCD_SPEED_HIGH;
  hhcd.Init.use_external_vbus = 1;  
  /* Link the driver to the stack */
  hhcd.pData = phost;
  phost->pData = &hhcd;
  /* Initialize the LL driver */
  HAL_HCD_Init(&hhcd);
 
#endif /*USE_USB_HS*/ 
  USBH_LL_SetTimer(phost, HAL_HCD_GetCurrentFrame(&hhcd));
 
  return USBH_OK;
}

Please see the attached picture for more detail. I opened my MJPEG (avi) file by RIFF pad and it show me that the header was written into this output file was completely okay.

Anybody have experience about this? I am very appreciate with any advise.

Sorry for my English. Thank so much.

0690X000006CXhBQAW.png

0 REPLIES 0