Skip to content

Commit 6d0de1f

Browse files
committed
Video: stm32_dcmi: Have snaphshot recover like continuous
As suggested, I am trying the changes suggested, and have the error recovery code run in both modes, instead of returning an error condition in snapshot mode. Now testing
1 parent c7d69e9 commit 6d0de1f

File tree

1 file changed

+15
-38
lines changed

1 file changed

+15
-38
lines changed

drivers/video/video_stm32_dcmi.c

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct video_stm32_dcmi_data {
4646
struct k_fifo fifo_out;
4747
struct video_buffer *vbuf;
4848
bool snapshot_mode : 1;
49-
bool dma_error_detected : 1;
5049
};
5150

5251
struct video_stm32_dcmi_config {
@@ -63,25 +62,21 @@ static void stm32_dcmi_process_dma_error(DCMI_HandleTypeDef *hdcmi)
6362
struct video_stm32_dcmi_data *dev_data =
6463
CONTAINER_OF(hdcmi, struct video_stm32_dcmi_data, hdcmi);
6564

66-
if (dev_data->snapshot_mode) {
67-
dev_data->dma_error_detected = true;
68-
k_fifo_cancel_wait(&dev_data->fifo_out);
69-
} else {
70-
LOG_ERR("Restart DMA after Error!");
71-
/* Lets try to recover by stopping and maybe restart */
72-
if (HAL_DCMI_Stop(&dev_data->hdcmi) != HAL_OK) {
73-
LOG_WRN("HAL_DCMI_Stop FAILED!");
74-
return;
75-
}
76-
77-
/* error on last transfer try to restart it */
78-
if (HAL_DCMI_Start_DMA(&dev_data->hdcmi, DCMI_MODE_CONTINUOUS,
79-
(uint32_t)dev_data->vbuf->buffer,
80-
dev_data->vbuf->size / 4) != HAL_OK) {
81-
LOG_WRN("Continuous: HAL_DCMI_Start_DMA FAILED!");
82-
return;
83-
}
84-
}
65+
LOG_WRN("Restart DMA after Error!");
66+
/* Lets try to recover by stopping and maybe restart */
67+
if (HAL_DCMI_Stop(&dev_data->hdcmi) != HAL_OK) {
68+
LOG_WRN("HAL_DCMI_Stop FAILED!");
69+
return;
70+
}
71+
72+
/* error on last transfer try to restart it */
73+
if (HAL_DCMI_Start_DMA(&dev_data->hdcmi,
74+
dev_data->snapshot_mode ? DCMI_MODE_SNAPSHOT : DCMI_MODE_CONTINUOUS,
75+
(uint32_t)dev_data->vbuf->buffer,
76+
dev_data->vbuf->size / 4) != HAL_OK) {
77+
LOG_WRN("Continuous: HAL_DCMI_Start_DMA FAILED!");
78+
return;
79+
}
8580
}
8681

8782
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
@@ -363,23 +358,6 @@ static int video_stm32_dcmi_dequeue(const struct device *dev, struct video_buffe
363358
*vbuf = k_fifo_get(&data->fifo_out, timeout);
364359
printk("k_fifo_get returned: %p\n", *vbuf);
365360

366-
if (data->dma_error_detected) {
367-
data->dma_error_detected = false;
368-
printk("\tDMA Error detected\n");
369-
370-
/* Should only happen in snapshot mode */
371-
if (data->snapshot_mode) {
372-
if (HAL_DCMI_Stop(&data->hdcmi) != HAL_OK) {
373-
LOG_WRN("HAL_DCMI_Stop FAILED!");
374-
}
375-
if (data->vbuf != NULL) {
376-
printk("\treturn buffer: %p\n", data->vbuf);
377-
k_fifo_put(&data->fifo_in, data->vbuf);
378-
data->vbuf = NULL;
379-
}
380-
}
381-
}
382-
383361
if (*vbuf == NULL) {
384362
return -EAGAIN;
385363
}
@@ -646,7 +624,6 @@ static int video_stm32_dcmi_init(const struct device *dev)
646624
}
647625

648626
/* See if we should initialize to only support snapshot mode or not */
649-
data->dma_error_detected = false;
650627
data->snapshot_mode = config->snapshot_mode;
651628
if (CONFIG_VIDEO_BUFFER_POOL_NUM_MAX == 1) {
652629
LOG_DBG("Only one buffer so snapshot mode only");

0 commit comments

Comments
 (0)