Skip to content

Commit e21d91f

Browse files
committed
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. This Pull request tries to recover from a subset of them, by stopping the HAL DCMI and then restart it. Signed-off-by: Kurt Eckhardt <kurte@rockisland.com>
1 parent c6818e1 commit e21d91f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

drivers/video/video_stm32_dcmi.c

Lines changed: 24 additions & 6 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)
@@ -94,6 +116,7 @@ static void stm32_dcmi_isr(const struct device *dev)
94116
static void dcmi_dma_callback(const struct device *dev, void *arg, uint32_t channel, int status)
95117
{
96118
DMA_HandleTypeDef *hdma = arg;
119+
DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)hdma->Parent;
97120

98121
ARG_UNUSED(dev);
99122

@@ -104,11 +127,6 @@ static void dcmi_dma_callback(const struct device *dev, void *arg, uint32_t chan
104127
HAL_DMA_IRQHandler(hdma);
105128
}
106129

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

0 commit comments

Comments
 (0)