Skip to content

Commit eb7e332

Browse files
KurtEcfriedt
authored andcommitted
video: stm32_dcmi: DMA Error recovery
On several boards, such as the Arduino Giga and Portenta H7, they are often times setup with their camera buffers and potentially video buffers in SDRam. This can lead to a significant number of DMA errors, which currently stops the camera from returning any additional frames. Signed-off-by: Kurt Eckhardt <[email protected]>
1 parent 3d11ffd commit eb7e332

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

drivers/video/video_stm32_dcmi.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,31 @@ struct video_stm32_dcmi_config {
5555
const struct stream dma;
5656
};
5757

58+
static void stm32_dcmi_process_dma_error(DCMI_HandleTypeDef *hdcmi)
59+
{
60+
struct video_stm32_dcmi_data *dev_data =
61+
CONTAINER_OF(hdcmi, struct video_stm32_dcmi_data, hdcmi);
62+
63+
LOG_DBG("Restart DMA after Error!");
64+
65+
/* Lets try to recover by stopping and restart */
66+
if (HAL_DCMI_Stop(&dev_data->hdcmi) != HAL_OK) {
67+
LOG_WRN("HAL_DCMI_Stop FAILED!");
68+
return;
69+
}
70+
71+
if (HAL_DCMI_Start_DMA(&dev_data->hdcmi,
72+
DCMI_MODE_CONTINUOUS,
73+
(uint32_t)dev_data->vbuf->buffer,
74+
dev_data->vbuf->size / 4) != HAL_OK) {
75+
LOG_WRN("Continuous: HAL_DCMI_Start_DMA FAILED!");
76+
return;
77+
}
78+
}
79+
5880
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
5981
{
60-
LOG_WRN("%s", __func__);
82+
stm32_dcmi_process_dma_error(hdcmi);
6183
}
6284

6385
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
@@ -96,19 +118,12 @@ static void dcmi_dma_callback(const struct device *dev, void *arg, uint32_t chan
96118
DMA_HandleTypeDef *hdma = arg;
97119

98120
ARG_UNUSED(dev);
99-
100-
if (status < 0) {
101-
LOG_ERR("DMA callback error with channel %d.", channel);
102-
}
121+
ARG_UNUSED(channel);
122+
ARG_UNUSED(status);
103123

104124
HAL_DMA_IRQHandler(hdma);
105125
}
106126

107-
void HAL_DMA_ErrorCallback(DMA_HandleTypeDef *hdma)
108-
{
109-
LOG_WRN("%s", __func__);
110-
}
111-
112127
static int stm32_dma_init(const struct device *dev)
113128
{
114129
struct video_stm32_dcmi_data *data = dev->data;

0 commit comments

Comments
 (0)