From c17de02430e2089188774059dba7d0f2b3566a1b Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 25 Jan 2021 22:05:12 +0200 Subject: [PATCH 1/2] Add DCMI MSP Deinit. --- src/omv/ports/stm32/stm32fxxx_hal_msp.c | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/omv/ports/stm32/stm32fxxx_hal_msp.c b/src/omv/ports/stm32/stm32fxxx_hal_msp.c index e6584690c..4a5f2e19a 100644 --- a/src/omv/ports/stm32/stm32fxxx_hal_msp.c +++ b/src/omv/ports/stm32/stm32fxxx_hal_msp.c @@ -139,25 +139,27 @@ void HAL_MspInit(void) #if defined(DCMI_RESET_PIN) || defined(DCMI_PWDN_PIN) || defined(DCMI_FSYNC_PIN) /* Configure DCMI GPIO */ GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.Pull = GPIO_PULLDOWN; GPIO_InitStructure.Speed = GPIO_SPEED_LOW; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; #if defined(DCMI_RESET_PIN) GPIO_InitStructure.Pin = DCMI_RESET_PIN; + GPIO_InitStructure.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(DCMI_RESET_PORT, &GPIO_InitStructure); #endif - #if defined(DCMI_PWDN_PIN) - GPIO_InitStructure.Pin = DCMI_PWDN_PIN; - HAL_GPIO_Init(DCMI_PWDN_PORT, &GPIO_InitStructure); - #endif - #if defined(DCMI_FSYNC_PIN) GPIO_InitStructure.Pin = DCMI_FSYNC_PIN; + GPIO_InitStructure.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(DCMI_FSYNC_PORT, &GPIO_InitStructure); #endif + #if defined(DCMI_PWDN_PIN) + GPIO_InitStructure.Pin = DCMI_PWDN_PIN; + GPIO_InitStructure.Pull = GPIO_PULLUP; + HAL_GPIO_Init(DCMI_PWDN_PORT, &GPIO_InitStructure); + #endif + #endif // DCMI_RESET_PIN || DCMI_PWDN_PIN || DCMI_FSYNC_PIN } @@ -222,7 +224,7 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) /* Timer GPIO configuration */ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.Pin = DCMI_TIM_PIN; - GPIO_InitStructure.Pull = GPIO_NOPULL; + GPIO_InitStructure.Pull = GPIO_PULLUP; GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; GPIO_InitStructure.Alternate = DCMI_TIM_AF; @@ -255,7 +257,7 @@ void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi) /* DCMI GPIOs configuration */ GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.Pull = GPIO_PULLDOWN; + GPIO_InitStructure.Pull = GPIO_PULLUP; GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; GPIO_InitStructure.Alternate = GPIO_AF13_DCMI; @@ -272,6 +274,16 @@ void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi) } } +void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi) +{ + /* DCMI clock enable */ + __DCMI_CLK_DISABLE(); + for (int i=0; i Date: Mon, 25 Jan 2021 22:06:46 +0200 Subject: [PATCH 2/2] Deinit DCMI on sensor shutdown. --- src/omv/ports/stm32/sensor.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/omv/ports/stm32/sensor.c b/src/omv/ports/stm32/sensor.c index e3e1b4d58..d699594be 100644 --- a/src/omv/ports/stm32/sensor.c +++ b/src/omv/ports/stm32/sensor.c @@ -546,16 +546,28 @@ int sensor_sleep(int enable) int sensor_shutdown(int enable) { + int ret = 0; dcmi_abort(); if (enable) { - DCMI_PWDN_HIGH(); + if (sensor.pwdn_pol == ACTIVE_HIGH) { + DCMI_PWDN_HIGH(); + } else { + DCMI_PWDN_LOW(); + } + HAL_NVIC_DisableIRQ(DCMI_IRQn); + HAL_DCMI_DeInit(&DCMIHandle); } else { - DCMI_PWDN_LOW(); + if (sensor.pwdn_pol == ACTIVE_HIGH) { + DCMI_PWDN_LOW(); + } else { + DCMI_PWDN_HIGH(); + } + ret = dcmi_config(DCMI_JPEG_DISABLE); } systick_sleep(10); - return 0; + return ret; } int sensor_read_reg(uint16_t reg_addr)