Skip to content

Commit 4e37920

Browse files
committed
video: stm32_dcmi: DMA Error recovery
This was extracted from my snapshot PR: #93797 Been wondering if we should split off from there and at least get the simple recovery mechanism in place? Signed-off-by: Kurt Eckhardt <kurte@rockisland.com>
1 parent 2c3ec6b commit 4e37920

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

drivers/video/video_stm32_dcmi.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,32 @@ 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_WRN("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+
LOG_WRN("%s %p", __func__, hdcmi);
83+
stm32_dcmi_process_dma_error(hdcmi);
6184
}
6285

6386
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
@@ -94,21 +117,18 @@ static void stm32_dcmi_isr(const struct device *dev)
94117
static void dcmi_dma_callback(const struct device *dev, void *arg, uint32_t channel, int status)
95118
{
96119
DMA_HandleTypeDef *hdma = arg;
120+
DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)hdma->Parent;
97121

98122
ARG_UNUSED(dev);
99123

100124
if (status < 0) {
101125
LOG_ERR("DMA callback error with channel %d.", channel);
126+
stm32_dcmi_process_dma_error(hdcmi);
102127
}
103128

104129
HAL_DMA_IRQHandler(hdma);
105130
}
106131

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

0 commit comments

Comments
 (0)