/** * @brief Drives VBUS. * @param phost: Host handle * @param state: VBUS state * This parameter can be one of these values: * 0: VBUS Active * 1: VBUS Inactive * @retval USBH Status */ USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state) { #ifdef USE_USB_FS if(state == 0) { /* Configure Low Charge pump */ BSP_IO_WritePin(OTG_FS1_POWER_SWITCH_PIN, BSP_IO_PIN_RESET); } else { /* Drive High Charge pump */ BSP_IO_WritePin(OTG_FS1_POWER_SWITCH_PIN, BSP_IO_PIN_SET); } #endif #ifdef USE_USB_HS_IN_FS if(state == 0) { /* Configure Low Charge pump */ BSP_IO_WritePin(OTG_FS2_POWER_SWITCH_PIN, BSP_IO_PIN_RESET); } else { /* Drive High Charge pump */ BSP_IO_WritePin(OTG_FS2_POWER_SWITCH_PIN, BSP_IO_PIN_SET); } #endif HAL_Delay(200); return USBH_OK; }
/** * @brief Audio Application Init. * @param None * @retval None */ static void AUDIO_InitApplication(void) { /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Configure IO and LED1 */ BSP_IO_Init(); BSP_LED_Init(LED1); BSP_LED_Init(LED4); /* Configure Joystick in EXTI mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* Camera has to be powered down as some signals use same GPIOs between * I2S signals and camera bus. Camera drives its signals to low impedance * when powered ON. So the camera is powered off to let its signals * in high impedance */ /* Camera power down sequence */ BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT); BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); /* De-assert the camera STANDBY pin (active high) */ BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_RESET); /* Assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET); /* Initialize the LCD */ BSP_LCD_Init(); /* LCD Layer Initialization */ BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); /* Select the LCD Layer */ BSP_LCD_SelectLayer(1); /* Enable the display */ BSP_LCD_DisplayOn(); /* Init the LCD Log module */ LCD_LOG_Init(); LCD_LOG_SetHeader((uint8_t *)"Audio Playback and Record Application"); LCD_UsrLog("USB Host library started.\n"); /* Start Audio interface */ USBH_UsrLog("Starting Audio Demo"); /* Init Audio interface */ AUDIO_PLAYER_Init(); /* Start Audio interface */ AUDIO_MenuInit(); }
/** * @brief CAMERA power down * @param None * @retval None */ void BSP_CAMERA_PwrDown(void) { /* Camera power down sequence */ BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT); BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); /* De-assert the camera STANDBY pin (active high) */ BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_RESET); /* Assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET); }
/** * @brief Stops audio playing and Power down the Audio Codec. * @param Option: could be one of the following parameters * - CODEC_PDWN_HW: completely shut down the codec (physically). * Then need to reconfigure the Codec after power on. * @retval AUDIO_OK if correct communication, else wrong communication */ uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option) { /* Call DMA Stop to disable DMA stream before stopping codec */ HAL_I2S_DMAStop(&hAudioOutI2s); /* Call Audio Codec Stop function */ if(pAudioDrv->Stop(AUDIO_I2C_ADDRESS, Option) != 0) { return AUDIO_ERROR; } else { if(Option == CODEC_PDWN_HW) { /* Wait at least 100us */ HAL_Delay(1); /* Power Down the codec */ BSP_IO_WritePin(AUDIO_RESET_PIN, GPIO_PIN_RESET); } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; } }
/** * @brief Stops audio playing and Power down the Audio Codec. * @param Option: could be one of the following parameters * - CODEC_PDWN_SW: for software power off (by writing registers). * Then no need to reconfigure the Codec after power on. * - CODEC_PDWN_HW: completely shut down the codec (physically). * Then need to reconfigure the Codec after power on. * @retval AUDIO_OK if correct communication, else wrong communication */ uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option) { /* Call the Media layer stop function */ HAL_I2S_DMAStop(&haudio_i2s); /* Call Audio Codec Stop function */ if(audio_drv->Stop(AUDIO_I2C_ADDRESS, Option) != 0) { return AUDIO_ERROR; } else { if(Option == CODEC_PDWN_HW) { /* Wait at least 1ms */ HAL_Delay(1); /* Reset the pin */ BSP_IO_WritePin(AUDIO_RESET_PIN, RESET); } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; } }
/** * @brief Resets the audio codec. It restores the default configuration of the * codec (this function shall be called before initializing the codec). * @note This function calls an external driver function: The IO Expander driver. * @param None * @retval None */ static void CODEC_Reset(void) { /* Configure the IO Expander (to use the Codec Reset pin mapped on the IOExpander) */ BSP_IO_Init(); BSP_IO_ConfigPin(AUDIO_RESET_PIN, IO_MODE_OUTPUT); /* Power Down the codec */ BSP_IO_WritePin(AUDIO_RESET_PIN, RESET); /* Wait for a delay to insure registers erasing */ HAL_Delay(CODEC_RESET_DELAY); /* Power on the codec */ BSP_IO_WritePin(AUDIO_RESET_PIN, SET); /* Wait for a delay to insure registers erasing */ HAL_Delay(CODEC_RESET_DELAY); }
/** * @brief Get Idd current value. * @param IddValue: Pointer on u32 to store Idd. Value unit is 10 nA. * @retval None */ void BSP_IDD_GetValue(uint32_t *IddValue) { /* De-activate the OPAMP used ny the MFX to measure the current consumption */ BSP_IO_ConfigPin(IDD_AMP_CONTROL_PIN, IO_MODE_OUTPUT); BSP_IO_WritePin(IDD_AMP_CONTROL_PIN, GPIO_PIN_RESET); if (IddDrv->GetValue != NULL) { IddDrv->GetValue(IDD_I2C_ADDRESS, IddValue); } }
/** * @brief Start Measurement campaign * @retval None */ void BSP_IDD_StartMeasure(void) { /* Activate the OPAMP used ny the MFX to measure the current consumption */ BSP_IO_ConfigPin(IDD_AMP_CONTROL_PIN, IO_MODE_OUTPUT); BSP_IO_WritePin(IDD_AMP_CONTROL_PIN, GPIO_PIN_RESET); if (IddDrv->Start != NULL) { IddDrv->Start(IDD_I2C_ADDRESS); } }
/** * @brief Initializes the camera. * @param Camera: Pointer to the camera configuration structure * @retval Camera status */ uint8_t BSP_CAMERA_Init(uint32_t Resolution) { DCMI_HandleTypeDef *phdcmi; uint8_t ret = CAMERA_ERROR; /* Get the DCMI handle structure */ phdcmi = &hdcmi_eval; /*** Configures the DCMI to interface with the camera module ***/ /* DCMI configuration */ phdcmi->Init.CaptureRate = DCMI_CR_ALL_FRAME; phdcmi->Init.HSPolarity = DCMI_HSPOLARITY_LOW; phdcmi->Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; phdcmi->Init.VSPolarity = DCMI_VSPOLARITY_LOW; phdcmi->Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; phdcmi->Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; phdcmi->Instance = DCMI; /* Configure IO functionalities for camera detect pin */ BSP_IO_Init(); /* Set the camera STANDBY pin */ BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); BSP_IO_WritePin(XSDN_PIN, SET); /* Check if the camera is plugged */ if(BSP_IO_ReadPin(CAM_PLUG_PIN)) { return CAMERA_ERROR; } /* DCMI Initialization */ DCMI_MspInit(); HAL_DCMI_Init(phdcmi); if(ov2640_ReadID(CAMERA_I2C_ADDRESS) == OV2640_ID) { /* Initialize the camera driver structure */ camera_drv = &ov2640_drv; /* Camera Init */ camera_drv->Init(CAMERA_I2C_ADDRESS, Resolution); /* Return CAMERA_OK status */ ret = CAMERA_OK; } current_resolution = Resolution; return ret; }
/** * @brief CAMERA hardware reset * @param None * @retval None */ void BSP_CAMERA_HwReset(void) { /* Camera sensor RESET sequence */ BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT); BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); /* Assert the camera STANDBY pin (active high) */ BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_SET); /* Assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET); HAL_Delay(100); /* RST and XSDN signals asserted during 100ms */ /* De-assert the camera STANDBY pin (active high) */ BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_RESET); HAL_Delay(3); /* RST de-asserted and XSDN asserted during 3ms */ /* De-assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_SET); HAL_Delay(6); /* RST de-asserted during 3ms */ }
/** * @brief Stop the CAMERA capture * @param None * @retval Camera status */ uint8_t BSP_CAMERA_Stop(void) { DCMI_HandleTypeDef *phdcmi; uint8_t ret = CAMERA_ERROR; /* Get the DCMI handle structure */ phdcmi = &hdcmi_eval; if(HAL_DCMI_Stop(phdcmi) == HAL_OK) { ret = CAMERA_OK; } /* Initialize IO */ BSP_IO_Init(); /* Reset the camera STANDBY pin */ BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); BSP_IO_WritePin(XSDN_PIN, RESET); return ret; }
/** * @brief Main program * @param None * @retval None */ int main(void) { FRESULT res; /* FatFs function common result code */ uint32_t byteswritten, bytesread; /* File write/read counts */ uint8_t wtext[] = "This is STM32 working with FatFs"; /* File write buffer */ uint8_t rtext[100]; /* File read buffer */ /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure the system clock to 180 MHz */ SystemClock_Config(); /* Initialize IO expander */ BSP_IO_Init(); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /* ########################################################################### When the uSD Card is used; the Camera module must be unplugged, this is due to the shared pins between the two devices. Otherwise, you have to set camera sensor in Power Down mode, by calling the BSP_CAMERA_PwrDown() available under stm32446e_eval_camera.c BSP driver */ BSP_IO_Init(); /* Assert the camera RSTI pin */ /* Camera power down sequence */ BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT); /* Assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET); /*##-1- Link the SD disk I/O driver ########################################*/ if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0) { /*##-2- Register the file system object to the FatFs module ##############*/ if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK) { /* FatFs Initialization Error */ Error_Handler(); } else { /*##-3- Create a FAT file system (format) on the logical drive #########*/ if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK) { Error_Handler(); } else { /*##-4- Create and Open a new text file object with write access #####*/ if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { /* 'STM32.TXT' file Open for write Error */ Error_Handler(); } else { /*##-5- Write data to the text file ################################*/ res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten); if((byteswritten == 0) || (res != FR_OK)) { /* 'STM32.TXT' file Write or EOF Error */ Error_Handler(); } else { /*##-6- Close the open text file #################################*/ f_close(&MyFile); /*##-7- Open the text file object with read access ###############*/ if(f_open(&MyFile, "STM32.TXT", FA_READ) != FR_OK) { /* 'STM32.TXT' file Open for read Error */ Error_Handler(); } else { /*##-8- Read data from the text file ###########################*/ res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread); if((bytesread == 0) || (res != FR_OK)) { /* 'STM32.TXT' file Read or EOF Error */ Error_Handler(); } else { /*##-9- Close the open text file #############################*/ f_close(&MyFile); /*##-10- Compare read data with the expected data ############*/ if ((bytesread != byteswritten)) { /* Read data is different from the expected data */ Error_Handler(); } else { /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); } } } } } } } } /*##-11- Unlink the SD disk I/O driver ####################################*/ FATFS_UnLinkDriver(SDPath); /* Infinite loop */ while (1) { } }
/** * @brief SDRAM Demo * @param None * @retval None */ void IOE_GPIO_demo (void) { uint32_t ioe_irq_pending_status, ioe_gpio_status; uint32_t lcd_line = 85; uint8_t test_result = IOE_GPIO_TEST_PASSED; uint8_t all_test_fail = 1; GPIO_PinState mcu_pin_state; IOE_GPIO_SetHint(); /* Enable the Leds */ BSP_IO_Init(); BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_On(LED1); BSP_LED_On(LED2); BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); /* TEST IO_MODE_OUPUT mode */ /* ---------------------------------- */ /* SetUp a GPIO to be connected to one of the MFX GPIOS via a wire */ SetMcuGpioToBeConnectedToMfxGPO(); test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OUTPUT); BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_RESET); HAL_Delay(1); mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN); if (mcu_pin_state) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_SET); HAL_Delay(1); mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN); if (mcu_pin_state) { test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_RESET); HAL_Delay(1); mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN); if (mcu_pin_state) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_OUTPUT: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_OUTPUT: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_INPUT mode */ /* ---------------------------------- */ /* SetUp a GPIO to be connected to one of the MFX GPIOS via a wire */ SetMcuGpioToBeConnectedToMfxGPI(); test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_INPUT); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); HAL_Delay(1); ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN); if (ioe_gpio_status) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); HAL_Delay(1); ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN); if (ioe_gpio_status) { test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); HAL_Delay(1); ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN); if (ioe_gpio_status) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_INPUT: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_INPUT: PASSED", LEFT_MODE); all_test_fail = 0; } SetMcuGpioToBeConnectedToMfxGPI(); /* TEST IO_MODE_IT_HIGH_LEVEL mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_HIGH_LEVEL_PD); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_HIGH_LEVEL: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_HIGH_LEVEL: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_IT_LOW_LEVEL mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_LOW_LEVEL_PU); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_Delay(1); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_LOW_LEVEL: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_LOW_LEVEL: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_IT_RISING_EDGE mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_RISING_EDGE_PD); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_RISING_EDGE: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_RISING_EDGE: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_IT_FALLING_EDGE mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_FALLING_EDGE_PU); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_FALLING_EDGE: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_FALLING_EDGE: PASSED", LEFT_MODE); all_test_fail = 0; } if (all_test_fail) { BSP_LCD_DisplayStringAt(20, lcd_line + 20, (uint8_t *)" all IOE tests FAILED !!!", LEFT_MODE); BSP_LCD_DisplayStringAt(15, lcd_line + 40, (uint8_t *)"Are you sure that MCU_PB4 pin is connected ", LEFT_MODE); BSP_LCD_DisplayStringAt(15, lcd_line + 55, (uint8_t *)"to TP9 probe with a wire on the board ??", LEFT_MODE); } /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_EnableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); while (1) { if(CheckForUserInput() > 0) { return; } } }
/** * @brief Initializes the SD MSP. * @param hsd: SD handle * @param Params : pointer on additional configuration parameters, can be NULL. */ __weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params) { static DMA_HandleTypeDef dma_rx_handle; static DMA_HandleTypeDef dma_tx_handle; GPIO_InitTypeDef gpio_init_structure; /* SD pins are in conflict with Camera pins therefore Camera is power down */ /* __weak function can be modified by the application */ BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT); BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); /* De-assert the camera STANDBY pin (active high) */ BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_RESET); /* Assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET); HAL_Delay(100); /* Enable SDIO clock */ __HAL_RCC_SDIO_CLK_ENABLE(); /* Enable DMA2 clocks */ __DMAx_TxRx_CLK_ENABLE(); /* Enable GPIOs clock */ __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /* Common GPIO configuration */ gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Pull = GPIO_PULLUP; gpio_init_structure.Speed = GPIO_SPEED_HIGH; gpio_init_structure.Alternate = GPIO_AF12_SDIO; /* GPIOC configuration */ gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; HAL_GPIO_Init(GPIOC, &gpio_init_structure); /* GPIOD configuration */ gpio_init_structure.Pin = GPIO_PIN_2; HAL_GPIO_Init(GPIOD, &gpio_init_structure); /* NVIC configuration for SDIO interrupts */ HAL_NVIC_SetPriority(SDIO_IRQn, 5, 0); HAL_NVIC_EnableIRQ(SDIO_IRQn); /* Configure DMA Rx parameters */ dma_rx_handle.Init.Channel = SD_DMAx_Rx_CHANNEL; dma_rx_handle.Init.Direction = DMA_PERIPH_TO_MEMORY; dma_rx_handle.Init.PeriphInc = DMA_PINC_DISABLE; dma_rx_handle.Init.MemInc = DMA_MINC_ENABLE; dma_rx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dma_rx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; dma_rx_handle.Init.Mode = DMA_PFCTRL; dma_rx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH; dma_rx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dma_rx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dma_rx_handle.Init.MemBurst = DMA_MBURST_INC4; dma_rx_handle.Init.PeriphBurst = DMA_PBURST_INC4; dma_rx_handle.Instance = SD_DMAx_Rx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmarx, dma_rx_handle); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dma_rx_handle); /* Configure the DMA stream */ HAL_DMA_Init(&dma_rx_handle); /* Configure DMA Tx parameters */ dma_tx_handle.Init.Channel = SD_DMAx_Tx_CHANNEL; dma_tx_handle.Init.Direction = DMA_MEMORY_TO_PERIPH; dma_tx_handle.Init.PeriphInc = DMA_PINC_DISABLE; dma_tx_handle.Init.MemInc = DMA_MINC_ENABLE; dma_tx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dma_tx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; dma_tx_handle.Init.Mode = DMA_PFCTRL; dma_tx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH; dma_tx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dma_tx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dma_tx_handle.Init.MemBurst = DMA_MBURST_INC4; dma_tx_handle.Init.PeriphBurst = DMA_PBURST_INC4; dma_tx_handle.Instance = SD_DMAx_Tx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmatx, dma_tx_handle); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dma_tx_handle); /* Configure the DMA stream */ HAL_DMA_Init(&dma_tx_handle); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD_DMAx_Rx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD_DMAx_Rx_IRQn); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD_DMAx_Tx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD_DMAx_Tx_IRQn); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the MPU attributes as Write Through */ MPU_Config(); /* Enable the CPU Cache */ CPU_CACHE_Enable(); /* STM32F7xx HAL library initialization: - Configure the Flash ART accelerator on ITCM interface - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 200 MHz */ SystemClock_Config(); BSP_LED_Init(LED_GREEN); BSP_LED_Init(LED_ORANGE); BSP_LED_Init(LED_RED); BSP_LED_Init(LED_BLUE); /* Camera power down sequence */ BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT); BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); /* De-assert the camera STANDBY pin (active high) */ BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_RESET); /* Assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET); /* Configure the Tamper push-button in GPIO Mode */ BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO); /*##-1- Initialize the LCD #################################################*/ /* Initialize the LCD */ BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS); Display_DemoDescription(); /* Wait For User inputs */ while (1) { if ( mfx_toggle_led == 1) /* Toggle LED */ { BSP_LED_Toggle(LED_GREEN); mfx_toggle_led = 0; } if(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET) { while (BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET); BSP_examples[DemoIndex++].DemoFunc(); if(DemoIndex >= COUNT_OF_EXAMPLE(BSP_examples)) { NbLoop++; DemoIndex = 0; } Display_DemoDescription(); } } }
/** * @brief Initializes the SD MSP. * @param hsd: SD handle * @retval None */ __weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params) { static DMA_HandleTypeDef dma_rx_handle; static DMA_HandleTypeDef dma_tx_handle; static DMA_HandleTypeDef dma_rx_handle2; static DMA_HandleTypeDef dma_tx_handle2; GPIO_InitTypeDef gpio_init_structure; /* Camera has to be powered down as some signals use same GPIOs between * SD card and camera bus. Camera drives its signals to low impedance * when powered ON. So the camera is powered off to let its signals * in high impedance */ /* Camera power down sequence */ BSP_IO_ConfigPin(RSTI_PIN, IO_MODE_OUTPUT); BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); /* De-assert the camera STANDBY pin (active high) */ BSP_IO_WritePin(XSDN_PIN, BSP_IO_PIN_RESET); /* Assert the camera RSTI pin (active low) */ BSP_IO_WritePin(RSTI_PIN, BSP_IO_PIN_RESET); if(hsd->Instance == SDMMC1) { /* Enable SDIO clock */ __HAL_RCC_SDMMC1_CLK_ENABLE(); /* Enable DMA2 clocks */ __DMAx_TxRx_CLK_ENABLE(); /* Enable GPIOs clock */ __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /* Common GPIO configuration */ gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Pull = GPIO_PULLUP; gpio_init_structure.Speed = GPIO_SPEED_HIGH; gpio_init_structure.Alternate = GPIO_AF12_SDMMC1; /* GPIOC configuration: SD1_D0, SD1_D1, SD1_D2, SD1_D3 and SD1_CLK pins */ gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; HAL_GPIO_Init(GPIOC, &gpio_init_structure); /* GPIOD configuration: SD1_CMD pin */ gpio_init_structure.Pin = GPIO_PIN_2; HAL_GPIO_Init(GPIOD, &gpio_init_structure); /* NVIC configuration for SDIO interrupts */ HAL_NVIC_SetPriority(SDMMC1_IRQn, 5, 0); HAL_NVIC_EnableIRQ(SDMMC1_IRQn); dma_rx_handle.Init.Channel = SD1_DMAx_Rx_CHANNEL; dma_rx_handle.Init.Direction = DMA_PERIPH_TO_MEMORY; dma_rx_handle.Init.PeriphInc = DMA_PINC_DISABLE; dma_rx_handle.Init.MemInc = DMA_MINC_ENABLE; dma_rx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dma_rx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; dma_rx_handle.Init.Mode = DMA_PFCTRL; dma_rx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH; dma_rx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dma_rx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dma_rx_handle.Init.MemBurst = DMA_MBURST_INC4; dma_rx_handle.Init.PeriphBurst = DMA_PBURST_INC4; dma_rx_handle.Instance = SD1_DMAx_Rx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmarx, dma_rx_handle); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dma_rx_handle); /* Configure the DMA stream */ HAL_DMA_Init(&dma_rx_handle); dma_tx_handle.Init.Channel = SD1_DMAx_Tx_CHANNEL; dma_tx_handle.Init.Direction = DMA_MEMORY_TO_PERIPH; dma_tx_handle.Init.PeriphInc = DMA_PINC_DISABLE; dma_tx_handle.Init.MemInc = DMA_MINC_ENABLE; dma_tx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dma_tx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; dma_tx_handle.Init.Mode = DMA_PFCTRL; dma_tx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH; dma_tx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dma_tx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dma_tx_handle.Init.MemBurst = DMA_MBURST_INC4; dma_tx_handle.Init.PeriphBurst = DMA_PBURST_INC4; dma_tx_handle.Instance = SD1_DMAx_Tx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmatx, dma_tx_handle); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dma_tx_handle); /* Configure the DMA stream */ HAL_DMA_Init(&dma_tx_handle); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD1_DMAx_Rx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD1_DMAx_Rx_IRQn); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD1_DMAx_Tx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD1_DMAx_Tx_IRQn); } else { /* Enable SDIO clock */ __HAL_RCC_SDMMC2_CLK_ENABLE(); /* Enable DMA2 clocks */ __DMAx_TxRx_CLK_ENABLE(); /* Enable GPIOs clock */ __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); /* Common GPIO configuration */ gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Pull = GPIO_PULLUP; gpio_init_structure.Speed = GPIO_SPEED_HIGH; gpio_init_structure.Alternate = GPIO_AF10_SDMMC2; /* GPIOB configuration: SD2_D2 and SD2_D3 pins */ gpio_init_structure.Pin = GPIO_PIN_3 | GPIO_PIN_4; HAL_GPIO_Init(GPIOB, &gpio_init_structure); /* GPIOD configuration: SD2_CLK and SD2_CMD pins */ gpio_init_structure.Pin = GPIO_PIN_6 | GPIO_PIN_7; gpio_init_structure.Alternate = GPIO_AF11_SDMMC2; HAL_GPIO_Init(GPIOD, &gpio_init_structure); /* GPIOG configuration: SD2_D0 and SD2_D1 pins */ gpio_init_structure.Pin = GPIO_PIN_9 | GPIO_PIN_10; HAL_GPIO_Init(GPIOG, &gpio_init_structure); /* NVIC configuration for SDIO interrupts */ HAL_NVIC_SetPriority(SDMMC2_IRQn, 5, 0); HAL_NVIC_EnableIRQ(SDMMC2_IRQn); dma_rx_handle2.Init.Channel = SD2_DMAx_Rx_CHANNEL; dma_rx_handle2.Init.Direction = DMA_PERIPH_TO_MEMORY; dma_rx_handle2.Init.PeriphInc = DMA_PINC_DISABLE; dma_rx_handle2.Init.MemInc = DMA_MINC_ENABLE; dma_rx_handle2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dma_rx_handle2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; dma_rx_handle2.Init.Mode = DMA_PFCTRL; dma_rx_handle2.Init.Priority = DMA_PRIORITY_VERY_HIGH; dma_rx_handle2.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dma_rx_handle2.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dma_rx_handle2.Init.MemBurst = DMA_MBURST_INC4; dma_rx_handle2.Init.PeriphBurst = DMA_PBURST_INC4; dma_rx_handle2.Instance = SD2_DMAx_Rx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmarx, dma_rx_handle2); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dma_rx_handle2); /* Configure the DMA stream */ HAL_DMA_Init(&dma_rx_handle2); dma_tx_handle2.Init.Channel = SD2_DMAx_Tx_CHANNEL; dma_tx_handle2.Init.Direction = DMA_MEMORY_TO_PERIPH; dma_tx_handle2.Init.PeriphInc = DMA_PINC_DISABLE; dma_tx_handle2.Init.MemInc = DMA_MINC_ENABLE; dma_tx_handle2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dma_tx_handle2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; dma_tx_handle2.Init.Mode = DMA_PFCTRL; dma_tx_handle2.Init.Priority = DMA_PRIORITY_VERY_HIGH; dma_tx_handle2.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dma_tx_handle2.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dma_tx_handle2.Init.MemBurst = DMA_MBURST_INC4; dma_tx_handle2.Init.PeriphBurst = DMA_PBURST_INC4; dma_tx_handle2.Instance = SD2_DMAx_Tx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmatx, dma_tx_handle2); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dma_tx_handle2); /* Configure the DMA stream */ HAL_DMA_Init(&dma_tx_handle2); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD2_DMAx_Rx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD2_DMAx_Rx_IRQn); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD2_DMAx_Tx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD2_DMAx_Tx_IRQn); } }