@@ -45,6 +45,7 @@ struct video_stm32_dcmi_data {
45
45
struct k_fifo fifo_in ;
46
46
struct k_fifo fifo_out ;
47
47
struct video_buffer * vbuf ;
48
+ uint32_t snapshot_start_time ;
48
49
bool snapshot_mode ;
49
50
};
50
51
@@ -63,19 +64,19 @@ static void stm32_dcmi_process_dma_error(DCMI_HandleTypeDef *hdcmi)
63
64
CONTAINER_OF (hdcmi , struct video_stm32_dcmi_data , hdcmi );
64
65
65
66
LOG_WRN ("Restart DMA after Error!" );
66
- /* Lets try to recover by stopping and maybe restart */
67
+
68
+ /* Lets try to recover by stopping and restart */
67
69
if (HAL_DCMI_Stop (& dev_data -> hdcmi ) != HAL_OK ) {
68
- LOG_WRN ("HAL_DCMI_Stop FAILED!" );
70
+ LOG_WRN ("HAL_DCMI_Stop FAILED!" );
69
71
return ;
70
72
}
71
73
72
- /* error on last transfer try to restart it */
73
74
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 ;
75
+ dev_data -> snapshot_mode ? DCMI_MODE_SNAPSHOT : DCMI_MODE_CONTINUOUS ,
76
+ (uint32_t )dev_data -> vbuf -> buffer ,
77
+ dev_data -> vbuf -> size / 4 ) != HAL_OK ) {
78
+ LOG_WRN ("Continuous: HAL_DCMI_Start_DMA FAILED!" );
79
+ return ;
79
80
}
80
81
}
81
82
@@ -327,6 +328,8 @@ static int video_stm32_dcmi_enqueue(const struct device *dev, struct video_buffe
327
328
return 0 ;
328
329
}
329
330
331
+ #define SNAPSHOT_TIMEOUT_MS 5000
332
+
330
333
static int video_stm32_dcmi_dequeue (const struct device * dev , struct video_buffer * * vbuf ,
331
334
k_timeout_t timeout )
332
335
{
@@ -335,7 +338,29 @@ static int video_stm32_dcmi_dequeue(const struct device *dev, struct video_buffe
335
338
if (data -> snapshot_mode ) {
336
339
LOG_DBG ("dequeue snapshot: %p %llu\n" , data -> vbuf , timeout .ticks );
337
340
/* See if we were already called and have an active buffer */
338
- if (data -> vbuf == NULL ) {
341
+ if (data -> vbuf != NULL ) {
342
+ uint32_t time_since_start_time =
343
+ (uint32_t )(k_uptime_get_32 () - data -> snapshot_start_time );
344
+ if (time_since_start_time > SNAPSHOT_TIMEOUT_MS ) {
345
+ LOG_WRN ("Snapshot: Timed out!" );
346
+ if (HAL_DCMI_Stop (& data -> hdcmi ) != HAL_OK ) {
347
+ LOG_WRN ("Snapshot: HAL_DCMI_Stop FAILED!" );
348
+ }
349
+
350
+ if (HAL_DCMI_Start_DMA (& data -> hdcmi , DCMI_MODE_SNAPSHOT ,
351
+ (uint32_t )data -> vbuf -> buffer ,
352
+ data -> vbuf -> size / 4 ) != HAL_OK ) {
353
+ LOG_WRN ("Snapshot: HAL_DCMI_Start_DMA FAILED!" );
354
+ return - EIO ;
355
+ }
356
+
357
+ /* remember when we started this request */
358
+ data -> snapshot_start_time = k_uptime_get_32 ();
359
+ } else {
360
+ LOG_DBG ("Snapshot: restart after timeout" );
361
+ }
362
+
363
+ } else {
339
364
/* check first to see if we already have a buffer returned */
340
365
* vbuf = k_fifo_get (& data -> fifo_out , K_NO_WAIT );
341
366
if (* vbuf != NULL ) {
@@ -358,8 +383,9 @@ static int video_stm32_dcmi_dequeue(const struct device *dev, struct video_buffe
358
383
LOG_WRN ("Snapshot: HAL_DCMI_Start_DMA FAILED!" );
359
384
return - EIO ;
360
385
}
361
- } else {
362
- LOG_DBG ("Snapshot: restart after timeout" );
386
+
387
+ /* remember when we started this request */
388
+ data -> snapshot_start_time = k_uptime_get_32 ();
363
389
}
364
390
}
365
391
0 commit comments