5.9 DVP
This chapter covers how the N32H49x DVP camera interface is organized in the development kit, its public API and its example.
5.9.1 Related files
The table lists the header, the driver implementation, the example root and the layout of one example.
| Relative path | Purpose |
|---|---|
firmware/n32h49x_std_periph_driver/inc/n32h49x_dvp.h |
Register definitions, data types and public function declarations of the DVP peripheral. |
firmware/n32h49x_std_periph_driver/src/n32h49x_dvp.c |
DVP driver implementation: interface and capture control, frame buffer and DMA, interrupts and status. |
projects/n32h49x_EVAL/examples/DVP/Camera/ |
Example entry: the OV5640 captures an image and it is shown on an 800x480 ILI9806 LCD. |
projects/n32h49x_EVAL/examples/DVP/Camera/src/ |
Source layout: main.c, dvp_demo.c, bsp_dvp.c, bsp_ov5640.c, lcd.c and n32h49x_it.c. |
projects/n32h49x_EVAL/examples/DVP/Camera/inc/ |
Headers and declarations of the font and logo resources. |
5.9.2 API reference
The 40 public functions are grouped into 6 blocks in the declaration order of n32h49x_dvp.h; each entry gives a summary and the original source comment.
Initialization and reset
DVP_DeInit, DVP_Init, DVP_StructInit, DVP_DMAStructInit, DVP_ConfigDma
Interface and capture control
DVP_EnablePort, DVP_SetCaptureMode, DVP_EnableCrop, DVP_ConfigVBlankFilter, DVP_ConfigInitSKIP, DVP_ConfigRepeatSKIP, DVP_ConfigCROPStart, DVP_ConfigCROPEnd
Signal polarity and data format
DVP_ConfigPixelClockPolarity, DVP_ConfigHSyncPolarity, DVP_ConfigVSyncPolarity, DVP_EnableDataInvert, DVP_EnableDataReverse, DVP_ConfigDataMode, DVP_ConfigPixelByte, DVP_ConfigDATAByteOrder
Embedded synchronization
DVP_ConfigEmbSyncPos, DVP_ConfigEmbSyncData, DVP_ConfigEmbSyncDataMask, DVP_EnableEmbSyncMode
Frame buffer and DMA
DVP_EnableBuffer1, DVP_SetBuffer1Address, DVP_EnableBuffer2, DVP_SetBuffer2Address, DVP_SetBufferSize, DVP_SetDisplayBufferStatus, DVP_GetDisplayBufferStatus1, DVP_GetDisplayBufferStatus2, DVP_EnableAcross1KBoundary, DVP_FrameBufferAddrIncrementEnable
Interrupts and status
DVP_ConfigInt, DVP_GetFlagStatus, DVP_ClearFlag, DVP_GetIntStatus, DVP_ClrIntPendingBit
void DVP_EnablePort(FunctionalState Cmd)DVP interface enable. This function is called after DVP initialization is successful to start moving data.
name DVP_EnablePort.
fun DVP interface enable. This function is called after DVP
initialization is successful to start moving data.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_SetCaptureMode(uint32_t Mode)Config the capture mode.
name DVP_SetCaptureMode.
fun Config the capture mode.
param Mode:(The input parameters must be the following values)
- DVP_CAPTURE_MODE_CONTINUE
- DVP_CAPTURE_MODE_SINGLE
return none
void DVP_EnableCrop(FunctionalState Cmd)DVP crop feature enable. This function should be called before to enable and start the DVP interface.
name DVP_EnableCrop.
fun DVP crop feature enable. This function should be called
before to enable and start the DVP interface.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigVBlankFilter(uint8_t Filt)VSYNC blanking glitch filtering control. This function should be called before to enable and start the DVP interface.
name DVP_ConfigVBFLT.
fun VSYNC blanking glitch filtering control. This function should be called
before to enable and start the DVP interface.
param Filt:(The input parameters must be the following values)
- 0~0xF
return none
Use note: The name field in the source comment is written as DVP_ConfigVBFLT. and differs from the function name DVP_ConfigVBlankFilter; call it by the function name.
void DVP_ConfigInt(uint32_t DVPInt, FunctionalState Cmd)DVP interrupts enable.
name DVP_ConfigInt.
fun DVP interrupts enable.
param DVPInt (The input parameters must be the following values):
- DVP_INT_M1S
- DVP_INT_M2S
- DVP_INT_M1TC
- DVP_INT_M2TC
- DVP_INT_FO
- DVP_INT_AHBERR
- DVP_INT_MO
- DVP_INT_SKIP
- DVP_INT_CERR
- DVP_INT_SERR
- DVP_INT_FMS
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
FlagStatus DVP_GetFlagStatus(uint32_t DVP_Flag)Get DVP flag status. Checks whether the DVP interface flag is set or not.
name DVP_GetFlagStatus.
fun Get DVP flag status. Checks whether the DVP interface flag is set or not.
param DVP_Flag (The input parameters must be the following values):
- DVP_FLAG_M1S
- DVP_FLAG_M2S
- DVP_FLAG_M1TC
- DVP_FLAG_M2TC
- DVP_FLAG_M1FO
- DVP_FLAG_M2FO
- DVP_FLAG_AHBERR1
- DVP_FLAG_AHBERR2
- DVP_FLAG_M1O
- DVP_FLAG_M2O
- DVP_FLAG_SKIP
- DVP_FLAG_CERR
- DVP_FLAG_SERR
- DVP_FLAG_FMS
return SET or RESET.
void DVP_ClearFlag(uint32_t DVP_Flag)Clears DVP flag status.
name DVP_ClearFlag.
fun Clears DVP flag status.
param DVP_Flag (The input parameters must be the following values):
- DVP_FLAG_M1S
- DVP_FLAG_M2S
- DVP_FLAG_M1TC
- DVP_FLAG_M2TC
- DVP_FLAG_M1FO
- DVP_FLAG_M2FO
- DVP_FLAG_AHBERR1
- DVP_FLAG_AHBERR2
- DVP_FLAG_M1O
- DVP_FLAG_M2O
- DVP_FLAG_SKIP
- DVP_FLAG_CERR
- DVP_FLAG_SERR
- DVP_FLAG_FMS
return none.
INTStatus DVP_GetIntStatus(uint32_t DVP_Int)Get DVP interrupt status. Checks whether the DVP interrupt has occurred or not.
name DVP_GetIntStatus.
fun Get DVP interrupt status. Checks whether the DVP interrupt has occurred or not.
param DVP_Int (The input parameters must be the following values):
- DVP_INT_M1S
- DVP_INT_M2S
- DVP_INT_M1TC
- DVP_INT_M2TC
- DVP_INT_FO
- DVP_INT_AHBERR
- DVP_INT_MO
- DVP_INT_SKIP
- DVP_INT_CERR
- DVP_INT_SERR
- DVP_INT_FMS
return SET or RESET.
void DVP_ClrIntPendingBit(uint32_t DVP_Int)Clear DVP interrupt status bits.
name DVP_ClrIntPendingBit.
fun Clear DVP interrupt status bits.
param DVP_Int (The input parameters must be the following values):
- DVP_INT_M1S
- DVP_INT_M2S
- DVP_INT_M1TC
- DVP_INT_M2TC
- DVP_INT_FO
- DVP_INT_AHBERR
- DVP_INT_MO
- DVP_INT_SKIP
- DVP_INT_CERR
- DVP_INT_SERR
- DVP_INT_FMS
return none.
void DVP_ConfigPixelClockPolarity(uint32_t PLCK_POL)DVP port pixel clock polarity control.
name DVP_ConfigPixelClockPolarity.
fun DVP port pixel clock polarity control.
param PLCK_POL (The input parameters must be the following values):
- DVP_PIXEL_POLARITY_RISING
- DVP_PIXEL_POLARITY_FALLING
return none.
void DVP_ConfigHSyncPolarity(uint32_t HSYNC_POL)DVP HSYNC polarity control.
name DVP_ConfigHSyncPolarity.
fun DVP HSYNC polarity control.
param HSYNC_POL (The input parameters must be the following values):
- DVP_HSYNC_POLARITY_HIGH
- DVP_HSYNC_POLARITY_LOW
return none.
void DVP_ConfigVSyncPolarity(uint32_t VSYNC_POL)DVP VSYNC polarity control.
name DVP_ConfigVSyncPolarity.
fun DVP VSYNC polarity control.
param VSYNC_POL (The input parameters must be the following values):
- DVP_VSYNC_POLARITY_HIGH
- DVP_VSYNC_POLARITY_LOW
return none.
void DVP_EnableDataInvert(FunctionalState Cmd)DVP data inversion enable.
name DVP_EnableDataInvert.
fun DVP data inversion enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_EnableDataReverse(FunctionalState Cmd)DVP data Reverse enable.
name DVP_EnableDataReverse.
fun DVP data Reverse enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigEmbSyncPos(uint32_t SYNC_Pos)Embedded Synchronization Code Position.
name DVP_ConfigEmbSyncPos.
fun Embedded Synchronization Code Position.
param SYNC_Pos (The input parameters must be the following values):
- DVP_EMBSYNC_LSB
- DVP_EMBSYNC_MSB
return none.
void DVP_ConfigEmbSyncData(uint8_t FrameStartValue, uint8_t FrameEndValue, uint8_t LineStartValue, uint8_t LineEndValue)Embedded Synchronization Code Position.
name DVP_ConfigEmbSyncData.
fun Embedded Synchronization Code Position.
param FrameStartValue/FrameEndValue/LineStartValue/LineEndValue (The input parameters must be the following values):
- 0x00 ~ 0xFF
return none.
void DVP_ConfigEmbSyncDataMask(uint8_t FrameStartMask, uint8_t FrameEndMask, uint8_t LineStartMask, uint8_t LineEndMask)Embedded Synchronization Code Position.
name DVP_ConfigEmbSyncDataMask.
fun Embedded Synchronization Code Position.
param FrameStartMask/FrameEndMask/LineStartMask/LineEndMask (The input parameters must be the following values):
- 0x00 ~ 0xFF
return none.
void DVP_EnableEmbSyncMode(FunctionalState Cmd)Embedded Synchronization Mode enable bit.
name DVP_EnableEmbSyncMode.
fun Embedded Synchronization Mode enable bit.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigDataMode(uint32_t Mode)Config DVP data port mode.
name DVP_ConfigDataMode.
fun Config DVP data port mode.
param Mode (The input parameters must be the following values):
- DVP_DATA_MODE1
- DVP_DATA_MODE2
- DVP_DATA_MODE3
- DVP_DATA_MODE4
- DVP_DATA_MODE5
- DVP_DATA_MODE6
- DVP_DATA_MODE7
- DVP_DATA_MODE8
return none.
void DVP_ConfigPixelByte(uint32_t Pixel_Byte)Config DVP pixel bytes.
name DVP_ConfigPixelByte.
fun Config DVP pixel bytes.
param Pixel_Byte (The input parameters must be the following values):
- DVP_PIXEL_BYTE1
- DVP_PIXEL_BYTE2
return none.
void DVP_ConfigDATAByteOrder(uint32_t Byte0, uint32_t Byte1, uint32_t Byte2, uint32_t Byte3)Config DVP DATA order.
name DVP_ConfigDATAByteOrder.
fun Config DVP DATA order.
param Byte0 (The input parameters must be the following values):
- DVP_BYTE0_ORDER1
- DVP_BYTE0_ORDER2
- DVP_BYTE0_ORDER3
- DVP_BYTE0_ORDER4
param Byte1 (The input parameters must be the following values):
- DVP_BYTE1_ORDER1
- DVP_BYTE1_ORDER2
- DVP_BYTE1_ORDER3
- DVP_BYTE1_ORDER4
param Byte2 (The input parameters must be the following values):
- DVP_BYTE2_ORDER1
- DVP_BYTE2_ORDER2
- DVP_BYTE2_ORDER3
- DVP_BYTE2_ORDER4
param Byte3 (The input parameters must be the following values):
- DVP_BYTE3_ORDER1
- DVP_BYTE3_ORDER2
- DVP_BYTE3_ORDER3
- DVP_BYTE3_ORDER4
return none.
void DVP_ConfigInitSKIP(uint32_t Line)Config Initial Frame Line Skip .
name DVP_ConfigInitSKIP.
fun Config Initial Frame Line Skip .
param Line (The input parameters must be the following values):
- DVP_SKIP_LINE1
- DVP_SKIP_LINE2
- DVP_SKIP_LINE3
- DVP_SKIP_LINE4
- DVP_SKIP_LINE5
- DVP_SKIP_LINE6
- DVP_SKIP_LINE7
- DVP_SKIP_LINE8
- DVP_SKIP_LINE9
- DVP_SKIP_LINE10
- DVP_SKIP_LINE11
- DVP_SKIP_LINE12
- DVP_SKIP_LINE13
- DVP_SKIP_LINE14
- DVP_SKIP_LINE15
return none.
void DVP_ConfigRepeatSKIP(uint32_t Line)Config Repeat Frame Line Skip .
name DVP_ConfigRepeatSKIP.
fun Config Repeat Frame Line Skip .
param Line (The input parameters must be the following values):
- DVP_SKIP_LINE1
- DVP_SKIP_LINE2
- DVP_SKIP_LINE3
- DVP_SKIP_LINE4
- DVP_SKIP_LINE5
- DVP_SKIP_LINE6
- DVP_SKIP_LINE7
- DVP_SKIP_LINE8
- DVP_SKIP_LINE9
- DVP_SKIP_LINE10
- DVP_SKIP_LINE11
- DVP_SKIP_LINE12
- DVP_SKIP_LINE13
- DVP_ODD_LINE
- DVP_EVEN_LINE
return none.
void DVP_EnableBuffer1(FunctionalState Cmd)Frame Buffer 1 enable.
name DVP_EnableBuffer1.
fun Frame Buffer 1 enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_SetBuffer1Address(uint32_t Addres)Set Frame Buffer 1 Start Address.
name DVP_SetBuffer1Address.
fun Set Frame Buffer 1 Start Address.
param Addres:(The input parameters must be the following values)
- 0x00000000~0xFFFFFFFF
return none
void DVP_EnableBuffer2(FunctionalState Cmd)Frame Buffer 2 enable.
name DVP_EnableBuffer2.
fun Frame Buffer 2 enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_SetBuffer2Address(uint32_t Addres)Set Frame Buffer 2 Start Address.
name DVP_SetBuffer2Address.
fun Set Frame Buffer 2 Start Address.
param Addres:(The input parameters must be the following values)
- 0x00000000~0xFFFFFFFF
return none
void DVP_SetBufferSize(uint32_t Size)Set Frame Buffer Size.
name DVP_SetBufferSize.
fun Set Frame Buffer Size.
param Size:(The input parameters must be the following values)
- 0 ~ 4194303
return none
void DVP_SetDisplayBufferStatus(uint32_t State_Mode)Set show current frame buffer status.
name DVP_SetDisplayBufferStatus.
fun Set show current frame buffer status.
param State_Mode:(The input parameters must be the following values)
- DVP_DISPLAY_ADDRESS
- DVP_DISPLAY_NUMBER
return none
uint32_t DVP_GetDisplayBufferStatus1(void)Get current frame buffer 1 status.
name DVP_GetDisplayBufferStatus1.
fun Get current frame buffer 1 status.
param none
return Frame Buffer 1 address or Number of data bytes
uint32_t DVP_GetDisplayBufferStatus2(void)Get current frame buffer 2 status.
name DVP_GetDisplayBufferStatus2.
fun Get current frame buffer 2 status.
param none
return Frame Buffer 2 address or Number of data bytes
void DVP_EnableAcross1KBoundary(FunctionalState Cmd)Increamental bursting across 1K boundary is allowed/enabled
name DVP_EnableAcross1KBoundary.
fun Increamental bursting across 1K boundary is allowed/enabled
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
void DVP_ConfigCROPStart(uint16_t X,uint16_t Y)Config Y-coordinate and X-coordinate of crop image start point.
name DVP_ConfigCROPStart.
fun Config Y-coordinate and X-coordinate of crop image start point.
param (X,Y):(The input parameters must be the following values)
- (0,0) ~ (2047,2047)
return none
void DVP_ConfigCROPEnd(uint16_t X,uint16_t Y)Config Y-coordinate and X-coordinate of crop image end point.
name DVP_ConfigCROPEnd.
fun Config Y-coordinate and X-coordinate of crop image end point.
param (X,Y):(The input parameters must be the following values)
- (0,0) ~ (2047,2047)
return none
void DVP_DeInit(void)Deinitializes the DVP peripheral registers to their default reset values.
name DVP_DeInit.
fun Deinitializes the DVP peripheral registers to their default reset values.
param none
return none
void DVP_Init(DVP_InitType* DVP_InitParam)Initializes the DVP peripheral according to the specified parameters in the DVP_InitParam .
name DVP_Init.
fun Initializes the DVP peripheral according to the specified
parameters in the DVP_InitParam .
param DVP_InitParam (The input parameters must be the following values):
- CaptureMode
- DVP_CAPTURE_MODE_CONTINUE
- DVP_CAPTURE_MODE_SINGLE
- CropMode
- DVP_NORMAL_MODE
- DVP_CROP_MODE
- SynchroMode
- DVP_SYNC_MODE_SOFTWARE
- DVP_SYNC_MODE_HARDWARE
- CropStartX
- CropStartY
- CropEndX
- CropEndY
- BFilter
- PixelClkPolarity
- DVP_PIXEL_POLARITY_RISING
- DVP_PIXEL_POLARITY_FALLING
- HsyncPolarity
- DVP_HSYNC_POLARITY_HIGH
- DVP_HSYNC_POLARITY_LOW
- VsyncPolarity
- DVP_VSYNC_POLARITY_HIGH
- DVP_VSYNC_POLARITY_LOW
- DataInvert
- DVP_DATA_INVERT
- DVP_DATA_NOTINVERT
- DataReverse
- DVP_DATA_REVERSE
- DVP_DATA_NOTREVERSE
- DataMode
- DVP_DATA_MODE1
- DVP_DATA_MODE2
- DVP_DATA_MODE3
- DVP_DATA_MODE4
- DVP_DATA_MODE5
- DVP_DATA_MODE6
- DVP_DATA_MODE7
- DVP_DATA_MODE8
- PixelByte
- DVP_PIXEL_BYTE1
- DVP_PIXEL_BYTE2
return none
void DVP_StructInit(DVP_InitType* DVP_InitParam)Initializes the structure parameter of type DVP_InitType used to initialize DVP. This function is usually called before initializing a parameter of type DVP_InitType.
name DVP_StructInit.
fun Initializes the structure parameter of type DVP_InitType used to
initialize DVP. This function is usually called before initializing
a parameter of type DVP_InitType.
param DVP_InitParam :
- Pointer to the DVP_InitType structure which will be initialized.
return none
void DVP_ConfigDma(DVP_DMAInitType* DVP_DMAInitParam)Initializes the structure parameter of type DVP_DMAInitType used to initialize DVP DMA. This function is usually called before initializing a parameter of type DVP_DMAInitType.
name DVP_ConfigDma.
fun Initializes the structure parameter of type DVP_DMAInitType used to
initialize DVP DMA. This function is usually called before initializing
a parameter of type DVP_DMAInitType.
param DVP_DMAInitType :
- FrameBufferNum
- FrameBufferAddress1
- FrameBufferAddress2
- DisplayStatus
- DVP_DISPLAY_ADDRESS
- DVP_DISPLAY_NUMBER
- BurstSize
- DVP_BURST_SIZE_BYTE_4
- DVP_BURST_SIZE_BYTE_8
- DVP_BURST_SIZE_BYTE_12
- DVP_BURST_SIZE_BYTE_16
- DVP_BURST_SIZE_BYTE_20
- DVP_BURST_SIZE_BYTE_24
- DVP_BURST_SIZE_BYTE_28
- DVP_BURST_SIZE_BYTE_32
- FifoThreshold
- DVP_FIFO_THRSEHOLD_BYTE_4
- DVP_FIFO_THRSEHOLD_BYTE_8
- DVP_FIFO_THRSEHOLD_BYTE_16
- DVP_FIFO_THRSEHOLD_BYTE_32
- FrameBufferSize
return none
void DVP_DMAStructInit(DVP_DMAInitType* DVP_DMAInitParam)Initializes the structure parameter of type DVP_DMAInitType used to initialize DVP. This function is usually called before initializing a parameter of type DVP_DMAInitType.
name DVP_DMAStructInit.
fun Initializes the structure parameter of type DVP_DMAInitType used to
initialize DVP. This function is usually called before initializing
a parameter of type DVP_DMAInitType.
param DVP_DMAInitParam :
- Pointer to the DVP_DMAInitType structure which will be initialized.
return none
void DVP_FrameBufferAddrIncrementEnable(FunctionalState Cmd)DVP frame buffer address increment enable.
name DVP_FrameBufferAddrIncrementEnable.
fun DVP frame buffer address increment enable.
param Cmd:(The input parameters must be the following values)
- ENABLE
- DISABLE
return none
5.9.3 Demo descriptions
This section describes the DVP Camera example.
5.9.3.1 Camera OV5640 capture shown on the LCD
Example directory: projects/n32h49x_EVAL/examples/DVP/Camera/
Initialize the serial port and LCD→Configure the OV5640 over SCCB→Configure the DVP interface and DMA→Enable DVP capture→Move the frame to the LCD frame buffer in the frame interrupt
| Item | Source analysis |
|---|---|
| Function | Receives the image data produced by the OV5640. Shows the image on the ILI9806 LCD through the FEMC. |
| Source files | src/main.c: calls dvp_demo and then loops.src/dvp_demo.c: LCD initialization, the logo display and the example entry.src/bsp_dvp.c: the DVP interface, DMA and interrupt configuration.src/bsp_ov5640.c: SCCB timing and OV5640 register configuration.src/lcd.c: the FEMC-based LCD driver and image transfer.src/n32h49x_it.c: the DVP_IRQHandler interrupt service routine.readme.txt: function, environment and usage notes.MDK-ARM/, EWARM/: the Keil and IAR projects. |
| Key configuration | Clock source HSI+PLL, system frequency 240MHz. The OV5640 uses an 8-bit data interface: PCLK on PE4, HSYNC on PE2, VSYNC on PE3, with SCCB on PB6 and PB7. The LCD is an 800x480 ILI9806 driven by the FEMC over a 16-bit parallel bus. The frame buffer sits in on-chip SRAM and its size is set by DVP_IMAGE_SIZE. |
| Program and data path | main calls dvp_demo.dvp_demo initializes the serial port and LCD and then calls DVPDemo_Init.DVPDemo_Init configures the NVIC, initializes the OV5640, configures the DVP interface and DMA, and enables them.DVP_IRQHandler clears the flag in the frame interrupt and writes one frame into the LCD frame buffer. |
| Main APIs | DVP_Init, DVP_ConfigDma, DVP_ConfigInt, DVP_EnableBuffer1, DVP_EnablePort |
| Verification | After flashing and resetting, the camera image appears on the LCD. The serial port can be used for debug output. |
| Use note | J30 on the evaluation board controls the LCD reset and must be fitted. The development environment is KEIL MDK-ARM 5.34 or IAR EWARM 8.50.1. |
Core-code walkthrough and porting
The example shows the OV5640 image captured by the DVP directly on the LCD through the FEMC, a complete path from sensor to screen.
Data path: OV5640 outputs pixels -> the DVP interface and its internal DMA move them -> the frame buffer -> DVP_IRQHandler fires on the frame interrupt -> lcd_ov5640 writes the image into the LCD frame buffer
1. The example entry lights the screen before configuring capture. dvp_demo initializes the serial port and LCD, shows the logo, then calls DVPDemo_Init and finally enables the interface.
void dvp_demo(void)
{
log_init();
/* LCD configuration */
LCD_Configuration();
LCD_GramScan(0);
LCD_SetColors(RED,WHITE);
LCD_Clear(0,0,lcd_width,lcd_height);
LCD_Logo_init();
/* DVP configuration */
DVPDemo_Init();
DVP_EnablePort(ENABLE);
2. Initialization goes sensor, then interface, then interrupt. DVPDemo_Init configures the NVIC, initializes the OV5640 port and registers, configures the DVP interface and DMA, and enables them.
void DVPDemo_Init(void)
{
DVP_NVIC_Configuration();
OV5640_InitPort();
OV5640_Init();
OV5640_RGB565_Config();
DVP_InitInterface();
DVP_ConfigInt(DVP_INT_M1TC,ENABLE);
DVP_EnableBuffer1(ENABLE);
DVP_EnablePort(ENABLE);
3. The interface and DMA are configured through structures. DVP_InitInterface enables the DVP clock, fills DVP_InitType and DVP_DMAInitType, and calls DVP_Init and DVP_ConfigDma.
DVP_InitType DVP_InitStructure;
DVP_DMAInitType DVP_DMAInitStructure;
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPHEN_DVP, ENABLE);
DVP_StructInit(&DVP_InitStructure);
DVP_InitStructure.CaptureMode = DVP_CAPTURE_MODE_CONTINUE;
DVP_InitStructure.CropMode = DVP_NORMAL_MODE;
DVP_InitStructure.VBFilter = 3;
DVP_InitStructure.PixelClkPolarity = DVP_PIXEL_POLARITY_FALLING;
DVP_InitStructure.HsyncPolarity = DVP_HSYNC_POLARITY_HIGH;
DVP_InitStructure.VsyncPolarity = DVP_VSYNC_POLARITY_LOW;
DVP_InitStructure.DataInvert = DVP_DATA_NOTINVERT;
DVP_InitStructure.DataReverse = DVP_DATA_NOTREVERSE;
DVP_InitStructure.DataMode = DVP_DATA_MODE1;
DVP_InitStructure.PixelByte = DVP_PIXEL_BYTE1;
DVP_Init(&DVP_InitStructure);
DVP_DMAStructInit(&DVP_DMAInitStructure);
DVP_DMAInitStructure.FrameBufferNum = 1;
DVP_DMAInitStructure.FrameBufferAddress1 = LCD_IMAGE_ADDRESS;
DVP_DMAInitStructure.DisplayStatus = DVP_DISPLAY_ADDRESS;
DVP_DMAInitStructure.BurstSize = DVP_BURST_SIZE_BYTE_4;
DVP_DMAInitStructure.FifoThreshold = DVP_FIFO_THRSEHOLD_BYTE_4;
DVP_DMAInitStructure.FrameBufferSize = DVP_IMAGE_SIZE;
DVP_ConfigDma(&DVP_DMAInitStructure);
4. One frame is moved in the frame interrupt. DVP_IRQHandler checks the frame flag and interrupt status, clears the pending bit, and then writes the image to the LCD.
void DVP_IRQHandler(void)
{
if((DVP_GetFlagStatus(DVP_FLAG_M1TC)==1)&&(DVP_GetIntStatus(DVP_INT_M1TC)==1))
{
DVP_ClrIntPendingBit(DVP_INT_M1TC);
Corresponding source files: src/main.c, src/dvp_demo.c, src/bsp_dvp.c, src/n32h49x_it.c
5.9.4 Notes and troubleshooting
The table lists the operational constraints stated in the user manual for this peripheral.
| Scenario | Check & action | Source |
|---|---|---|
| DVP enabled after the vertical sync | The DVP port enable bit must be set at least 4 pixel clock cycles before DVP_VSYNC becomes active, otherwise the current frame is discarded. | User manual |
| Interface clock too slow | The AHB interface clock (hclk) must be equal to or faster than the pixel clock. | User manual |
| Crop coordinates not written first | Write the start and end coordinates before setting the CROPEN bit for the crop function. | User manual |
| Frame buffer DMA burst too large | The single-transfer size of the frame buffer DMA must be greater than or equal to the FIFO threshold. | User manual |
| Embedded sync data width | Embedded sync mode supports only 8-bit, 10-bit and 12-bit data modes. | User manual |
| Interrupt flag not cleared | Clear the relevant flag in DVP_INTSTS (write 0 to clear) before using an interrupt, so earlier state does not affect reporting. | User manual |
| Missing gap between lines | There must be at least one pixel clock cycle between any two lines. | User manual |