├── .cproject ├── .gitignore ├── .mxproject ├── .project ├── .settings └── language.settings.xml ├── Drivers ├── CMSIS │ ├── Device │ │ └── ST │ │ │ └── STM32F4xx │ │ │ └── Include │ │ │ ├── stm32f401xe.h │ │ │ ├── stm32f4xx.h │ │ │ └── system_stm32f4xx.h │ └── Include │ │ ├── arm_common_tables.h │ │ ├── arm_const_structs.h │ │ ├── arm_math.h │ │ ├── cmsis_armcc.h │ │ ├── cmsis_armcc_V6.h │ │ ├── cmsis_gcc.h │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm3.h │ │ ├── core_cm4.h │ │ ├── core_cm7.h │ │ ├── core_cmFunc.h │ │ ├── core_cmInstr.h │ │ ├── core_cmSimd.h │ │ ├── core_sc000.h │ │ └── core_sc300.h └── STM32F4xx_HAL_Driver │ ├── Inc │ ├── Legacy │ │ └── stm32_hal_legacy.h │ ├── stm32f4xx_hal.h │ ├── stm32f4xx_hal_adc.h │ ├── stm32f4xx_hal_adc_ex.h │ ├── stm32f4xx_hal_cortex.h │ ├── stm32f4xx_hal_def.h │ ├── stm32f4xx_hal_dma.h │ ├── stm32f4xx_hal_dma_ex.h │ ├── stm32f4xx_hal_flash.h │ ├── stm32f4xx_hal_flash_ex.h │ ├── stm32f4xx_hal_flash_ramfunc.h │ ├── stm32f4xx_hal_gpio.h │ ├── stm32f4xx_hal_gpio_ex.h │ ├── stm32f4xx_hal_i2c.h │ ├── stm32f4xx_hal_i2c_ex.h │ ├── stm32f4xx_hal_pwr.h │ ├── stm32f4xx_hal_pwr_ex.h │ ├── stm32f4xx_hal_rcc.h │ ├── stm32f4xx_hal_rcc_ex.h │ ├── stm32f4xx_hal_tim.h │ ├── stm32f4xx_hal_tim_ex.h │ └── stm32f4xx_hal_uart.h │ └── Src │ ├── stm32f4xx_hal.c │ ├── stm32f4xx_hal_adc.c │ ├── stm32f4xx_hal_adc_ex.c │ ├── stm32f4xx_hal_cortex.c │ ├── stm32f4xx_hal_dma.c │ ├── stm32f4xx_hal_dma_ex.c │ ├── stm32f4xx_hal_flash.c │ ├── stm32f4xx_hal_flash_ex.c │ ├── stm32f4xx_hal_flash_ramfunc.c │ ├── stm32f4xx_hal_gpio.c │ ├── stm32f4xx_hal_i2c.c │ ├── stm32f4xx_hal_i2c_ex.c │ ├── stm32f4xx_hal_pwr.c │ ├── stm32f4xx_hal_pwr_ex.c │ ├── stm32f4xx_hal_rcc.c │ ├── stm32f4xx_hal_rcc_ex.c │ ├── stm32f4xx_hal_tim.c │ ├── stm32f4xx_hal_tim_ex.c │ └── stm32f4xx_hal_uart.c ├── Inc ├── adc.h ├── bh1750.h ├── dma.h ├── gpio.h ├── i2c.h ├── main.h ├── max44009.h ├── stm32f4xx_hal_conf.h ├── stm32f4xx_it.h ├── temt6000.h └── usart.h ├── LICENSE ├── Light_sensors Run.cfg ├── Light_sensors.ioc ├── Light_sensors.xml ├── README.md ├── STM32F401RETx_FLASH.ld ├── Src ├── adc.c ├── bh1750.c ├── dma.c ├── gpio.c ├── i2c.c ├── main.c ├── max44009.c ├── stm32f4xx_hal_msp.c ├── stm32f4xx_it.c ├── system_stm32f4xx.c ├── temt6000.c └── usart.c ├── startup └── startup_stm32f401xe.s └── syscalls.c /.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | */Backup/ -------------------------------------------------------------------------------- /.mxproject: -------------------------------------------------------------------------------- 1 | [PreviousGenFiles] 2 | HeaderPath=D:/GoogleDrive/Blog msalamon.pl/Materialy do wpisow/Czujniki swiatla/Kod/Light_sensors/Inc 3 | HeaderFiles=stm32f4xx_it.h;stm32f4xx_hal_conf.h;main.h;gpio.h;i2c.h;usart.h;adc.h;dma.h; 4 | SourcePath=D:/GoogleDrive/Blog msalamon.pl/Materialy do wpisow/Czujniki swiatla/Kod/Light_sensors/Src 5 | SourceFiles=stm32f4xx_it.c;stm32f4xx_hal_msp.c;main.c;gpio.c;i2c.c;usart.c;adc.c;dma.c; 6 | 7 | [PreviousLibFiles] 8 | LibFiles=Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f401xe.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/arm_common_tables.h;Drivers/CMSIS/Include/arm_const_structs.h;Drivers/CMSIS/Include/arm_math.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armcc_V6.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cmFunc.h;Drivers/CMSIS/Include/core_cmInstr.h;Drivers/CMSIS/Include/core_cmSimd.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_sc300.h; 9 | 10 | [PreviousUsedSW4STM32Files] 11 | SourceFiles=..\Src\main.c;..\Src\gpio.c;..\Src\adc.c;..\Src\dma.c;..\Src\i2c.c;..\Src\usart.c;..\Src\stm32f4xx_it.c;..\Src\stm32f4xx_hal_msp.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;../\Src/system_stm32f4xx.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;../\Src/system_stm32f4xx.c;../Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;D:/GoogleDrive/Blog msalamon.pl/Materialy do wpisow/Czujniki swiatla/Kod/Light_sensors//startup/startup_stm32f401xe.s; 12 | HeaderPath=..\Drivers\STM32F4xx_HAL_Driver\Inc;..\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32F4xx\Include;..\Drivers\CMSIS\Include;..\Inc; 13 | CDefines=__weak:__attribute__((weak));__packed:__attribute__((__packed__)); 14 | 15 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Light_sensors 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | fr.ac6.mcu.ide.core.MCUProjectNature 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamik/Light_Sensors_STM32/6130f058951df7c6bbe7fdd53192d99ed9387e91/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f4xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F4XX_H 48 | #define __SYSTEM_STM32F4XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F4xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F4xx_System_Exported_types 64 | * @{ 65 | */ 66 | /* This variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | /** 106 | * @} 107 | */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /*__SYSTEM_STM32F4XX_H */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. October 2015 5 | * $Revision: V.1.4.5 a 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * - Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * - Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in 21 | * the documentation and/or other materials provided with the 22 | * distribution. 23 | * - Neither the name of ARM LIMITED nor the names of its contributors 24 | * may be used to endorse or promote products derived from this 25 | * software without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * -------------------------------------------------------------------- */ 40 | 41 | #ifndef _ARM_COMMON_TABLES_H 42 | #define _ARM_COMMON_TABLES_H 43 | 44 | #include "arm_math.h" 45 | 46 | extern const uint16_t armBitRevTable[1024]; 47 | extern const q15_t armRecipTableQ15[64]; 48 | extern const q31_t armRecipTableQ31[64]; 49 | /* extern const q31_t realCoefAQ31[1024]; */ 50 | /* extern const q31_t realCoefBQ31[1024]; */ 51 | extern const float32_t twiddleCoef_16[32]; 52 | extern const float32_t twiddleCoef_32[64]; 53 | extern const float32_t twiddleCoef_64[128]; 54 | extern const float32_t twiddleCoef_128[256]; 55 | extern const float32_t twiddleCoef_256[512]; 56 | extern const float32_t twiddleCoef_512[1024]; 57 | extern const float32_t twiddleCoef_1024[2048]; 58 | extern const float32_t twiddleCoef_2048[4096]; 59 | extern const float32_t twiddleCoef_4096[8192]; 60 | #define twiddleCoef twiddleCoef_4096 61 | extern const q31_t twiddleCoef_16_q31[24]; 62 | extern const q31_t twiddleCoef_32_q31[48]; 63 | extern const q31_t twiddleCoef_64_q31[96]; 64 | extern const q31_t twiddleCoef_128_q31[192]; 65 | extern const q31_t twiddleCoef_256_q31[384]; 66 | extern const q31_t twiddleCoef_512_q31[768]; 67 | extern const q31_t twiddleCoef_1024_q31[1536]; 68 | extern const q31_t twiddleCoef_2048_q31[3072]; 69 | extern const q31_t twiddleCoef_4096_q31[6144]; 70 | extern const q15_t twiddleCoef_16_q15[24]; 71 | extern const q15_t twiddleCoef_32_q15[48]; 72 | extern const q15_t twiddleCoef_64_q15[96]; 73 | extern const q15_t twiddleCoef_128_q15[192]; 74 | extern const q15_t twiddleCoef_256_q15[384]; 75 | extern const q15_t twiddleCoef_512_q15[768]; 76 | extern const q15_t twiddleCoef_1024_q15[1536]; 77 | extern const q15_t twiddleCoef_2048_q15[3072]; 78 | extern const q15_t twiddleCoef_4096_q15[6144]; 79 | extern const float32_t twiddleCoef_rfft_32[32]; 80 | extern const float32_t twiddleCoef_rfft_64[64]; 81 | extern const float32_t twiddleCoef_rfft_128[128]; 82 | extern const float32_t twiddleCoef_rfft_256[256]; 83 | extern const float32_t twiddleCoef_rfft_512[512]; 84 | extern const float32_t twiddleCoef_rfft_1024[1024]; 85 | extern const float32_t twiddleCoef_rfft_2048[2048]; 86 | extern const float32_t twiddleCoef_rfft_4096[4096]; 87 | 88 | 89 | /* floating-point bit reversal tables */ 90 | #define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 ) 91 | #define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 ) 92 | #define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 ) 93 | #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 ) 94 | #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 ) 95 | #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 ) 96 | #define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800) 97 | #define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808) 98 | #define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032) 99 | 100 | extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH]; 101 | extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH]; 102 | extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH]; 103 | extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; 104 | extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; 105 | extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; 106 | extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH]; 107 | extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH]; 108 | extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH]; 109 | 110 | /* fixed-point bit reversal tables */ 111 | #define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 ) 112 | #define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 ) 113 | #define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 ) 114 | #define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 ) 115 | #define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 ) 116 | #define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 ) 117 | #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 ) 118 | #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) 119 | #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) 120 | 121 | extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH]; 122 | extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH]; 123 | extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH]; 124 | extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH]; 125 | extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH]; 126 | extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH]; 127 | extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; 128 | extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; 129 | extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; 130 | 131 | /* Tables for Fast Math Sine and Cosine */ 132 | extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; 133 | extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; 134 | extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; 135 | 136 | #endif /* ARM_COMMON_TABLES_H */ 137 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/arm_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. March 2015 5 | * $Revision: V.1.4.5 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_const_structs.h 9 | * 10 | * Description: This file has constant structs that are initialized for 11 | * user convenience. For example, some can be given as 12 | * arguments to the arm_cfft_f32() function. 13 | * 14 | * Target Processor: Cortex-M4/Cortex-M3 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * - Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above copyright 22 | * notice, this list of conditions and the following disclaimer in 23 | * the documentation and/or other materials provided with the 24 | * distribution. 25 | * - Neither the name of ARM LIMITED nor the names of its contributors 26 | * may be used to endorse or promote products derived from this 27 | * software without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 33 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 34 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 39 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 | * POSSIBILITY OF SUCH DAMAGE. 41 | * -------------------------------------------------------------------- */ 42 | 43 | #ifndef _ARM_CONST_STRUCTS_H 44 | #define _ARM_CONST_STRUCTS_H 45 | 46 | #include "arm_math.h" 47 | #include "arm_common_tables.h" 48 | 49 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; 50 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; 51 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; 52 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; 53 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; 54 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; 55 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; 56 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; 57 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; 58 | 59 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; 60 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; 61 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; 62 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; 63 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; 64 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; 65 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; 66 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; 67 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; 68 | 69 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; 70 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; 71 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; 72 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; 73 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; 74 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; 75 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; 76 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; 77 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/core_cmFunc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmFunc.h 3 | * @brief CMSIS Cortex-M Core Function Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMFUNC_H 42 | #define __CORE_CMFUNC_H 43 | 44 | 45 | /* ########################### Core Function Access ########################### */ 46 | /** \ingroup CMSIS_Core_FunctionInterface 47 | \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@} end of CMSIS_Core_RegAccFunctions */ 86 | 87 | #endif /* __CORE_CMFUNC_H */ 88 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/core_cmInstr.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmInstr.h 3 | * @brief CMSIS Cortex-M Core Instruction Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMINSTR_H 42 | #define __CORE_CMINSTR_H 43 | 44 | 45 | /* ########################## Core Instruction Access ######################### */ 46 | /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface 47 | Access to dedicated instructions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ 86 | 87 | #endif /* __CORE_CMINSTR_H */ 88 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/core_cmSimd.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmSimd.h 3 | * @brief CMSIS Cortex-M SIMD Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMSIMD_H 42 | #define __CORE_CMSIMD_H 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | 49 | /* ################### Compiler specific Intrinsics ########################### */ 50 | /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics 51 | Access to dedicated SIMD instructions 52 | @{ 53 | */ 54 | 55 | /*------------------ RealView Compiler -----------------*/ 56 | #if defined ( __CC_ARM ) 57 | #include "cmsis_armcc.h" 58 | 59 | /*------------------ ARM Compiler V6 -------------------*/ 60 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 61 | #include "cmsis_armcc_V6.h" 62 | 63 | /*------------------ GNU Compiler ----------------------*/ 64 | #elif defined ( __GNUC__ ) 65 | #include "cmsis_gcc.h" 66 | 67 | /*------------------ ICC Compiler ----------------------*/ 68 | #elif defined ( __ICCARM__ ) 69 | #include 70 | 71 | /*------------------ TI CCS Compiler -------------------*/ 72 | #elif defined ( __TMS470__ ) 73 | #include 74 | 75 | /*------------------ TASKING Compiler ------------------*/ 76 | #elif defined ( __TASKING__ ) 77 | /* 78 | * The CMSIS functions have been implemented as intrinsics in the compiler. 79 | * Please use "carm -?i" to get an up to date list of all intrinsics, 80 | * Including the CMSIS ones. 81 | */ 82 | 83 | /*------------------ COSMIC Compiler -------------------*/ 84 | #elif defined ( __CSMC__ ) 85 | #include 86 | 87 | #endif 88 | 89 | /*@} end of group CMSIS_SIMD_intrinsics */ 90 | 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* __CORE_CMSIMD_H */ 97 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the functions prototypes for the HAL 6 | * module driver. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© COPYRIGHT(c) 2017 STMicroelectronics

11 | * 12 | * Redistribution and use in source and binary forms, with or without modification, 13 | * are permitted provided that the following conditions are met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | ****************************************************************************** 35 | */ 36 | 37 | /* Define to prevent recursive inclusion -------------------------------------*/ 38 | #ifndef __STM32F4xx_HAL_H 39 | #define __STM32F4xx_HAL_H 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* Includes ------------------------------------------------------------------*/ 46 | #include "stm32f4xx_hal_conf.h" 47 | 48 | /** @addtogroup STM32F4xx_HAL_Driver 49 | * @{ 50 | */ 51 | 52 | /** @addtogroup HAL 53 | * @{ 54 | */ 55 | 56 | /* Exported types ------------------------------------------------------------*/ 57 | /* Exported constants --------------------------------------------------------*/ 58 | 59 | /** @defgroup HAL_Exported_Constants HAL Exported Constants 60 | * @{ 61 | */ 62 | 63 | /** @defgroup HAL_TICK_FREQ Tick Frequency 64 | * @{ 65 | */ 66 | typedef enum 67 | { 68 | HAL_TICK_FREQ_10HZ = 100U, 69 | HAL_TICK_FREQ_100HZ = 10U, 70 | HAL_TICK_FREQ_1KHZ = 1U, 71 | HAL_TICK_FREQ_DEFAULT = HAL_TICK_FREQ_1KHZ 72 | } HAL_TickFreqTypeDef; 73 | /** 74 | * @} 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Exported macro ------------------------------------------------------------*/ 82 | /** @defgroup HAL_Exported_Macros HAL Exported Macros 83 | * @{ 84 | */ 85 | 86 | /** @brief Freeze/Unfreeze Peripherals in Debug mode 87 | */ 88 | #define __HAL_DBGMCU_FREEZE_TIM2() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM2_STOP)) 89 | #define __HAL_DBGMCU_FREEZE_TIM3() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM3_STOP)) 90 | #define __HAL_DBGMCU_FREEZE_TIM4() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM4_STOP)) 91 | #define __HAL_DBGMCU_FREEZE_TIM5() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM5_STOP)) 92 | #define __HAL_DBGMCU_FREEZE_TIM6() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM6_STOP)) 93 | #define __HAL_DBGMCU_FREEZE_TIM7() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM7_STOP)) 94 | #define __HAL_DBGMCU_FREEZE_TIM12() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM12_STOP)) 95 | #define __HAL_DBGMCU_FREEZE_TIM13() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM13_STOP)) 96 | #define __HAL_DBGMCU_FREEZE_TIM14() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_TIM14_STOP)) 97 | #define __HAL_DBGMCU_FREEZE_RTC() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_RTC_STOP)) 98 | #define __HAL_DBGMCU_FREEZE_WWDG() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_WWDG_STOP)) 99 | #define __HAL_DBGMCU_FREEZE_IWDG() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_IWDG_STOP)) 100 | #define __HAL_DBGMCU_FREEZE_I2C1_TIMEOUT() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT)) 101 | #define __HAL_DBGMCU_FREEZE_I2C2_TIMEOUT() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_I2C2_SMBUS_TIMEOUT)) 102 | #define __HAL_DBGMCU_FREEZE_I2C3_TIMEOUT() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_I2C3_SMBUS_TIMEOUT)) 103 | #define __HAL_DBGMCU_FREEZE_CAN1() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_CAN1_STOP)) 104 | #define __HAL_DBGMCU_FREEZE_CAN2() (DBGMCU->APB1FZ |= (DBGMCU_APB1_FZ_DBG_CAN2_STOP)) 105 | #define __HAL_DBGMCU_FREEZE_TIM1() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM1_STOP)) 106 | #define __HAL_DBGMCU_FREEZE_TIM8() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM8_STOP)) 107 | #define __HAL_DBGMCU_FREEZE_TIM9() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM9_STOP)) 108 | #define __HAL_DBGMCU_FREEZE_TIM10() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM10_STOP)) 109 | #define __HAL_DBGMCU_FREEZE_TIM11() (DBGMCU->APB2FZ |= (DBGMCU_APB2_FZ_DBG_TIM11_STOP)) 110 | 111 | #define __HAL_DBGMCU_UNFREEZE_TIM2() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM2_STOP)) 112 | #define __HAL_DBGMCU_UNFREEZE_TIM3() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM3_STOP)) 113 | #define __HAL_DBGMCU_UNFREEZE_TIM4() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM4_STOP)) 114 | #define __HAL_DBGMCU_UNFREEZE_TIM5() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM5_STOP)) 115 | #define __HAL_DBGMCU_UNFREEZE_TIM6() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM6_STOP)) 116 | #define __HAL_DBGMCU_UNFREEZE_TIM7() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM7_STOP)) 117 | #define __HAL_DBGMCU_UNFREEZE_TIM12() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM12_STOP)) 118 | #define __HAL_DBGMCU_UNFREEZE_TIM13() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM13_STOP)) 119 | #define __HAL_DBGMCU_UNFREEZE_TIM14() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_TIM14_STOP)) 120 | #define __HAL_DBGMCU_UNFREEZE_RTC() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_RTC_STOP)) 121 | #define __HAL_DBGMCU_UNFREEZE_WWDG() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_WWDG_STOP)) 122 | #define __HAL_DBGMCU_UNFREEZE_IWDG() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_IWDG_STOP)) 123 | #define __HAL_DBGMCU_UNFREEZE_I2C1_TIMEOUT() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT)) 124 | #define __HAL_DBGMCU_UNFREEZE_I2C2_TIMEOUT() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_I2C2_SMBUS_TIMEOUT)) 125 | #define __HAL_DBGMCU_UNFREEZE_I2C3_TIMEOUT() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_I2C3_SMBUS_TIMEOUT)) 126 | #define __HAL_DBGMCU_UNFREEZE_CAN1() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_CAN1_STOP)) 127 | #define __HAL_DBGMCU_UNFREEZE_CAN2() (DBGMCU->APB1FZ &= ~(DBGMCU_APB1_FZ_DBG_CAN2_STOP)) 128 | #define __HAL_DBGMCU_UNFREEZE_TIM1() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM1_STOP)) 129 | #define __HAL_DBGMCU_UNFREEZE_TIM8() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM8_STOP)) 130 | #define __HAL_DBGMCU_UNFREEZE_TIM9() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM9_STOP)) 131 | #define __HAL_DBGMCU_UNFREEZE_TIM10() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM10_STOP)) 132 | #define __HAL_DBGMCU_UNFREEZE_TIM11() (DBGMCU->APB2FZ &= ~(DBGMCU_APB2_FZ_DBG_TIM11_STOP)) 133 | 134 | /** @brief Main Flash memory mapped at 0x00000000 135 | */ 136 | #define __HAL_SYSCFG_REMAPMEMORY_FLASH() (SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_MEM_MODE)) 137 | 138 | /** @brief System Flash memory mapped at 0x00000000 139 | */ 140 | #define __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH() do {SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_MEM_MODE);\ 141 | SYSCFG->MEMRMP |= SYSCFG_MEMRMP_MEM_MODE_0;\ 142 | }while(0); 143 | 144 | /** @brief Embedded SRAM mapped at 0x00000000 145 | */ 146 | #define __HAL_SYSCFG_REMAPMEMORY_SRAM() do {SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_MEM_MODE);\ 147 | SYSCFG->MEMRMP |= (SYSCFG_MEMRMP_MEM_MODE_0 | SYSCFG_MEMRMP_MEM_MODE_1);\ 148 | }while(0); 149 | 150 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx) 151 | /** @brief FSMC Bank1 (NOR/PSRAM 1 and 2) mapped at 0x00000000 152 | */ 153 | #define __HAL_SYSCFG_REMAPMEMORY_FSMC() do {SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_MEM_MODE);\ 154 | SYSCFG->MEMRMP |= (SYSCFG_MEMRMP_MEM_MODE_1);\ 155 | }while(0); 156 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */ 157 | 158 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\ 159 | defined(STM32F469xx) || defined(STM32F479xx) 160 | /** @brief FMC Bank1 (NOR/PSRAM 1 and 2) mapped at 0x00000000 161 | */ 162 | #define __HAL_SYSCFG_REMAPMEMORY_FMC() do {SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_MEM_MODE);\ 163 | SYSCFG->MEMRMP |= (SYSCFG_MEMRMP_MEM_MODE_1);\ 164 | }while(0); 165 | 166 | /** @brief FMC/SDRAM Bank 1 and 2 mapped at 0x00000000 167 | */ 168 | #define __HAL_SYSCFG_REMAPMEMORY_FMC_SDRAM() do {SYSCFG->MEMRMP &= ~(SYSCFG_MEMRMP_MEM_MODE);\ 169 | SYSCFG->MEMRMP |= (SYSCFG_MEMRMP_MEM_MODE_2);\ 170 | }while(0); 171 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ 172 | 173 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F413xx) || defined(STM32F423xx) 174 | /** @defgroup Cortex_Lockup_Enable Cortex Lockup Enable 175 | * @{ 176 | */ 177 | /** @brief SYSCFG Break Lockup lock 178 | * Enables and locks the connection of Cortex-M4 LOCKUP (Hardfault) output to TIM1/8 input 179 | * @note The selected configuration is locked and can be unlocked by system reset 180 | */ 181 | #define __HAL_SYSCFG_BREAK_PVD_LOCK() do {SYSCFG->CFGR2 &= ~(SYSCFG_CFGR2_PVD_LOCK); \ 182 | SYSCFG->CFGR2 |= SYSCFG_CFGR2_PVD_LOCK; \ 183 | }while(0) 184 | /** 185 | * @} 186 | */ 187 | 188 | /** @defgroup PVD_Lock_Enable PVD Lock 189 | * @{ 190 | */ 191 | /** @brief SYSCFG Break PVD lock 192 | * Enables and locks the PVD connection with Timer1/8 Break Input, , as well as the PVDE and PLS[2:0] in the PWR_CR register 193 | * @note The selected configuration is locked and can be unlocked by system reset 194 | */ 195 | #define __HAL_SYSCFG_BREAK_LOCKUP_LOCK() do {SYSCFG->CFGR2 &= ~(SYSCFG_CFGR2_LOCKUP_LOCK); \ 196 | SYSCFG->CFGR2 |= SYSCFG_CFGR2_LOCKUP_LOCK; \ 197 | }while(0) 198 | /** 199 | * @} 200 | */ 201 | #endif /* STM32F410Tx || STM32F410Cx || STM32F410Rx || STM32F413xx || STM32F423xx */ 202 | /** 203 | * @} 204 | */ 205 | 206 | /** @defgroup HAL_Private_Macros HAL Private Macros 207 | * @{ 208 | */ 209 | #define IS_TICKFREQ(FREQ) (((FREQ) == HAL_TICK_FREQ_10HZ) || \ 210 | ((FREQ) == HAL_TICK_FREQ_100HZ) || \ 211 | ((FREQ) == HAL_TICK_FREQ_1KHZ)) 212 | /** 213 | * @} 214 | */ 215 | 216 | /* Exported functions --------------------------------------------------------*/ 217 | /** @addtogroup HAL_Exported_Functions 218 | * @{ 219 | */ 220 | /** @addtogroup HAL_Exported_Functions_Group1 221 | * @{ 222 | */ 223 | /* Initialization and Configuration functions ******************************/ 224 | HAL_StatusTypeDef HAL_Init(void); 225 | HAL_StatusTypeDef HAL_DeInit(void); 226 | void HAL_MspInit(void); 227 | void HAL_MspDeInit(void); 228 | HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority); 229 | /** 230 | * @} 231 | */ 232 | 233 | /** @addtogroup HAL_Exported_Functions_Group2 234 | * @{ 235 | */ 236 | /* Peripheral Control functions ************************************************/ 237 | void HAL_IncTick(void); 238 | void HAL_Delay(uint32_t Delay); 239 | uint32_t HAL_GetTick(void); 240 | uint32_t HAL_GetTickPrio(void); 241 | HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq); 242 | HAL_TickFreqTypeDef HAL_GetTickFreq(void); 243 | void HAL_SuspendTick(void); 244 | void HAL_ResumeTick(void); 245 | uint32_t HAL_GetHalVersion(void); 246 | uint32_t HAL_GetREVID(void); 247 | uint32_t HAL_GetDEVID(void); 248 | void HAL_DBGMCU_EnableDBGSleepMode(void); 249 | void HAL_DBGMCU_DisableDBGSleepMode(void); 250 | void HAL_DBGMCU_EnableDBGStopMode(void); 251 | void HAL_DBGMCU_DisableDBGStopMode(void); 252 | void HAL_DBGMCU_EnableDBGStandbyMode(void); 253 | void HAL_DBGMCU_DisableDBGStandbyMode(void); 254 | void HAL_EnableCompensationCell(void); 255 | void HAL_DisableCompensationCell(void); 256 | void HAL_GetUID(uint32_t *UID); 257 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\ 258 | defined(STM32F469xx) || defined(STM32F479xx) 259 | void HAL_EnableMemorySwappingBank(void); 260 | void HAL_DisableMemorySwappingBank(void); 261 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ 262 | /** 263 | * @} 264 | */ 265 | 266 | /** 267 | * @} 268 | */ 269 | /* Private types -------------------------------------------------------------*/ 270 | /* Private variables ---------------------------------------------------------*/ 271 | /** @defgroup HAL_Private_Variables HAL Private Variables 272 | * @{ 273 | */ 274 | /** 275 | * @} 276 | */ 277 | /* Private constants ---------------------------------------------------------*/ 278 | /** @defgroup HAL_Private_Constants HAL Private Constants 279 | * @{ 280 | */ 281 | /** 282 | * @} 283 | */ 284 | /* Private macros ------------------------------------------------------------*/ 285 | /* Private functions ---------------------------------------------------------*/ 286 | /** 287 | * @} 288 | */ 289 | 290 | /** 291 | * @} 292 | */ 293 | 294 | #ifdef __cplusplus 295 | } 296 | #endif 297 | 298 | #endif /* __STM32F4xx_HAL_H */ 299 | 300 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 301 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© COPYRIGHT(c) 2017 STMicroelectronics

11 | * 12 | * Redistribution and use in source and binary forms, with or without modification, 13 | * are permitted provided that the following conditions are met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | ****************************************************************************** 35 | */ 36 | 37 | /* Define to prevent recursive inclusion -------------------------------------*/ 38 | #ifndef __STM32F4xx_HAL_DEF 39 | #define __STM32F4xx_HAL_DEF 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* Includes ------------------------------------------------------------------*/ 46 | #include "stm32f4xx.h" 47 | #include "Legacy/stm32_hal_legacy.h" 48 | #include 49 | 50 | /* Exported types ------------------------------------------------------------*/ 51 | 52 | /** 53 | * @brief HAL Status structures definition 54 | */ 55 | typedef enum 56 | { 57 | HAL_OK = 0x00U, 58 | HAL_ERROR = 0x01U, 59 | HAL_BUSY = 0x02U, 60 | HAL_TIMEOUT = 0x03U 61 | } HAL_StatusTypeDef; 62 | 63 | /** 64 | * @brief HAL Lock structures definition 65 | */ 66 | typedef enum 67 | { 68 | HAL_UNLOCKED = 0x00U, 69 | HAL_LOCKED = 0x01U 70 | } HAL_LockTypeDef; 71 | 72 | /* Exported macro ------------------------------------------------------------*/ 73 | 74 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 75 | 76 | #define HAL_MAX_DELAY 0xFFFFFFFFU 77 | 78 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != RESET) 79 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET) 80 | 81 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 82 | do{ \ 83 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 84 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 85 | } while(0U) 86 | 87 | /** @brief Reset the Handle's State field. 88 | * @param __HANDLE__ specifies the Peripheral Handle. 89 | * @note This macro can be used for the following purpose: 90 | * - When the Handle is declared as local variable; before passing it as parameter 91 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 92 | * to set to 0 the Handle's "State" field. 93 | * Otherwise, "State" field may have any random value and the first time the function 94 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 95 | * (i.e. HAL_PPP_MspInit() will not be executed). 96 | * - When there is a need to reconfigure the low level hardware: instead of calling 97 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 98 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 99 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 100 | * @retval None 101 | */ 102 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 103 | 104 | #if (USE_RTOS == 1U) 105 | /* Reserved for future use */ 106 | #error "USE_RTOS should be 0 in the current HAL release" 107 | #else 108 | #define __HAL_LOCK(__HANDLE__) \ 109 | do{ \ 110 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 111 | { \ 112 | return HAL_BUSY; \ 113 | } \ 114 | else \ 115 | { \ 116 | (__HANDLE__)->Lock = HAL_LOCKED; \ 117 | } \ 118 | }while (0U) 119 | 120 | #define __HAL_UNLOCK(__HANDLE__) \ 121 | do{ \ 122 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 123 | }while (0U) 124 | #endif /* USE_RTOS */ 125 | 126 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 127 | #ifndef __weak 128 | #define __weak __attribute__((weak)) 129 | #endif /* __weak */ 130 | #ifndef __packed 131 | #define __packed __attribute__((__packed__)) 132 | #endif /* __packed */ 133 | #endif /* __GNUC__ */ 134 | 135 | 136 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 137 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 138 | #ifndef __ALIGN_END 139 | #define __ALIGN_END __attribute__ ((aligned (4))) 140 | #endif /* __ALIGN_END */ 141 | #ifndef __ALIGN_BEGIN 142 | #define __ALIGN_BEGIN 143 | #endif /* __ALIGN_BEGIN */ 144 | #else 145 | #ifndef __ALIGN_END 146 | #define __ALIGN_END 147 | #endif /* __ALIGN_END */ 148 | #ifndef __ALIGN_BEGIN 149 | #if defined (__CC_ARM) /* ARM Compiler */ 150 | #define __ALIGN_BEGIN __align(4) 151 | #elif defined (__ICCARM__) /* IAR Compiler */ 152 | #define __ALIGN_BEGIN 153 | #endif /* __CC_ARM */ 154 | #endif /* __ALIGN_BEGIN */ 155 | #endif /* __GNUC__ */ 156 | 157 | 158 | /** 159 | * @brief __RAM_FUNC definition 160 | */ 161 | #if defined ( __CC_ARM ) 162 | /* ARM Compiler 163 | ------------ 164 | RAM functions are defined using the toolchain options. 165 | Functions that are executed in RAM should reside in a separate source module. 166 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 167 | area of a module to a memory space in physical RAM. 168 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 169 | dialog. 170 | */ 171 | #define __RAM_FUNC 172 | 173 | #elif defined ( __ICCARM__ ) 174 | /* ICCARM Compiler 175 | --------------- 176 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 177 | */ 178 | #define __RAM_FUNC __ramfunc 179 | 180 | #elif defined ( __GNUC__ ) 181 | /* GNU Compiler 182 | ------------ 183 | RAM functions are defined using a specific toolchain attribute 184 | "__attribute__((section(".RamFunc")))". 185 | */ 186 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 187 | 188 | #endif 189 | 190 | /** 191 | * @brief __NOINLINE definition 192 | */ 193 | #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 194 | /* ARM & GNUCompiler 195 | ---------------- 196 | */ 197 | #define __NOINLINE __attribute__ ( (noinline) ) 198 | 199 | #elif defined ( __ICCARM__ ) 200 | /* ICCARM Compiler 201 | --------------- 202 | */ 203 | #define __NOINLINE _Pragma("optimize = no_inline") 204 | 205 | #endif 206 | 207 | #ifdef __cplusplus 208 | } 209 | #endif 210 | 211 | #endif /* ___STM32F4xx_HAL_DEF */ 212 | 213 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 214 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F4xx_HAL_DMA_EX_H 38 | #define __STM32F4xx_HAL_DMA_EX_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Includes ------------------------------------------------------------------*/ 45 | #include "stm32f4xx_hal_def.h" 46 | 47 | /** @addtogroup STM32F4xx_HAL_Driver 48 | * @{ 49 | */ 50 | 51 | /** @addtogroup DMAEx 52 | * @{ 53 | */ 54 | 55 | /* Exported types ------------------------------------------------------------*/ 56 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 57 | * @brief DMAEx Exported types 58 | * @{ 59 | */ 60 | 61 | /** 62 | * @brief HAL DMA Memory definition 63 | */ 64 | typedef enum 65 | { 66 | MEMORY0 = 0x00U, /*!< Memory 0 */ 67 | MEMORY1 = 0x01U /*!< Memory 1 */ 68 | }HAL_DMA_MemoryTypeDef; 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /* Exported functions --------------------------------------------------------*/ 75 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 76 | * @brief DMAEx Exported functions 77 | * @{ 78 | */ 79 | 80 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 81 | * @brief Extended features functions 82 | * @{ 83 | */ 84 | 85 | /* IO operation functions *******************************************************/ 86 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 87 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 88 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 89 | 90 | /** 91 | * @} 92 | */ 93 | /** 94 | * @} 95 | */ 96 | 97 | /* Private functions ---------------------------------------------------------*/ 98 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 99 | * @brief DMAEx Private functions 100 | * @{ 101 | */ 102 | /** 103 | * @} 104 | */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** 111 | * @} 112 | */ 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 119 | 120 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 121 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 38 | #define __STM32F4xx_FLASH_RAMFUNC_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 44 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f4xx_hal_def.h" 48 | 49 | /** @addtogroup STM32F4xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup FLASH_RAMFUNC 54 | * @{ 55 | */ 56 | 57 | /* Exported types ------------------------------------------------------------*/ 58 | /* Exported macro ------------------------------------------------------------*/ 59 | /* Exported functions --------------------------------------------------------*/ 60 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 61 | * @{ 62 | */ 63 | 64 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 65 | * @{ 66 | */ 67 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 68 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 69 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 70 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | 93 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 94 | 95 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 96 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_gpio.h 4 | * @author MCD Application Team 5 | * @brief Header file of GPIO HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F4xx_HAL_GPIO_H 38 | #define __STM32F4xx_HAL_GPIO_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Includes ------------------------------------------------------------------*/ 45 | #include "stm32f4xx_hal_def.h" 46 | 47 | /** @addtogroup STM32F4xx_HAL_Driver 48 | * @{ 49 | */ 50 | 51 | /** @addtogroup GPIO 52 | * @{ 53 | */ 54 | 55 | /* Exported types ------------------------------------------------------------*/ 56 | /** @defgroup GPIO_Exported_Types GPIO Exported Types 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @brief GPIO Init structure definition 62 | */ 63 | typedef struct 64 | { 65 | uint32_t Pin; /*!< Specifies the GPIO pins to be configured. 66 | This parameter can be any value of @ref GPIO_pins_define */ 67 | 68 | uint32_t Mode; /*!< Specifies the operating mode for the selected pins. 69 | This parameter can be a value of @ref GPIO_mode_define */ 70 | 71 | uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins. 72 | This parameter can be a value of @ref GPIO_pull_define */ 73 | 74 | uint32_t Speed; /*!< Specifies the speed for the selected pins. 75 | This parameter can be a value of @ref GPIO_speed_define */ 76 | 77 | uint32_t Alternate; /*!< Peripheral to be connected to the selected pins. 78 | This parameter can be a value of @ref GPIO_Alternate_function_selection */ 79 | }GPIO_InitTypeDef; 80 | 81 | /** 82 | * @brief GPIO Bit SET and Bit RESET enumeration 83 | */ 84 | typedef enum 85 | { 86 | GPIO_PIN_RESET = 0, 87 | GPIO_PIN_SET 88 | }GPIO_PinState; 89 | /** 90 | * @} 91 | */ 92 | 93 | /* Exported constants --------------------------------------------------------*/ 94 | 95 | /** @defgroup GPIO_Exported_Constants GPIO Exported Constants 96 | * @{ 97 | */ 98 | 99 | /** @defgroup GPIO_pins_define GPIO pins define 100 | * @{ 101 | */ 102 | #define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */ 103 | #define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */ 104 | #define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */ 105 | #define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */ 106 | #define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */ 107 | #define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */ 108 | #define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */ 109 | #define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */ 110 | #define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */ 111 | #define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */ 112 | #define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */ 113 | #define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */ 114 | #define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */ 115 | #define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */ 116 | #define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */ 117 | #define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */ 118 | #define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */ 119 | 120 | #define GPIO_PIN_MASK 0x0000FFFFU /* PIN mask for assert test */ 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup GPIO_mode_define GPIO mode define 126 | * @brief GPIO Configuration Mode 127 | * Elements values convention: 0xX0yz00YZ 128 | * - X : GPIO mode or EXTI Mode 129 | * - y : External IT or Event trigger detection 130 | * - z : IO configuration on External IT or Event 131 | * - Y : Output type (Push Pull or Open Drain) 132 | * - Z : IO Direction mode (Input, Output, Alternate or Analog) 133 | * @{ 134 | */ 135 | #define GPIO_MODE_INPUT 0x00000000U /*!< Input Floating Mode */ 136 | #define GPIO_MODE_OUTPUT_PP 0x00000001U /*!< Output Push Pull Mode */ 137 | #define GPIO_MODE_OUTPUT_OD 0x00000011U /*!< Output Open Drain Mode */ 138 | #define GPIO_MODE_AF_PP 0x00000002U /*!< Alternate Function Push Pull Mode */ 139 | #define GPIO_MODE_AF_OD 0x00000012U /*!< Alternate Function Open Drain Mode */ 140 | 141 | #define GPIO_MODE_ANALOG 0x00000003U /*!< Analog Mode */ 142 | 143 | #define GPIO_MODE_IT_RISING 0x10110000U /*!< External Interrupt Mode with Rising edge trigger detection */ 144 | #define GPIO_MODE_IT_FALLING 0x10210000U /*!< External Interrupt Mode with Falling edge trigger detection */ 145 | #define GPIO_MODE_IT_RISING_FALLING 0x10310000U /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ 146 | 147 | #define GPIO_MODE_EVT_RISING 0x10120000U /*!< External Event Mode with Rising edge trigger detection */ 148 | #define GPIO_MODE_EVT_FALLING 0x10220000U /*!< External Event Mode with Falling edge trigger detection */ 149 | #define GPIO_MODE_EVT_RISING_FALLING 0x10320000U /*!< External Event Mode with Rising/Falling edge trigger detection */ 150 | /** 151 | * @} 152 | */ 153 | 154 | /** @defgroup GPIO_speed_define GPIO speed define 155 | * @brief GPIO Output Maximum frequency 156 | * @{ 157 | */ 158 | #define GPIO_SPEED_FREQ_LOW 0x00000000U /*!< IO works at 2 MHz, please refer to the product datasheet */ 159 | #define GPIO_SPEED_FREQ_MEDIUM 0x00000001U /*!< range 12,5 MHz to 50 MHz, please refer to the product datasheet */ 160 | #define GPIO_SPEED_FREQ_HIGH 0x00000002U /*!< range 25 MHz to 100 MHz, please refer to the product datasheet */ 161 | #define GPIO_SPEED_FREQ_VERY_HIGH 0x00000003U /*!< range 50 MHz to 200 MHz, please refer to the product datasheet */ 162 | /** 163 | * @} 164 | */ 165 | 166 | /** @defgroup GPIO_pull_define GPIO pull define 167 | * @brief GPIO Pull-Up or Pull-Down Activation 168 | * @{ 169 | */ 170 | #define GPIO_NOPULL 0x00000000U /*!< No Pull-up or Pull-down activation */ 171 | #define GPIO_PULLUP 0x00000001U /*!< Pull-up activation */ 172 | #define GPIO_PULLDOWN 0x00000002U /*!< Pull-down activation */ 173 | /** 174 | * @} 175 | */ 176 | 177 | /** 178 | * @} 179 | */ 180 | 181 | /* Exported macro ------------------------------------------------------------*/ 182 | /** @defgroup GPIO_Exported_Macros GPIO Exported Macros 183 | * @{ 184 | */ 185 | 186 | /** 187 | * @brief Checks whether the specified EXTI line flag is set or not. 188 | * @param __EXTI_LINE__ specifies the EXTI line flag to check. 189 | * This parameter can be GPIO_PIN_x where x can be(0..15) 190 | * @retval The new state of __EXTI_LINE__ (SET or RESET). 191 | */ 192 | #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__)) 193 | 194 | /** 195 | * @brief Clears the EXTI's line pending flags. 196 | * @param __EXTI_LINE__ specifies the EXTI lines flags to clear. 197 | * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 198 | * @retval None 199 | */ 200 | #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__)) 201 | 202 | /** 203 | * @brief Checks whether the specified EXTI line is asserted or not. 204 | * @param __EXTI_LINE__ specifies the EXTI line to check. 205 | * This parameter can be GPIO_PIN_x where x can be(0..15) 206 | * @retval The new state of __EXTI_LINE__ (SET or RESET). 207 | */ 208 | #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__)) 209 | 210 | /** 211 | * @brief Clears the EXTI's line pending bits. 212 | * @param __EXTI_LINE__ specifies the EXTI lines to clear. 213 | * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 214 | * @retval None 215 | */ 216 | #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__)) 217 | 218 | /** 219 | * @brief Generates a Software interrupt on selected EXTI line. 220 | * @param __EXTI_LINE__ specifies the EXTI line to check. 221 | * This parameter can be GPIO_PIN_x where x can be(0..15) 222 | * @retval None 223 | */ 224 | #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__)) 225 | /** 226 | * @} 227 | */ 228 | 229 | /* Include GPIO HAL Extension module */ 230 | #include "stm32f4xx_hal_gpio_ex.h" 231 | 232 | /* Exported functions --------------------------------------------------------*/ 233 | /** @addtogroup GPIO_Exported_Functions 234 | * @{ 235 | */ 236 | 237 | /** @addtogroup GPIO_Exported_Functions_Group1 238 | * @{ 239 | */ 240 | /* Initialization and de-initialization functions *****************************/ 241 | void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init); 242 | void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 243 | /** 244 | * @} 245 | */ 246 | 247 | /** @addtogroup GPIO_Exported_Functions_Group2 248 | * @{ 249 | */ 250 | /* IO operation functions *****************************************************/ 251 | GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 252 | void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState); 253 | void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 254 | HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 255 | void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin); 256 | void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); 257 | 258 | /** 259 | * @} 260 | */ 261 | 262 | /** 263 | * @} 264 | */ 265 | /* Private types -------------------------------------------------------------*/ 266 | /* Private variables ---------------------------------------------------------*/ 267 | /* Private constants ---------------------------------------------------------*/ 268 | /** @defgroup GPIO_Private_Constants GPIO Private Constants 269 | * @{ 270 | */ 271 | 272 | /** 273 | * @} 274 | */ 275 | 276 | /* Private macros ------------------------------------------------------------*/ 277 | /** @defgroup GPIO_Private_Macros GPIO Private Macros 278 | * @{ 279 | */ 280 | #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET)) 281 | #define IS_GPIO_PIN(PIN) ((((PIN) & GPIO_PIN_MASK ) != 0x00U) && (((PIN) & ~GPIO_PIN_MASK) == 0x00U)) 282 | #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT) ||\ 283 | ((MODE) == GPIO_MODE_OUTPUT_PP) ||\ 284 | ((MODE) == GPIO_MODE_OUTPUT_OD) ||\ 285 | ((MODE) == GPIO_MODE_AF_PP) ||\ 286 | ((MODE) == GPIO_MODE_AF_OD) ||\ 287 | ((MODE) == GPIO_MODE_IT_RISING) ||\ 288 | ((MODE) == GPIO_MODE_IT_FALLING) ||\ 289 | ((MODE) == GPIO_MODE_IT_RISING_FALLING) ||\ 290 | ((MODE) == GPIO_MODE_EVT_RISING) ||\ 291 | ((MODE) == GPIO_MODE_EVT_FALLING) ||\ 292 | ((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\ 293 | ((MODE) == GPIO_MODE_ANALOG)) 294 | #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_FREQ_LOW) || ((SPEED) == GPIO_SPEED_FREQ_MEDIUM) || \ 295 | ((SPEED) == GPIO_SPEED_FREQ_HIGH) || ((SPEED) == GPIO_SPEED_FREQ_VERY_HIGH)) 296 | #define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \ 297 | ((PULL) == GPIO_PULLDOWN)) 298 | /** 299 | * @} 300 | */ 301 | 302 | /* Private functions ---------------------------------------------------------*/ 303 | /** @defgroup GPIO_Private_Functions GPIO Private Functions 304 | * @{ 305 | */ 306 | 307 | /** 308 | * @} 309 | */ 310 | 311 | /** 312 | * @} 313 | */ 314 | 315 | /** 316 | * @} 317 | */ 318 | 319 | #ifdef __cplusplus 320 | } 321 | #endif 322 | 323 | #endif /* __STM32F4xx_HAL_GPIO_H */ 324 | 325 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 326 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_i2c_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of I2C HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F4xx_HAL_I2C_EX_H 38 | #define __STM32F4xx_HAL_I2C_EX_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ 45 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) ||\ 46 | defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx) 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "stm32f4xx_hal_def.h" 49 | 50 | /** @addtogroup STM32F4xx_HAL_Driver 51 | * @{ 52 | */ 53 | 54 | /** @addtogroup I2CEx 55 | * @{ 56 | */ 57 | 58 | /* Exported types ------------------------------------------------------------*/ 59 | /* Exported constants --------------------------------------------------------*/ 60 | /** @defgroup I2CEx_Exported_Constants I2C Exported Constants 61 | * @{ 62 | */ 63 | 64 | /** @defgroup I2CEx_Analog_Filter I2C Analog Filter 65 | * @{ 66 | */ 67 | #define I2C_ANALOGFILTER_ENABLE 0x00000000U 68 | #define I2C_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /* Exported macro ------------------------------------------------------------*/ 78 | /* Exported functions --------------------------------------------------------*/ 79 | /** @addtogroup I2CEx_Exported_Functions 80 | * @{ 81 | */ 82 | 83 | /** @addtogroup I2CEx_Exported_Functions_Group1 84 | * @{ 85 | */ 86 | /* Peripheral Control functions ************************************************/ 87 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter); 88 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter); 89 | /** 90 | * @} 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | /* Private types -------------------------------------------------------------*/ 97 | /* Private variables ---------------------------------------------------------*/ 98 | /* Private constants ---------------------------------------------------------*/ 99 | /** @defgroup I2CEx_Private_Constants I2C Private Constants 100 | * @{ 101 | */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /* Private macros ------------------------------------------------------------*/ 108 | /** @defgroup I2CEx_Private_Macros I2C Private Macros 109 | * @{ 110 | */ 111 | #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ 112 | ((FILTER) == I2C_ANALOGFILTER_DISABLE)) 113 | #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU) 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** 123 | * @} 124 | */ 125 | 126 | #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC ||\ 127 | STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx ||\ 128 | STM32F413xx || STM32F423xx */ 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | 134 | #endif /* __STM32F4xx_HAL_I2C_EX_H */ 135 | 136 | 137 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 138 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.c 4 | * @author MCD Application Team 5 | * @brief DMA Extension HAL module driver 6 | * This file provides firmware functions to manage the following 7 | * functionalities of the DMA Extension peripheral: 8 | * + Extended features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### How to use this driver ##### 13 | ============================================================================== 14 | [..] 15 | The DMA Extension HAL driver can be used as follows: 16 | (#) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function 17 | for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode. 18 | 19 | -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed. 20 | -@- When Multi (Double) Buffer mode is enabled the, transfer is circular by default. 21 | -@- In Multi (Double) buffer mode, it is possible to update the base address for 22 | the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled. 23 | 24 | @endverbatim 25 | ****************************************************************************** 26 | * @attention 27 | * 28 | *

© COPYRIGHT(c) 2017 STMicroelectronics

29 | * 30 | * Redistribution and use in source and binary forms, with or without modification, 31 | * are permitted provided that the following conditions are met: 32 | * 1. Redistributions of source code must retain the above copyright notice, 33 | * this list of conditions and the following disclaimer. 34 | * 2. Redistributions in binary form must reproduce the above copyright notice, 35 | * this list of conditions and the following disclaimer in the documentation 36 | * and/or other materials provided with the distribution. 37 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 38 | * may be used to endorse or promote products derived from this software 39 | * without specific prior written permission. 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 42 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 47 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 48 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 49 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 | * 52 | ****************************************************************************** 53 | */ 54 | 55 | /* Includes ------------------------------------------------------------------*/ 56 | #include "stm32f4xx_hal.h" 57 | 58 | /** @addtogroup STM32F4xx_HAL_Driver 59 | * @{ 60 | */ 61 | 62 | /** @defgroup DMAEx DMAEx 63 | * @brief DMA Extended HAL module driver 64 | * @{ 65 | */ 66 | 67 | #ifdef HAL_DMA_MODULE_ENABLED 68 | 69 | /* Private types -------------------------------------------------------------*/ 70 | /* Private variables ---------------------------------------------------------*/ 71 | /* Private Constants ---------------------------------------------------------*/ 72 | /* Private macros ------------------------------------------------------------*/ 73 | /* Private functions ---------------------------------------------------------*/ 74 | /** @addtogroup DMAEx_Private_Functions 75 | * @{ 76 | */ 77 | static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); 78 | /** 79 | * @} 80 | */ 81 | 82 | /* Exported functions ---------------------------------------------------------*/ 83 | 84 | /** @addtogroup DMAEx_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | 89 | /** @addtogroup DMAEx_Exported_Functions_Group1 90 | * 91 | @verbatim 92 | =============================================================================== 93 | ##### Extended features functions ##### 94 | =============================================================================== 95 | [..] This section provides functions allowing to: 96 | (+) Configure the source, destination address and data length and 97 | Start MultiBuffer DMA transfer 98 | (+) Configure the source, destination address and data length and 99 | Start MultiBuffer DMA transfer with interrupt 100 | (+) Change on the fly the memory0 or memory1 address. 101 | 102 | @endverbatim 103 | * @{ 104 | */ 105 | 106 | 107 | /** 108 | * @brief Starts the multi_buffer DMA Transfer. 109 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 110 | * the configuration information for the specified DMA Stream. 111 | * @param SrcAddress The source memory Buffer address 112 | * @param DstAddress The destination memory Buffer address 113 | * @param SecondMemAddress The second memory Buffer address in case of multi buffer Transfer 114 | * @param DataLength The length of data to be transferred from source to destination 115 | * @retval HAL status 116 | */ 117 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) 118 | { 119 | HAL_StatusTypeDef status = HAL_OK; 120 | 121 | /* Check the parameters */ 122 | assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 123 | 124 | /* Memory-to-memory transfer not supported in double buffering mode */ 125 | if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY) 126 | { 127 | hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED; 128 | status = HAL_ERROR; 129 | } 130 | else 131 | { 132 | /* Process Locked */ 133 | __HAL_LOCK(hdma); 134 | 135 | if(HAL_DMA_STATE_READY == hdma->State) 136 | { 137 | /* Change DMA peripheral state */ 138 | hdma->State = HAL_DMA_STATE_BUSY; 139 | 140 | /* Enable the double buffer mode */ 141 | hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; 142 | 143 | /* Configure DMA Stream destination address */ 144 | hdma->Instance->M1AR = SecondMemAddress; 145 | 146 | /* Configure the source, destination address and the data length */ 147 | DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); 148 | 149 | /* Enable the peripheral */ 150 | __HAL_DMA_ENABLE(hdma); 151 | } 152 | else 153 | { 154 | /* Return error status */ 155 | status = HAL_BUSY; 156 | } 157 | } 158 | return status; 159 | } 160 | 161 | /** 162 | * @brief Starts the multi_buffer DMA Transfer with interrupt enabled. 163 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 164 | * the configuration information for the specified DMA Stream. 165 | * @param SrcAddress The source memory Buffer address 166 | * @param DstAddress The destination memory Buffer address 167 | * @param SecondMemAddress The second memory Buffer address in case of multi buffer Transfer 168 | * @param DataLength The length of data to be transferred from source to destination 169 | * @retval HAL status 170 | */ 171 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) 172 | { 173 | HAL_StatusTypeDef status = HAL_OK; 174 | 175 | /* Check the parameters */ 176 | assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 177 | 178 | /* Memory-to-memory transfer not supported in double buffering mode */ 179 | if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY) 180 | { 181 | hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED; 182 | return HAL_ERROR; 183 | } 184 | 185 | /* Check callback functions */ 186 | if ((NULL == hdma->XferCpltCallback) || (NULL == hdma->XferM1CpltCallback) || (NULL == hdma->XferErrorCallback)) 187 | { 188 | hdma->ErrorCode = HAL_DMA_ERROR_PARAM; 189 | return HAL_ERROR; 190 | } 191 | 192 | /* Process locked */ 193 | __HAL_LOCK(hdma); 194 | 195 | if(HAL_DMA_STATE_READY == hdma->State) 196 | { 197 | /* Change DMA peripheral state */ 198 | hdma->State = HAL_DMA_STATE_BUSY; 199 | 200 | /* Initialize the error code */ 201 | hdma->ErrorCode = HAL_DMA_ERROR_NONE; 202 | 203 | /* Enable the Double buffer mode */ 204 | hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; 205 | 206 | /* Configure DMA Stream destination address */ 207 | hdma->Instance->M1AR = SecondMemAddress; 208 | 209 | /* Configure the source, destination address and the data length */ 210 | DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); 211 | 212 | /* Clear all flags */ 213 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); 214 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); 215 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); 216 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)); 217 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)); 218 | 219 | /* Enable Common interrupts*/ 220 | hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME; 221 | hdma->Instance->FCR |= DMA_IT_FE; 222 | 223 | if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL)) 224 | { 225 | hdma->Instance->CR |= DMA_IT_HT; 226 | } 227 | 228 | /* Enable the peripheral */ 229 | __HAL_DMA_ENABLE(hdma); 230 | } 231 | else 232 | { 233 | /* Process unlocked */ 234 | __HAL_UNLOCK(hdma); 235 | 236 | /* Return error status */ 237 | status = HAL_BUSY; 238 | } 239 | return status; 240 | } 241 | 242 | /** 243 | * @brief Change the memory0 or memory1 address on the fly. 244 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 245 | * the configuration information for the specified DMA Stream. 246 | * @param Address The new address 247 | * @param memory the memory to be changed, This parameter can be one of 248 | * the following values: 249 | * MEMORY0 / 250 | * MEMORY1 251 | * @note The MEMORY0 address can be changed only when the current transfer use 252 | * MEMORY1 and the MEMORY1 address can be changed only when the current 253 | * transfer use MEMORY0. 254 | * @retval HAL status 255 | */ 256 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory) 257 | { 258 | if(memory == MEMORY0) 259 | { 260 | /* change the memory0 address */ 261 | hdma->Instance->M0AR = Address; 262 | } 263 | else 264 | { 265 | /* change the memory1 address */ 266 | hdma->Instance->M1AR = Address; 267 | } 268 | 269 | return HAL_OK; 270 | } 271 | 272 | /** 273 | * @} 274 | */ 275 | 276 | /** 277 | * @} 278 | */ 279 | 280 | /** @addtogroup DMAEx_Private_Functions 281 | * @{ 282 | */ 283 | 284 | /** 285 | * @brief Set the DMA Transfer parameter. 286 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 287 | * the configuration information for the specified DMA Stream. 288 | * @param SrcAddress The source memory Buffer address 289 | * @param DstAddress The destination memory Buffer address 290 | * @param DataLength The length of data to be transferred from source to destination 291 | * @retval HAL status 292 | */ 293 | static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) 294 | { 295 | /* Configure DMA Stream data length */ 296 | hdma->Instance->NDTR = DataLength; 297 | 298 | /* Peripheral to Memory */ 299 | if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) 300 | { 301 | /* Configure DMA Stream destination address */ 302 | hdma->Instance->PAR = DstAddress; 303 | 304 | /* Configure DMA Stream source address */ 305 | hdma->Instance->M0AR = SrcAddress; 306 | } 307 | /* Memory to Peripheral */ 308 | else 309 | { 310 | /* Configure DMA Stream source address */ 311 | hdma->Instance->PAR = SrcAddress; 312 | 313 | /* Configure DMA Stream destination address */ 314 | hdma->Instance->M0AR = DstAddress; 315 | } 316 | } 317 | 318 | /** 319 | * @} 320 | */ 321 | 322 | #endif /* HAL_DMA_MODULE_ENABLED */ 323 | /** 324 | * @} 325 | */ 326 | 327 | /** 328 | * @} 329 | */ 330 | 331 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 332 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @brief FLASH RAMFUNC module driver. 6 | * This file provides a FLASH firmware functions which should be 7 | * executed from internal SRAM 8 | * + Stop/Start the flash interface while System Run 9 | * + Enable/Disable the flash sleep while System Run 10 | @verbatim 11 | ============================================================================== 12 | ##### APIs executed from Internal RAM ##### 13 | ============================================================================== 14 | [..] 15 | *** ARM Compiler *** 16 | -------------------- 17 | [..] RAM functions are defined using the toolchain options. 18 | Functions that are be executed in RAM should reside in a separate 19 | source module. Using the 'Options for File' dialog you can simply change 20 | the 'Code / Const' area of a module to a memory space in physical RAM. 21 | Available memory areas are declared in the 'Target' tab of the 22 | Options for Target' dialog. 23 | 24 | *** ICCARM Compiler *** 25 | ----------------------- 26 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 27 | 28 | *** GNU Compiler *** 29 | -------------------- 30 | [..] RAM functions are defined using a specific toolchain attribute 31 | "__attribute__((section(".RamFunc")))". 32 | 33 | @endverbatim 34 | ****************************************************************************** 35 | * @attention 36 | * 37 | *

© COPYRIGHT(c) 2017 STMicroelectronics

38 | * 39 | * Redistribution and use in source and binary forms, with or without modification, 40 | * are permitted provided that the following conditions are met: 41 | * 1. Redistributions of source code must retain the above copyright notice, 42 | * this list of conditions and the following disclaimer. 43 | * 2. Redistributions in binary form must reproduce the above copyright notice, 44 | * this list of conditions and the following disclaimer in the documentation 45 | * and/or other materials provided with the distribution. 46 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 47 | * may be used to endorse or promote products derived from this software 48 | * without specific prior written permission. 49 | * 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 51 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 53 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 56 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 57 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 58 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | * 61 | ****************************************************************************** 62 | */ 63 | 64 | /* Includes ------------------------------------------------------------------*/ 65 | #include "stm32f4xx_hal.h" 66 | 67 | /** @addtogroup STM32F4xx_HAL_Driver 68 | * @{ 69 | */ 70 | 71 | /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC 72 | * @brief FLASH functions executed from RAM 73 | * @{ 74 | */ 75 | #ifdef HAL_FLASH_MODULE_ENABLED 76 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ 77 | defined(STM32F412Rx) || defined(STM32F412Cx) 78 | 79 | /* Private typedef -----------------------------------------------------------*/ 80 | /* Private define ------------------------------------------------------------*/ 81 | /* Private macro -------------------------------------------------------------*/ 82 | /* Private variables ---------------------------------------------------------*/ 83 | /* Private function prototypes -----------------------------------------------*/ 84 | /* Exported functions --------------------------------------------------------*/ 85 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions 86 | * @{ 87 | */ 88 | 89 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM 90 | * @brief Peripheral Extended features functions 91 | * 92 | @verbatim 93 | 94 | =============================================================================== 95 | ##### ramfunc functions ##### 96 | =============================================================================== 97 | [..] 98 | This subsection provides a set of functions that should be executed from RAM 99 | transfers. 100 | 101 | @endverbatim 102 | * @{ 103 | */ 104 | 105 | /** 106 | * @brief Stop the flash interface while System Run 107 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 108 | * @note This mode couldn't be set while executing with the flash itself. 109 | * It should be done with specific routine executed from RAM. 110 | * @retval HAL status 111 | */ 112 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void) 113 | { 114 | /* Enable Power ctrl clock */ 115 | __HAL_RCC_PWR_CLK_ENABLE(); 116 | /* Stop the flash interface while System Run */ 117 | SET_BIT(PWR->CR, PWR_CR_FISSR); 118 | 119 | return HAL_OK; 120 | } 121 | 122 | /** 123 | * @brief Start the flash interface while System Run 124 | * @note This mode is only available for STM32F411xx/STM32F446xx devices. 125 | * @note This mode couldn't be set while executing with the flash itself. 126 | * It should be done with specific routine executed from RAM. 127 | * @retval HAL status 128 | */ 129 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void) 130 | { 131 | /* Enable Power ctrl clock */ 132 | __HAL_RCC_PWR_CLK_ENABLE(); 133 | /* Start the flash interface while System Run */ 134 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR); 135 | 136 | return HAL_OK; 137 | } 138 | 139 | /** 140 | * @brief Enable the flash sleep while System Run 141 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 142 | * @note This mode could n't be set while executing with the flash itself. 143 | * It should be done with specific routine executed from RAM. 144 | * @retval HAL status 145 | */ 146 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void) 147 | { 148 | /* Enable Power ctrl clock */ 149 | __HAL_RCC_PWR_CLK_ENABLE(); 150 | /* Enable the flash sleep while System Run */ 151 | SET_BIT(PWR->CR, PWR_CR_FMSSR); 152 | 153 | return HAL_OK; 154 | } 155 | 156 | /** 157 | * @brief Disable the flash sleep while System Run 158 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 159 | * @note This mode couldn't be set while executing with the flash itself. 160 | * It should be done with specific routine executed from RAM. 161 | * @retval HAL status 162 | */ 163 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void) 164 | { 165 | /* Enable Power ctrl clock */ 166 | __HAL_RCC_PWR_CLK_ENABLE(); 167 | /* Disable the flash sleep while System Run */ 168 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR); 169 | 170 | return HAL_OK; 171 | } 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | /** 178 | * @} 179 | */ 180 | 181 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 182 | #endif /* HAL_FLASH_MODULE_ENABLED */ 183 | /** 184 | * @} 185 | */ 186 | 187 | /** 188 | * @} 189 | */ 190 | 191 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 192 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_i2c_ex.c 4 | * @author MCD Application Team 5 | * @brief I2C Extension HAL module driver. 6 | * This file provides firmware functions to manage the following 7 | * functionalities of I2C extension peripheral: 8 | * + Extension features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### I2C peripheral extension features ##### 13 | ============================================================================== 14 | 15 | [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/ 16 | 429xx/439xx devices contains the following additional features : 17 | 18 | (+) Possibility to disable or enable Analog Noise Filter 19 | (+) Use of a configured Digital Noise Filter 20 | 21 | ##### How to use this driver ##### 22 | ============================================================================== 23 | [..] This driver provides functions to configure Noise Filter 24 | (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config() 25 | (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config() 26 | 27 | @endverbatim 28 | ****************************************************************************** 29 | * @attention 30 | * 31 | *

© COPYRIGHT(c) 2017 STMicroelectronics

32 | * 33 | * Redistribution and use in source and binary forms, with or without modification, 34 | * are permitted provided that the following conditions are met: 35 | * 1. Redistributions of source code must retain the above copyright notice, 36 | * this list of conditions and the following disclaimer. 37 | * 2. Redistributions in binary form must reproduce the above copyright notice, 38 | * this list of conditions and the following disclaimer in the documentation 39 | * and/or other materials provided with the distribution. 40 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 41 | * may be used to endorse or promote products derived from this software 42 | * without specific prior written permission. 43 | * 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 45 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 47 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 48 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 50 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 51 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 52 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 | * 55 | ****************************************************************************** 56 | */ 57 | 58 | /* Includes ------------------------------------------------------------------*/ 59 | #include "stm32f4xx_hal.h" 60 | 61 | /** @addtogroup STM32F4xx_HAL_Driver 62 | * @{ 63 | */ 64 | 65 | /** @defgroup I2CEx I2CEx 66 | * @brief I2C HAL module driver 67 | * @{ 68 | */ 69 | 70 | #ifdef HAL_I2C_MODULE_ENABLED 71 | 72 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ 73 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) ||\ 74 | defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx) 75 | /* Private typedef -----------------------------------------------------------*/ 76 | /* Private define ------------------------------------------------------------*/ 77 | /* Private macro -------------------------------------------------------------*/ 78 | /* Private variables ---------------------------------------------------------*/ 79 | /* Private function prototypes -----------------------------------------------*/ 80 | /* Exported functions --------------------------------------------------------*/ 81 | /** @defgroup I2CEx_Exported_Functions I2C Exported Functions 82 | * @{ 83 | */ 84 | 85 | 86 | /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions 87 | * @brief Extension features functions 88 | * 89 | @verbatim 90 | =============================================================================== 91 | ##### Extension features functions ##### 92 | =============================================================================== 93 | [..] This section provides functions allowing to: 94 | (+) Configure Noise Filters 95 | 96 | @endverbatim 97 | * @{ 98 | */ 99 | 100 | /** 101 | * @brief Configures I2C Analog noise filter. 102 | * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 103 | * the configuration information for the specified I2Cx peripheral. 104 | * @param AnalogFilter new state of the Analog filter. 105 | * @retval HAL status 106 | */ 107 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) 108 | { 109 | /* Check the parameters */ 110 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 111 | assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); 112 | 113 | if(hi2c->State == HAL_I2C_STATE_READY) 114 | { 115 | hi2c->State = HAL_I2C_STATE_BUSY; 116 | 117 | /* Disable the selected I2C peripheral */ 118 | __HAL_I2C_DISABLE(hi2c); 119 | 120 | /* Reset I2Cx ANOFF bit */ 121 | hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF); 122 | 123 | /* Disable the analog filter */ 124 | hi2c->Instance->FLTR |= AnalogFilter; 125 | 126 | __HAL_I2C_ENABLE(hi2c); 127 | 128 | hi2c->State = HAL_I2C_STATE_READY; 129 | 130 | return HAL_OK; 131 | } 132 | else 133 | { 134 | return HAL_BUSY; 135 | } 136 | } 137 | 138 | /** 139 | * @brief Configures I2C Digital noise filter. 140 | * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 141 | * the configuration information for the specified I2Cx peripheral. 142 | * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F. 143 | * @retval HAL status 144 | */ 145 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 146 | { 147 | uint16_t tmpreg = 0; 148 | 149 | /* Check the parameters */ 150 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 151 | assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); 152 | 153 | if(hi2c->State == HAL_I2C_STATE_READY) 154 | { 155 | hi2c->State = HAL_I2C_STATE_BUSY; 156 | 157 | /* Disable the selected I2C peripheral */ 158 | __HAL_I2C_DISABLE(hi2c); 159 | 160 | /* Get the old register value */ 161 | tmpreg = hi2c->Instance->FLTR; 162 | 163 | /* Reset I2Cx DNF bit [3:0] */ 164 | tmpreg &= ~(I2C_FLTR_DNF); 165 | 166 | /* Set I2Cx DNF coefficient */ 167 | tmpreg |= DigitalFilter; 168 | 169 | /* Store the new register value */ 170 | hi2c->Instance->FLTR = tmpreg; 171 | 172 | __HAL_I2C_ENABLE(hi2c); 173 | 174 | hi2c->State = HAL_I2C_STATE_READY; 175 | 176 | return HAL_OK; 177 | } 178 | else 179 | { 180 | return HAL_BUSY; 181 | } 182 | } 183 | 184 | /** 185 | * @} 186 | */ 187 | 188 | /** 189 | * @} 190 | */ 191 | #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC ||\ 192 | STM32F401xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F413xx ||\ 193 | STM32F423xx */ 194 | 195 | #endif /* HAL_I2C_MODULE_ENABLED */ 196 | /** 197 | * @} 198 | */ 199 | 200 | /** 201 | * @} 202 | */ 203 | 204 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 205 | -------------------------------------------------------------------------------- /Inc/adc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : ADC.h 4 | * Description : This file provides code for the configuration 5 | * of the ADC instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __adc_H 41 | #define __adc_H 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "main.h" 48 | 49 | /* USER CODE BEGIN Includes */ 50 | 51 | /* USER CODE END Includes */ 52 | 53 | extern ADC_HandleTypeDef hadc1; 54 | 55 | /* USER CODE BEGIN Private defines */ 56 | 57 | /* USER CODE END Private defines */ 58 | 59 | void MX_ADC1_Init(void); 60 | 61 | /* USER CODE BEGIN Prototypes */ 62 | 63 | /* USER CODE END Prototypes */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | #endif /*__ adc_H */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 79 | -------------------------------------------------------------------------------- /Inc/bh1750.h: -------------------------------------------------------------------------------- 1 | /* 2 | * bh1750.h 3 | * 4 | * The MIT License. 5 | * Created on: 02.12.2018 6 | * Author: Mateusz Salamon 7 | * www.msalamon.pl 8 | * mateusz@msalamon.pl 9 | * 10 | * https://msalamon.pl/pomiar-natezenia-swiatla-z-wykorzystaniem-stm32/ 11 | * https://github.com/lamik/Light_Sensors_STM32 12 | */ 13 | 14 | #ifndef BH1750_H_ 15 | #define BH1750_H_ 16 | 17 | #define BH1750_ADDRESS (0x23<<1) 18 | 19 | #define BH1750_POWER_DOWN 0x00 20 | #define BH1750_POWER_ON 0x01 21 | #define BH1750_RESET 0x07 22 | #define BH1750_DEFAULT_MTREG 69 23 | 24 | #define BH1750_CONVERSION_FACTOR 1.2 25 | 26 | typedef enum { 27 | BH1750_OK = 0, 28 | BH1750_ERROR = 1 29 | } BH1750_STATUS; 30 | 31 | typedef enum 32 | { 33 | CONTINUOUS_HIGH_RES_MODE = 0x10, 34 | CONTINUOUS_HIGH_RES_MODE_2 = 0x11, 35 | CONTINUOUS_LOW_RES_MODE = 0x13, 36 | ONETIME_HIGH_RES_MODE = 0x20, 37 | ONETIME_HIGH_RES_MODE_2 = 0x21, 38 | ONETIME_LOW_RES_MODE = 0x23 39 | }bh1750_mode; 40 | 41 | BH1750_STATUS BH1750_Init(I2C_HandleTypeDef *hi2c); 42 | BH1750_STATUS BH1750_Reset(void); 43 | BH1750_STATUS BH1750_PowerState(uint8_t PowerOn); 44 | BH1750_STATUS BH1750_SetMtreg(uint8_t Mtreg); 45 | BH1750_STATUS BH1750_SetMode(bh1750_mode Mode); 46 | BH1750_STATUS BH1750_TriggerManualConversion(void); 47 | BH1750_STATUS BH1750_ReadLight(float *Result); 48 | 49 | #endif /* BH1750_H_ */ 50 | -------------------------------------------------------------------------------- /Inc/dma.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : dma.h 4 | * Description : This file contains all the function prototypes for 5 | * the dma.c file 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __dma_H 41 | #define __dma_H 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "main.h" 49 | 50 | /* DMA memory to memory transfer handles -------------------------------------*/ 51 | 52 | /* USER CODE BEGIN Includes */ 53 | 54 | /* USER CODE END Includes */ 55 | 56 | /* USER CODE BEGIN Private defines */ 57 | 58 | /* USER CODE END Private defines */ 59 | 60 | void MX_DMA_Init(void); 61 | 62 | /* USER CODE BEGIN Prototypes */ 63 | 64 | /* USER CODE END Prototypes */ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __dma_H */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.h 4 | * Description : This file contains all the functions prototypes for 5 | * the gpio 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Define to prevent recursive inclusion -------------------------------------*/ 41 | #ifndef __gpio_H 42 | #define __gpio_H 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "main.h" 49 | 50 | /* USER CODE BEGIN Includes */ 51 | 52 | /* USER CODE END Includes */ 53 | 54 | /* USER CODE BEGIN Private defines */ 55 | 56 | /* USER CODE END Private defines */ 57 | 58 | void MX_GPIO_Init(void); 59 | 60 | /* USER CODE BEGIN Prototypes */ 61 | 62 | /* USER CODE END Prototypes */ 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #endif /*__ pinoutConfig_H */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /Inc/i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : I2C.h 4 | * Description : This file provides code for the configuration 5 | * of the I2C instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __i2c_H 41 | #define __i2c_H 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "main.h" 48 | 49 | /* USER CODE BEGIN Includes */ 50 | 51 | /* USER CODE END Includes */ 52 | 53 | extern I2C_HandleTypeDef hi2c2; 54 | 55 | /* USER CODE BEGIN Private defines */ 56 | 57 | /* USER CODE END Private defines */ 58 | 59 | void MX_I2C2_Init(void); 60 | 61 | /* USER CODE BEGIN Prototypes */ 62 | 63 | /* USER CODE END Prototypes */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | #endif /*__ i2c_H */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 79 | -------------------------------------------------------------------------------- /Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | ** This notice applies to any and all portions of this file 9 | * that are not between comment pairs USER CODE BEGIN and 10 | * USER CODE END. Other portions of this file, whether 11 | * inserted by the user or by software development tools 12 | * are owned by their respective copyright owners. 13 | * 14 | * COPYRIGHT(c) 2018 STMicroelectronics 15 | * 16 | * Redistribution and use in source and binary forms, with or without modification, 17 | * are permitted provided that the following conditions are met: 18 | * 1. Redistributions of source code must retain the above copyright notice, 19 | * this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, 21 | * this list of conditions and the following disclaimer in the documentation 22 | * and/or other materials provided with the distribution. 23 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | ****************************************************************************** 39 | */ 40 | /* USER CODE END Header */ 41 | 42 | /* Define to prevent recursive inclusion -------------------------------------*/ 43 | #ifndef __MAIN_H 44 | #define __MAIN_H 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | /* Includes ------------------------------------------------------------------*/ 51 | #include "stm32f4xx_hal.h" 52 | #include "stm32f4xx_hal.h" 53 | 54 | /* Private includes ----------------------------------------------------------*/ 55 | /* USER CODE BEGIN Includes */ 56 | 57 | /* USER CODE END Includes */ 58 | 59 | /* Exported types ------------------------------------------------------------*/ 60 | /* USER CODE BEGIN ET */ 61 | 62 | /* USER CODE END ET */ 63 | 64 | /* Exported constants --------------------------------------------------------*/ 65 | /* USER CODE BEGIN EC */ 66 | 67 | /* USER CODE END EC */ 68 | 69 | /* Exported macro ------------------------------------------------------------*/ 70 | /* USER CODE BEGIN EM */ 71 | 72 | /* USER CODE END EM */ 73 | 74 | /* Exported functions prototypes ---------------------------------------------*/ 75 | void Error_Handler(void); 76 | 77 | /* USER CODE BEGIN EFP */ 78 | 79 | /* USER CODE END EFP */ 80 | 81 | /* Private defines -----------------------------------------------------------*/ 82 | #define TEMT600_ADC_IN_Pin GPIO_PIN_0 83 | #define TEMT600_ADC_IN_GPIO_Port GPIOA 84 | #define MAX44009_INT_Pin GPIO_PIN_10 85 | #define MAX44009_INT_GPIO_Port GPIOA 86 | #define MAX44009_INT_EXTI_IRQn EXTI15_10_IRQn 87 | #define TEST_Pin GPIO_PIN_4 88 | #define TEST_GPIO_Port GPIOB 89 | /* USER CODE BEGIN Private defines */ 90 | 91 | /* USER CODE END Private defines */ 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /* __MAIN_H */ 98 | 99 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 100 | -------------------------------------------------------------------------------- /Inc/max44009.h: -------------------------------------------------------------------------------- 1 | /* 2 | * max44009.h 3 | * 4 | * The MIT License. 5 | * Created on: 06.12.2018 6 | * Author: Mateusz Salamon 7 | * www.msalamon.pl 8 | * mateusz@msalamon.pl 9 | * 10 | * https://msalamon.pl/pomiar-natezenia-swiatla-z-wykorzystaniem-stm32/ 11 | * https://github.com/lamik/Light_Sensors_STM32 12 | */ 13 | 14 | #ifndef MAX44009_H_ 15 | #define MAX44009_H_ 16 | 17 | #define MAX44009_ADDRESS (0x4A<<1) 18 | 19 | // 20 | // Registers 21 | // 22 | #define MAX44009_INTERRUPT_STATUS_REGISTER 0x00 23 | #define MAX44009_INTERRPUT_ENABLE_REGISTER 0x01 24 | #define MAX44009_CONFIGURATION_REGISTER 0x02 25 | #define MAX44009_LUX_HIGH_BYTE_REGISTER 0x03 26 | #define MAX44009_LUX_LOW_BYTE_REGISTER 0x04 27 | #define MAX44009_UPPER_THRESHOLD_REGISTER 0x05 28 | #define MAX44009_LOWER_THRESHOLD_REGISTER 0x06 29 | #define MAX44009_THRESHOLD_TIMER_REGISTER 0x07 30 | 31 | 32 | typedef enum { 33 | MAX44009_OK = 0, 34 | MAX44009_ERROR = 1 35 | } MAX44009_STATUS; 36 | 37 | typedef enum 38 | { 39 | INTEGRATION_TIME_6_25_MS = 0x07, // Manual mode only 40 | INTEGRATION_TIME_12_5_MS = 0x06, // Manual mode only 41 | INTEGRATION_TIME_25_MS = 0x05, // Manual mode only 42 | INTEGRATION_TIME_50_MS = 0x04, // Manual mode only 43 | INTEGRATION_TIME_100_MS = 0x03, // This is a preferred mode for high-brightness applications 44 | INTEGRATION_TIME_200_MS = 0x02, 45 | INTEGRATION_TIME_400_MS = 0x01, 46 | INTEGRATION_TIME_800_MS = 0x00 // This is a preferred mode for boosting low-light sensitivity 47 | } max44009_timer; 48 | 49 | 50 | MAX44009_STATUS MAX44009_Init(I2C_HandleTypeDef *hi2c); 51 | 52 | MAX44009_STATUS MAX44009_ReadConfigurationRegister(uint8_t *Config); 53 | MAX44009_STATUS MAX44009_WriteConfigurationRegister(uint8_t Config); 54 | 55 | MAX44009_STATUS MAX44009_ContinuousMode(uint8_t Enable); 56 | MAX44009_STATUS MAX44009_ManualConfiguration(uint8_t Enable); 57 | MAX44009_STATUS MAX44009_CurrentDivisionRatio(uint8_t Enable); 58 | MAX44009_STATUS MAX44009_IntegrationTime(max44009_timer Timer); 59 | 60 | MAX44009_STATUS MAX44009_ReadLightLowResolution(float *Result); 61 | MAX44009_STATUS MAX44009_ReadLightHighResolution(float *Result); 62 | 63 | MAX44009_STATUS MAX44009_ReadInterruptStatus(uint8_t *Status); 64 | MAX44009_STATUS MAX44009_WriteInterruptEnable(uint8_t Enable); 65 | 66 | MAX44009_STATUS MAX44009_SetUpperThreshold(float Threshold); 67 | MAX44009_STATUS MAX44009_SetLowerThreshold(float Threshold); 68 | MAX44009_STATUS MAX44009_SetThresholdTimer(uint8_t Timer); 69 | 70 | #endif /* MAX44009_H_ */ 71 | -------------------------------------------------------------------------------- /Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2018 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* USER CODE END Header */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F4xx_IT_H 38 | #define __STM32F4xx_IT_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Private includes ----------------------------------------------------------*/ 45 | /* USER CODE BEGIN Includes */ 46 | 47 | /* USER CODE END Includes */ 48 | 49 | /* Exported types ------------------------------------------------------------*/ 50 | /* USER CODE BEGIN ET */ 51 | 52 | /* USER CODE END ET */ 53 | 54 | /* Exported constants --------------------------------------------------------*/ 55 | /* USER CODE BEGIN EC */ 56 | 57 | /* USER CODE END EC */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* USER CODE BEGIN EM */ 61 | 62 | /* USER CODE END EM */ 63 | 64 | /* Exported functions prototypes ---------------------------------------------*/ 65 | void NMI_Handler(void); 66 | void HardFault_Handler(void); 67 | void MemManage_Handler(void); 68 | void BusFault_Handler(void); 69 | void UsageFault_Handler(void); 70 | void SVC_Handler(void); 71 | void DebugMon_Handler(void); 72 | void PendSV_Handler(void); 73 | void SysTick_Handler(void); 74 | void EXTI15_10_IRQHandler(void); 75 | void DMA2_Stream0_IRQHandler(void); 76 | /* USER CODE BEGIN EFP */ 77 | 78 | /* USER CODE END EFP */ 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* __STM32F4xx_IT_H */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /Inc/temt6000.h: -------------------------------------------------------------------------------- 1 | /* 2 | * temt6000.h 3 | * 4 | * The MIT License. 5 | * Created on: 19.01.2019 6 | * Author: Mateusz Salamon 7 | * www.msalamon.pl 8 | * mateusz@msalamon.pl 9 | * 10 | * https://msalamon.pl/pomiar-natezenia-swiatla-z-wykorzystaniem-stm32/ 11 | * https://github.com/lamik/Light_Sensors_STM32 12 | */ 13 | 14 | #ifndef TEMT6000_H_ 15 | #define TEMT6000_H_ 16 | 17 | #define TEMT6000_ADC_MAX_VALUE 4096 18 | #define TEMT6000_POWER_SUPPLY 3.3 19 | #define TEMT6000_RESISTOR_OHMS 1000 20 | #define TEMT6000_ADC_SAMPLES 8 21 | 22 | typedef enum { 23 | TEMT6000_OK = 0, 24 | TEMT6000_ERROR = 1 25 | } TEMT6000_STATUS; 26 | 27 | TEMT6000_STATUS TEMT6000_Init(ADC_HandleTypeDef *hadc); 28 | 29 | TEMT6000_STATUS TEMT6000_ReadLight(float *Result); 30 | #endif /* TEMT6000_H_ */ 31 | -------------------------------------------------------------------------------- /Inc/usart.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.h 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __usart_H 41 | #define __usart_H 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "main.h" 48 | 49 | /* USER CODE BEGIN Includes */ 50 | 51 | /* USER CODE END Includes */ 52 | 53 | extern UART_HandleTypeDef huart2; 54 | 55 | /* USER CODE BEGIN Private defines */ 56 | 57 | /* USER CODE END Private defines */ 58 | 59 | void MX_USART2_UART_Init(void); 60 | 61 | /* USER CODE BEGIN Prototypes */ 62 | 63 | /* USER CODE END Prototypes */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | #endif /*__ usart_H */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Mateusz Salamon 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /Light_sensors Run.cfg: -------------------------------------------------------------------------------- 1 | # This is an Light_sensors board with a single STM32F401RETx chip 2 | # 3 | # Generated by System Workbench for STM32 4 | # Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) 5 | 6 | source [find interface/stlink.cfg] 7 | 8 | set WORKAREASIZE 0x8000 9 | 10 | transport select "hla_swd" 11 | 12 | set CHIPNAME STM32F401RETx 13 | set BOARDNAME Light_sensors 14 | 15 | # Enable debug when in low power modes 16 | set ENABLE_LOW_POWER 1 17 | 18 | # Stop Watchdog counters when halt 19 | set STOP_WATCHDOG 1 20 | 21 | # STlink Debug clock frequency 22 | set CLOCK_FREQ 4000 23 | 24 | # use hardware reset, connect under reset 25 | # connect_assert_srst needed if low power mode application running (WFI...) 26 | reset_config srst_only srst_nogate connect_assert_srst 27 | set CONNECT_UNDER_RESET 1 28 | 29 | source [find target/stm32f4x.cfg] 30 | -------------------------------------------------------------------------------- /Light_sensors.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0 3 | ADC1.ContinuousConvMode=ENABLE 4 | ADC1.DMAContinuousRequests=ENABLE 5 | ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,master,NbrOfConversion,InjNumberOfConversion,ScanConvMode,ContinuousConvMode,DMAContinuousRequests 6 | ADC1.InjNumberOfConversion=0 7 | ADC1.NbrOfConversion=1 8 | ADC1.NbrOfConversionFlag=1 9 | ADC1.Rank-0\#ChannelRegularConversion=1 10 | ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_480CYCLES 11 | ADC1.ScanConvMode=DISABLE 12 | ADC1.master=1 13 | Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY 14 | Dma.ADC1.0.FIFOMode=DMA_FIFOMODE_DISABLE 15 | Dma.ADC1.0.Instance=DMA2_Stream0 16 | Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD 17 | Dma.ADC1.0.MemInc=DMA_MINC_ENABLE 18 | Dma.ADC1.0.Mode=DMA_CIRCULAR 19 | Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD 20 | Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE 21 | Dma.ADC1.0.Priority=DMA_PRIORITY_MEDIUM 22 | Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode 23 | Dma.Request0=ADC1 24 | Dma.RequestsNb=1 25 | File.Version=6 26 | I2C2.I2C_Mode=I2C_Fast 27 | I2C2.IPParameters=I2C_Mode 28 | KeepUserPlacement=false 29 | Mcu.Family=STM32F4 30 | Mcu.IP0=ADC1 31 | Mcu.IP1=DMA 32 | Mcu.IP2=I2C2 33 | Mcu.IP3=NVIC 34 | Mcu.IP4=RCC 35 | Mcu.IP5=SYS 36 | Mcu.IP6=USART2 37 | Mcu.IPNb=7 38 | Mcu.Name=STM32F401R(D-E)Tx 39 | Mcu.Package=LQFP64 40 | Mcu.Pin0=PA0-WKUP 41 | Mcu.Pin1=PA2 42 | Mcu.Pin2=PA3 43 | Mcu.Pin3=PB10 44 | Mcu.Pin4=PA10 45 | Mcu.Pin5=PB3 46 | Mcu.Pin6=PB4 47 | Mcu.Pin7=VP_SYS_VS_Systick 48 | Mcu.PinsNb=8 49 | Mcu.ThirdPartyNb=0 50 | Mcu.UserConstants= 51 | Mcu.UserName=STM32F401RETx 52 | MxCube.Version=5.0.0 53 | MxDb.Version=DB.5.0.0 54 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false 55 | NVIC.DMA2_Stream0_IRQn=true\:0\:0\:false\:false\:true\:false 56 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false 57 | NVIC.EXTI15_10_IRQn=true\:0\:0\:false\:true\:true\:1\:true 58 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false 59 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false 60 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false 61 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false 62 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 63 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false 64 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false 65 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false 66 | PA0-WKUP.GPIOParameters=GPIO_Label 67 | PA0-WKUP.GPIO_Label=TEMT600_ADC_IN 68 | PA0-WKUP.Locked=true 69 | PA0-WKUP.Signal=ADCx_IN0 70 | PA10.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI 71 | PA10.GPIO_Label=MAX44009_INT 72 | PA10.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING 73 | PA10.GPIO_PuPd=GPIO_PULLUP 74 | PA10.Locked=true 75 | PA10.Signal=GPXTI10 76 | PA2.Mode=Asynchronous 77 | PA2.Signal=USART2_TX 78 | PA3.Mode=Asynchronous 79 | PA3.Signal=USART2_RX 80 | PB10.Mode=I2C 81 | PB10.Signal=I2C2_SCL 82 | PB3.Mode=I2C 83 | PB3.Signal=I2C2_SDA 84 | PB4.GPIOParameters=GPIO_Label 85 | PB4.GPIO_Label=TEST 86 | PB4.Locked=true 87 | PB4.Signal=GPIO_Output 88 | PCC.Checker=false 89 | PCC.Line=STM32F401 90 | PCC.MCU=STM32F401R(D-E)Tx 91 | PCC.PartNumber=STM32F401RETx 92 | PCC.Seq0=0 93 | PCC.Series=STM32F4 94 | PCC.Temperature=25 95 | PCC.Vdd=null 96 | PinOutPanel.RotationAngle=0 97 | ProjectManager.AskForMigrate=true 98 | ProjectManager.BackupPrevious=false 99 | ProjectManager.CompilerOptimize=6 100 | ProjectManager.ComputerToolchain=false 101 | ProjectManager.CoupleFile=true 102 | ProjectManager.CustomerFirmwarePackage= 103 | ProjectManager.DefaultFWLocation=true 104 | ProjectManager.DeletePrevious=true 105 | ProjectManager.DeviceId=STM32F401RETx 106 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.23.0 107 | ProjectManager.FreePins=false 108 | ProjectManager.HalAssertFull=false 109 | ProjectManager.HeapSize=0x200 110 | ProjectManager.KeepUserCode=true 111 | ProjectManager.LastFirmware=true 112 | ProjectManager.LibraryCopy=1 113 | ProjectManager.MainLocation=Src 114 | ProjectManager.NoMain=false 115 | ProjectManager.PreviousToolchain=SW4STM32 116 | ProjectManager.ProjectBuild=false 117 | ProjectManager.ProjectFileName=Light_sensors.ioc 118 | ProjectManager.ProjectName=Light_sensors 119 | ProjectManager.StackSize=0x400 120 | ProjectManager.TargetToolchain=SW4STM32 121 | ProjectManager.ToolChainLocation= 122 | ProjectManager.UnderRoot=true 123 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_I2C2_Init-I2C2-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true,6-MX_ADC1_Init-ADC1-false-HAL-true 124 | RCC.48MHZClocksFreq_Value=42000000 125 | RCC.AHBFreq_Value=84000000 126 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 127 | RCC.APB1Freq_Value=42000000 128 | RCC.APB1TimFreq_Value=84000000 129 | RCC.APB2Freq_Value=84000000 130 | RCC.APB2TimFreq_Value=84000000 131 | RCC.CortexFreq_Value=84000000 132 | RCC.FCLKCortexFreq_Value=84000000 133 | RCC.HCLKFreq_Value=84000000 134 | RCC.HSE_VALUE=25000000 135 | RCC.HSI_VALUE=16000000 136 | RCC.I2SClocksFreq_Value=192000000 137 | RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLQCLKFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S 138 | RCC.LSE_VALUE=32768 139 | RCC.LSI_VALUE=32000 140 | RCC.MCO2PinFreq_Value=84000000 141 | RCC.PLLCLKFreq_Value=84000000 142 | RCC.PLLM=8 143 | RCC.PLLN=84 144 | RCC.PLLQCLKFreq_Value=42000000 145 | RCC.RTCFreq_Value=32000 146 | RCC.RTCHSEDivFreq_Value=12500000 147 | RCC.SYSCLKFreq_VALUE=84000000 148 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 149 | RCC.VCOI2SOutputFreq_Value=384000000 150 | RCC.VCOInputFreq_Value=2000000 151 | RCC.VCOOutputFreq_Value=168000000 152 | RCC.VcooutputI2S=192000000 153 | SH.ADCx_IN0.0=ADC1_IN0,IN0 154 | SH.ADCx_IN0.ConfNb=1 155 | SH.GPXTI10.0=GPIO_EXTI10 156 | SH.GPXTI10.ConfNb=1 157 | USART2.IPParameters=VirtualMode 158 | USART2.VirtualMode=VM_ASYNC 159 | VP_SYS_VS_Systick.Mode=SysTick 160 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 161 | board=custom 162 | -------------------------------------------------------------------------------- /Light_sensors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Light_sensors 5 | STM32F401RETx 6 | SWD 7 | ST-LinkV2-1 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | https://msalamon.pl/pomiar-natezenia-swiatla-z-wykorzystaniem-stm32/ 2 | 3 | STM32 libraries for three light sensors: 4 | 5 | - BH1750 6 | - MAX44009 7 | - TEMT6000 8 | 9 | Code is based in STM32 HAL libraries. I used STM32F401RE but it's easy to port with HAL to another MCU. -------------------------------------------------------------------------------- /STM32F401RETx_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ***************************************************************************** 3 | ** 4 | 5 | ** File : LinkerScript.ld 6 | ** 7 | ** Abstract : Linker script for STM32F401RETx Device with 8 | ** 512KByte FLASH, 96KByte RAM 9 | ** 10 | ** Set heap size, stack size and stack location according 11 | ** to application requirements. 12 | ** 13 | ** Set memory bank area and size if external memory is used. 14 | ** 15 | ** Target : STMicroelectronics STM32 16 | ** 17 | ** 18 | ** Distribution: The file is distributed as is, without any warranty 19 | ** of any kind. 20 | ** 21 | ** (c)Copyright Ac6. 22 | ** You may use this file as-is or modify it according to the needs of your 23 | ** project. Distribution of this file (unmodified or modified) is not 24 | ** permitted. Ac6 permit registered System Workbench for MCU users the 25 | ** rights to distribute the assembled, compiled & linked contents of this 26 | ** file as part of an application binary file, provided that it is built 27 | ** using the System Workbench for MCU toolchain. 28 | ** 29 | ***************************************************************************** 30 | */ 31 | 32 | /* Entry Point */ 33 | ENTRY(Reset_Handler) 34 | 35 | /* Highest address of the user mode stack */ 36 | _estack = 0x20018000; /* end of RAM */ 37 | /* Generate a link error if heap and stack don't fit into RAM */ 38 | _Min_Heap_Size = 0x200; /* required amount of heap */ 39 | _Min_Stack_Size = 0x400; /* required amount of stack */ 40 | 41 | /* Specify the memory areas */ 42 | MEMORY 43 | { 44 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K 45 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K 46 | } 47 | 48 | /* Define output sections */ 49 | SECTIONS 50 | { 51 | /* The startup code goes first into FLASH */ 52 | .isr_vector : 53 | { 54 | . = ALIGN(4); 55 | KEEP(*(.isr_vector)) /* Startup code */ 56 | . = ALIGN(4); 57 | } >FLASH 58 | 59 | /* The program code and other data goes into FLASH */ 60 | .text : 61 | { 62 | . = ALIGN(4); 63 | *(.text) /* .text sections (code) */ 64 | *(.text*) /* .text* sections (code) */ 65 | *(.glue_7) /* glue arm to thumb code */ 66 | *(.glue_7t) /* glue thumb to arm code */ 67 | *(.eh_frame) 68 | 69 | KEEP (*(.init)) 70 | KEEP (*(.fini)) 71 | 72 | . = ALIGN(4); 73 | _etext = .; /* define a global symbols at end of code */ 74 | } >FLASH 75 | 76 | /* Constant data goes into FLASH */ 77 | .rodata : 78 | { 79 | . = ALIGN(4); 80 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 81 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 82 | . = ALIGN(4); 83 | } >FLASH 84 | 85 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH 86 | .ARM : { 87 | __exidx_start = .; 88 | *(.ARM.exidx*) 89 | __exidx_end = .; 90 | } >FLASH 91 | 92 | .preinit_array : 93 | { 94 | PROVIDE_HIDDEN (__preinit_array_start = .); 95 | KEEP (*(.preinit_array*)) 96 | PROVIDE_HIDDEN (__preinit_array_end = .); 97 | } >FLASH 98 | .init_array : 99 | { 100 | PROVIDE_HIDDEN (__init_array_start = .); 101 | KEEP (*(SORT(.init_array.*))) 102 | KEEP (*(.init_array*)) 103 | PROVIDE_HIDDEN (__init_array_end = .); 104 | } >FLASH 105 | .fini_array : 106 | { 107 | PROVIDE_HIDDEN (__fini_array_start = .); 108 | KEEP (*(SORT(.fini_array.*))) 109 | KEEP (*(.fini_array*)) 110 | PROVIDE_HIDDEN (__fini_array_end = .); 111 | } >FLASH 112 | 113 | /* used by the startup to initialize data */ 114 | _sidata = LOADADDR(.data); 115 | 116 | /* Initialized data sections goes into RAM, load LMA copy after code */ 117 | .data : 118 | { 119 | . = ALIGN(4); 120 | _sdata = .; /* create a global symbol at data start */ 121 | *(.data) /* .data sections */ 122 | *(.data*) /* .data* sections */ 123 | 124 | . = ALIGN(4); 125 | _edata = .; /* define a global symbol at data end */ 126 | } >RAM AT> FLASH 127 | 128 | 129 | /* Uninitialized data section */ 130 | . = ALIGN(4); 131 | .bss : 132 | { 133 | /* This is used by the startup in order to initialize the .bss secion */ 134 | _sbss = .; /* define a global symbol at bss start */ 135 | __bss_start__ = _sbss; 136 | *(.bss) 137 | *(.bss*) 138 | *(COMMON) 139 | 140 | . = ALIGN(4); 141 | _ebss = .; /* define a global symbol at bss end */ 142 | __bss_end__ = _ebss; 143 | } >RAM 144 | 145 | /* User_heap_stack section, used to check that there is enough RAM left */ 146 | ._user_heap_stack : 147 | { 148 | . = ALIGN(8); 149 | PROVIDE ( end = . ); 150 | PROVIDE ( _end = . ); 151 | . = . + _Min_Heap_Size; 152 | . = . + _Min_Stack_Size; 153 | . = ALIGN(8); 154 | } >RAM 155 | 156 | 157 | 158 | /* Remove information from the standard libraries */ 159 | /DISCARD/ : 160 | { 161 | libc.a ( * ) 162 | libm.a ( * ) 163 | libgcc.a ( * ) 164 | } 165 | 166 | .ARM.attributes 0 : { *(.ARM.attributes) } 167 | } 168 | 169 | 170 | -------------------------------------------------------------------------------- /Src/adc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : ADC.c 4 | * Description : This file provides code for the configuration 5 | * of the ADC instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Includes ------------------------------------------------------------------*/ 41 | #include "adc.h" 42 | 43 | /* USER CODE BEGIN 0 */ 44 | 45 | /* USER CODE END 0 */ 46 | 47 | ADC_HandleTypeDef hadc1; 48 | DMA_HandleTypeDef hdma_adc1; 49 | 50 | /* ADC1 init function */ 51 | void MX_ADC1_Init(void) 52 | { 53 | ADC_ChannelConfTypeDef sConfig = {0}; 54 | 55 | /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 56 | */ 57 | hadc1.Instance = ADC1; 58 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; 59 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 60 | hadc1.Init.ScanConvMode = DISABLE; 61 | hadc1.Init.ContinuousConvMode = ENABLE; 62 | hadc1.Init.DiscontinuousConvMode = DISABLE; 63 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 64 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 65 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 66 | hadc1.Init.NbrOfConversion = 1; 67 | hadc1.Init.DMAContinuousRequests = ENABLE; 68 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 69 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 70 | { 71 | Error_Handler(); 72 | } 73 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 74 | */ 75 | sConfig.Channel = ADC_CHANNEL_0; 76 | sConfig.Rank = 1; 77 | sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; 78 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 79 | { 80 | Error_Handler(); 81 | } 82 | 83 | } 84 | 85 | void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) 86 | { 87 | 88 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 89 | if(adcHandle->Instance==ADC1) 90 | { 91 | /* USER CODE BEGIN ADC1_MspInit 0 */ 92 | 93 | /* USER CODE END ADC1_MspInit 0 */ 94 | /* ADC1 clock enable */ 95 | __HAL_RCC_ADC1_CLK_ENABLE(); 96 | 97 | __HAL_RCC_GPIOA_CLK_ENABLE(); 98 | /**ADC1 GPIO Configuration 99 | PA0-WKUP ------> ADC1_IN0 100 | */ 101 | GPIO_InitStruct.Pin = TEMT600_ADC_IN_Pin; 102 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 103 | GPIO_InitStruct.Pull = GPIO_NOPULL; 104 | HAL_GPIO_Init(TEMT600_ADC_IN_GPIO_Port, &GPIO_InitStruct); 105 | 106 | /* ADC1 DMA Init */ 107 | /* ADC1 Init */ 108 | hdma_adc1.Instance = DMA2_Stream0; 109 | hdma_adc1.Init.Channel = DMA_CHANNEL_0; 110 | hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; 111 | hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; 112 | hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; 113 | hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; 114 | hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; 115 | hdma_adc1.Init.Mode = DMA_CIRCULAR; 116 | hdma_adc1.Init.Priority = DMA_PRIORITY_MEDIUM; 117 | hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; 118 | if (HAL_DMA_Init(&hdma_adc1) != HAL_OK) 119 | { 120 | Error_Handler(); 121 | } 122 | 123 | __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1); 124 | 125 | /* USER CODE BEGIN ADC1_MspInit 1 */ 126 | 127 | /* USER CODE END ADC1_MspInit 1 */ 128 | } 129 | } 130 | 131 | void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) 132 | { 133 | 134 | if(adcHandle->Instance==ADC1) 135 | { 136 | /* USER CODE BEGIN ADC1_MspDeInit 0 */ 137 | 138 | /* USER CODE END ADC1_MspDeInit 0 */ 139 | /* Peripheral clock disable */ 140 | __HAL_RCC_ADC1_CLK_DISABLE(); 141 | 142 | /**ADC1 GPIO Configuration 143 | PA0-WKUP ------> ADC1_IN0 144 | */ 145 | HAL_GPIO_DeInit(TEMT600_ADC_IN_GPIO_Port, TEMT600_ADC_IN_Pin); 146 | 147 | /* ADC1 DMA DeInit */ 148 | HAL_DMA_DeInit(adcHandle->DMA_Handle); 149 | /* USER CODE BEGIN ADC1_MspDeInit 1 */ 150 | 151 | /* USER CODE END ADC1_MspDeInit 1 */ 152 | } 153 | } 154 | 155 | /* USER CODE BEGIN 1 */ 156 | 157 | /* USER CODE END 1 */ 158 | 159 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 160 | -------------------------------------------------------------------------------- /Src/bh1750.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bh1750.c 3 | * 4 | * The MIT License. 5 | * Created on: 02.12.2018 6 | * Author: Mateusz Salamon 7 | * www.msalamon.pl 8 | * mateusz@msalamon.pl 9 | * 10 | * https://msalamon.pl/pomiar-natezenia-swiatla-z-wykorzystaniem-stm32/ 11 | * https://github.com/lamik/Light_Sensors_STM32 12 | */ 13 | 14 | #include "main.h" 15 | #include "i2c.h" 16 | 17 | #include "bh1750.h" 18 | 19 | I2C_HandleTypeDef *bh1750_i2c; // Handler to I2C interface 20 | bh1750_mode Bh1750_Mode; // Current sensor mode 21 | uint8_t Bh1750_Mtreg; // Current MT register value 22 | 23 | // 24 | // Initialization. 25 | // 26 | BH1750_STATUS BH1750_Init(I2C_HandleTypeDef *hi2c) 27 | { 28 | bh1750_i2c = hi2c; 29 | if(BH1750_OK == BH1750_Reset()) 30 | { 31 | if(BH1750_OK == BH1750_SetMtreg(BH1750_DEFAULT_MTREG)) // Set default value; 32 | return BH1750_OK; 33 | } 34 | return BH1750_ERROR; 35 | } 36 | 37 | // 38 | // Reset all registers to default value. 39 | // 40 | BH1750_STATUS BH1750_Reset(void) 41 | { 42 | uint8_t tmp = 0x07; 43 | if(HAL_OK == HAL_I2C_Master_Transmit(bh1750_i2c, BH1750_ADDRESS, &tmp, 1, 10)) 44 | return BH1750_OK; 45 | 46 | return BH1750_ERROR; 47 | } 48 | 49 | // 50 | // Set the power state. 51 | // 0 - sleep, low power. 52 | // 1 - running. 53 | // 54 | BH1750_STATUS BH1750_PowerState(uint8_t PowerOn) 55 | { 56 | PowerOn = (PowerOn? 1:0); 57 | if(HAL_OK == HAL_I2C_Master_Transmit(bh1750_i2c, BH1750_ADDRESS, &PowerOn, 1, 10)) 58 | return BH1750_OK; 59 | 60 | return BH1750_ERROR; 61 | } 62 | 63 | // 64 | // Set the mode of converting. Look into bh1750_mode enum. 65 | // 66 | BH1750_STATUS BH1750_SetMode(bh1750_mode Mode) 67 | { 68 | if(!((Mode >> 4) || (Mode >> 5))) return BH1750_ERROR; 69 | if((Mode & 0x0F) > 3) return BH1750_ERROR; 70 | 71 | Bh1750_Mode = Mode; 72 | if(HAL_OK == HAL_I2C_Master_Transmit(bh1750_i2c, BH1750_ADDRESS, &Mode, 1, 10)) 73 | return BH1750_OK; 74 | 75 | return BH1750_ERROR; 76 | } 77 | 78 | // 79 | // Set the Measurement Time register. It allows to increase or decrease the sensitivity. 80 | // 81 | BH1750_STATUS BH1750_SetMtreg(uint8_t Mtreg) 82 | { 83 | HAL_StatusTypeDef retCode; 84 | if (Mtreg < 31 || Mtreg > 254) { 85 | return BH1750_ERROR; 86 | } 87 | 88 | Bh1750_Mtreg = Mtreg; 89 | 90 | uint8_t tmp[2]; 91 | 92 | tmp[0] = (0x40 | (Mtreg >> 5)); 93 | tmp[1] = (0x60 | (Mtreg & 0x1F)); 94 | 95 | retCode = HAL_I2C_Master_Transmit(bh1750_i2c, BH1750_ADDRESS, &tmp[0], 1, 10); 96 | if (HAL_OK != retCode) { 97 | return BH1750_ERROR; 98 | } 99 | 100 | retCode = HAL_I2C_Master_Transmit(bh1750_i2c, BH1750_ADDRESS, &tmp[1], 1, 10); 101 | if (HAL_OK == retCode) { 102 | return BH1750_OK; 103 | } 104 | 105 | return BH1750_ERROR; 106 | } 107 | 108 | // 109 | // Trigger the conversion in manual modes. 110 | // For low resolution conversion time is typical 16 ms, 111 | // for high resolution 120 ms. You need to wait until read the measurement value. 112 | // There is no need to exit low power mode for manual conversion. It makes automatically. 113 | // 114 | BH1750_STATUS BH1750_TriggerManualConversion(void) 115 | { 116 | if(BH1750_OK == BH1750_SetMode(Bh1750_Mode)) 117 | { 118 | return BH1750_OK; 119 | } 120 | return BH1750_ERROR; 121 | } 122 | 123 | // 124 | // Read the converted value and calculate the result. 125 | // 126 | BH1750_STATUS BH1750_ReadLight(float *Result) 127 | { 128 | float result; 129 | uint8_t tmp[2]; 130 | 131 | if(HAL_OK == HAL_I2C_Master_Receive(bh1750_i2c, BH1750_ADDRESS, tmp, 2, 10)) 132 | { 133 | result = (tmp[0] << 8) | (tmp[1]); 134 | 135 | if(Bh1750_Mtreg != BH1750_DEFAULT_MTREG) 136 | { 137 | result *= (float)((uint8_t)BH1750_DEFAULT_MTREG/(float)Bh1750_Mtreg); 138 | } 139 | 140 | if(Bh1750_Mode == ONETIME_HIGH_RES_MODE_2 || Bh1750_Mode == CONTINUOUS_HIGH_RES_MODE_2) 141 | { 142 | result /= 2.0; 143 | } 144 | 145 | *Result = result / (float)BH1750_CONVERSION_FACTOR; 146 | return BH1750_OK; 147 | } 148 | return BH1750_ERROR; 149 | } 150 | -------------------------------------------------------------------------------- /Src/dma.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : dma.c 4 | * Description : This file provides code for the configuration 5 | * of all the requested memory to memory DMA transfers. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include "dma.h" 41 | 42 | /* USER CODE BEGIN 0 */ 43 | 44 | /* USER CODE END 0 */ 45 | 46 | /*----------------------------------------------------------------------------*/ 47 | /* Configure DMA */ 48 | /*----------------------------------------------------------------------------*/ 49 | 50 | /* USER CODE BEGIN 1 */ 51 | 52 | /* USER CODE END 1 */ 53 | 54 | /** 55 | * Enable DMA controller clock 56 | */ 57 | void MX_DMA_Init(void) 58 | { 59 | /* DMA controller clock enable */ 60 | __HAL_RCC_DMA2_CLK_ENABLE(); 61 | 62 | /* DMA interrupt init */ 63 | /* DMA2_Stream0_IRQn interrupt configuration */ 64 | HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0); 65 | HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn); 66 | 67 | } 68 | 69 | /* USER CODE BEGIN 2 */ 70 | 71 | /* USER CODE END 2 */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 82 | -------------------------------------------------------------------------------- /Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.c 4 | * Description : This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Includes ------------------------------------------------------------------*/ 41 | #include "gpio.h" 42 | /* USER CODE BEGIN 0 */ 43 | 44 | /* USER CODE END 0 */ 45 | 46 | /*----------------------------------------------------------------------------*/ 47 | /* Configure GPIO */ 48 | /*----------------------------------------------------------------------------*/ 49 | /* USER CODE BEGIN 1 */ 50 | 51 | /* USER CODE END 1 */ 52 | 53 | /** Configure pins 54 | */ 55 | void MX_GPIO_Init(void) 56 | { 57 | 58 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 59 | 60 | /* GPIO Ports Clock Enable */ 61 | __HAL_RCC_GPIOA_CLK_ENABLE(); 62 | __HAL_RCC_GPIOB_CLK_ENABLE(); 63 | 64 | /*Configure GPIO pin Output Level */ 65 | HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, GPIO_PIN_RESET); 66 | 67 | /*Configure GPIO pin : PtPin */ 68 | GPIO_InitStruct.Pin = MAX44009_INT_Pin; 69 | GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; 70 | GPIO_InitStruct.Pull = GPIO_PULLUP; 71 | HAL_GPIO_Init(MAX44009_INT_GPIO_Port, &GPIO_InitStruct); 72 | 73 | /*Configure GPIO pin : PtPin */ 74 | GPIO_InitStruct.Pin = TEST_Pin; 75 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 76 | GPIO_InitStruct.Pull = GPIO_NOPULL; 77 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 78 | HAL_GPIO_Init(TEST_GPIO_Port, &GPIO_InitStruct); 79 | 80 | } 81 | 82 | /* USER CODE BEGIN 2 */ 83 | 84 | /* USER CODE END 2 */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /Src/i2c.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : I2C.c 4 | * Description : This file provides code for the configuration 5 | * of the I2C instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Includes ------------------------------------------------------------------*/ 41 | #include "i2c.h" 42 | 43 | /* USER CODE BEGIN 0 */ 44 | 45 | /* USER CODE END 0 */ 46 | 47 | I2C_HandleTypeDef hi2c2; 48 | 49 | /* I2C2 init function */ 50 | void MX_I2C2_Init(void) 51 | { 52 | 53 | hi2c2.Instance = I2C2; 54 | hi2c2.Init.ClockSpeed = 400000; 55 | hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; 56 | hi2c2.Init.OwnAddress1 = 0; 57 | hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; 58 | hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; 59 | hi2c2.Init.OwnAddress2 = 0; 60 | hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; 61 | hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; 62 | if (HAL_I2C_Init(&hi2c2) != HAL_OK) 63 | { 64 | Error_Handler(); 65 | } 66 | 67 | } 68 | 69 | void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) 70 | { 71 | 72 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 73 | if(i2cHandle->Instance==I2C2) 74 | { 75 | /* USER CODE BEGIN I2C2_MspInit 0 */ 76 | 77 | /* USER CODE END I2C2_MspInit 0 */ 78 | 79 | __HAL_RCC_GPIOB_CLK_ENABLE(); 80 | /**I2C2 GPIO Configuration 81 | PB10 ------> I2C2_SCL 82 | PB3 ------> I2C2_SDA 83 | */ 84 | GPIO_InitStruct.Pin = GPIO_PIN_10; 85 | GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; 86 | GPIO_InitStruct.Pull = GPIO_PULLUP; 87 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 88 | GPIO_InitStruct.Alternate = GPIO_AF4_I2C2; 89 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 90 | 91 | GPIO_InitStruct.Pin = GPIO_PIN_3; 92 | GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; 93 | GPIO_InitStruct.Pull = GPIO_PULLUP; 94 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 95 | GPIO_InitStruct.Alternate = GPIO_AF9_I2C2; 96 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 97 | 98 | /* I2C2 clock enable */ 99 | __HAL_RCC_I2C2_CLK_ENABLE(); 100 | /* USER CODE BEGIN I2C2_MspInit 1 */ 101 | 102 | /* USER CODE END I2C2_MspInit 1 */ 103 | } 104 | } 105 | 106 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) 107 | { 108 | 109 | if(i2cHandle->Instance==I2C2) 110 | { 111 | /* USER CODE BEGIN I2C2_MspDeInit 0 */ 112 | 113 | /* USER CODE END I2C2_MspDeInit 0 */ 114 | /* Peripheral clock disable */ 115 | __HAL_RCC_I2C2_CLK_DISABLE(); 116 | 117 | /**I2C2 GPIO Configuration 118 | PB10 ------> I2C2_SCL 119 | PB3 ------> I2C2_SDA 120 | */ 121 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_3); 122 | 123 | /* USER CODE BEGIN I2C2_MspDeInit 1 */ 124 | 125 | /* USER CODE END I2C2_MspDeInit 1 */ 126 | } 127 | } 128 | 129 | /* USER CODE BEGIN 1 */ 130 | 131 | /* USER CODE END 1 */ 132 | 133 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 134 | -------------------------------------------------------------------------------- /Src/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2018 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* USER CODE END Header */ 40 | 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "main.h" 43 | #include "adc.h" 44 | #include "dma.h" 45 | #include "i2c.h" 46 | #include "usart.h" 47 | #include "gpio.h" 48 | 49 | /* Private includes ----------------------------------------------------------*/ 50 | /* USER CODE BEGIN Includes */ 51 | #include "bh1750.h" 52 | #include "max44009.h" 53 | #include "temt6000.h" 54 | /* USER CODE END Includes */ 55 | 56 | /* Private typedef -----------------------------------------------------------*/ 57 | /* USER CODE BEGIN PTD */ 58 | 59 | /* USER CODE END PTD */ 60 | 61 | /* Private define ------------------------------------------------------------*/ 62 | /* USER CODE BEGIN PD */ 63 | #define STM_STUDIO 64 | /* USER CODE END PD */ 65 | 66 | /* Private macro -------------------------------------------------------------*/ 67 | /* USER CODE BEGIN PM */ 68 | 69 | /* USER CODE END PM */ 70 | 71 | /* Private variables ---------------------------------------------------------*/ 72 | 73 | /* USER CODE BEGIN PV */ 74 | float BH1750_lux, MAX44009_lux, TEMT6000_lux; 75 | /* USER CODE END PV */ 76 | 77 | /* Private function prototypes -----------------------------------------------*/ 78 | void SystemClock_Config(void); 79 | static void MX_NVIC_Init(void); 80 | /* USER CODE BEGIN PFP */ 81 | 82 | /* USER CODE END PFP */ 83 | 84 | /* Private user code ---------------------------------------------------------*/ 85 | /* USER CODE BEGIN 0 */ 86 | 87 | /* USER CODE END 0 */ 88 | 89 | /** 90 | * @brief The application entry point. 91 | * @retval int 92 | */ 93 | int main(void) 94 | { 95 | /* USER CODE BEGIN 1 */ 96 | 97 | /* USER CODE END 1 */ 98 | 99 | /* MCU Configuration--------------------------------------------------------*/ 100 | 101 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 102 | HAL_Init(); 103 | 104 | /* USER CODE BEGIN Init */ 105 | 106 | /* USER CODE END Init */ 107 | 108 | /* Configure the system clock */ 109 | SystemClock_Config(); 110 | 111 | /* USER CODE BEGIN SysInit */ 112 | 113 | /* USER CODE END SysInit */ 114 | 115 | /* Initialize all configured peripherals */ 116 | MX_GPIO_Init(); 117 | MX_DMA_Init(); 118 | MX_I2C2_Init(); 119 | MX_USART2_UART_Init(); 120 | MX_ADC1_Init(); 121 | 122 | /* Initialize interrupts */ 123 | MX_NVIC_Init(); 124 | /* USER CODE BEGIN 2 */ 125 | BH1750_Init(&hi2c2); 126 | BH1750_SetMode(CONTINUOUS_HIGH_RES_MODE_2); 127 | 128 | MAX44009_Init(&hi2c2); 129 | MAX44009_ContinuousMode(1); 130 | // MAX44009_WriteInterruptEnable(1); 131 | // MAX44009_SetUpperThreshold(100); 132 | // MAX44009_SetThresholdTimer(10); 133 | // MAX44009_IntegrationTime(INTEGRATION_TIME_100_MS); 134 | 135 | TEMT6000_Init(&hadc1); 136 | /* USER CODE END 2 */ 137 | 138 | /* Infinite loop */ 139 | /* USER CODE BEGIN WHILE */ 140 | char buffer[40]; 141 | uint8_t size; 142 | while (1) 143 | { 144 | #ifdef STM_STUDIO 145 | 146 | BH1750_ReadLight(&BH1750_lux); 147 | MAX44009_ReadLightHighResolution(&MAX44009_lux); 148 | TEMT6000_ReadLight(&TEMT6000_lux); 149 | #else 150 | if(BH1750_OK == BH1750_ReadLight(&BH1750_lux)) 151 | { 152 | size = sprintf(buffer, "BH1750 Lux: %.2f\n\r", BH1750_lux); 153 | HAL_UART_Transmit(&huart2, (uint8_t*)buffer, size, 100); 154 | } 155 | 156 | if(MAX44009_OK == MAX44009_ReadLightLowResolution(&MAX44009_lux)) 157 | { 158 | size = sprintf(buffer, "MAX44009 Lux: %.2f\n\r", MAX44009_lux); 159 | HAL_UART_Transmit(&huart2, (uint8_t*)buffer, size, 100); 160 | } 161 | HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, 1); 162 | if(TEMT6000_OK == TEMT6000_ReadLight(&TEMT6000_lux)) 163 | { 164 | HAL_GPIO_WritePin(TEST_GPIO_Port, TEST_Pin, 0); 165 | size = sprintf(buffer, "TEMT6000 Lux: %.2f\n\r\n\r", TEMT6000_lux); 166 | HAL_UART_Transmit(&huart2, (uint8_t*)buffer, size, 100); 167 | } 168 | 169 | HAL_Delay(200); 170 | #endif 171 | /* USER CODE END WHILE */ 172 | 173 | /* USER CODE BEGIN 3 */ 174 | } 175 | /* USER CODE END 3 */ 176 | } 177 | 178 | /** 179 | * @brief System Clock Configuration 180 | * @retval None 181 | */ 182 | void SystemClock_Config(void) 183 | { 184 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 185 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 186 | 187 | /**Configure the main internal regulator output voltage 188 | */ 189 | __HAL_RCC_PWR_CLK_ENABLE(); 190 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); 191 | /**Initializes the CPU, AHB and APB busses clocks 192 | */ 193 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 194 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 195 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 196 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 197 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 198 | RCC_OscInitStruct.PLL.PLLM = 8; 199 | RCC_OscInitStruct.PLL.PLLN = 84; 200 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 201 | RCC_OscInitStruct.PLL.PLLQ = 4; 202 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 203 | { 204 | Error_Handler(); 205 | } 206 | /**Initializes the CPU, AHB and APB busses clocks 207 | */ 208 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 209 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 210 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 211 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 212 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 213 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 214 | 215 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 216 | { 217 | Error_Handler(); 218 | } 219 | } 220 | 221 | /** 222 | * @brief NVIC Configuration. 223 | * @retval None 224 | */ 225 | static void MX_NVIC_Init(void) 226 | { 227 | /* EXTI15_10_IRQn interrupt configuration */ 228 | HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); 229 | HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); 230 | } 231 | 232 | /* USER CODE BEGIN 4 */ 233 | HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) 234 | { 235 | // if(GPIO_Pin == MAX44009_INT_Pin) 236 | // { 237 | // uint8_t IntStatus; 238 | // MAX44009_ReadInterruptStatus(&IntStatus); 239 | // if(IntStatus) 240 | // { 241 | // MAX44009_ReadLightHighResolution(&lux2); 242 | // HAL_UART_Transmit(&huart2, "INT\n\r", 6, 100); 243 | // } 244 | // 245 | // } 246 | } 247 | /* USER CODE END 4 */ 248 | 249 | /** 250 | * @brief This function is executed in case of error occurrence. 251 | * @retval None 252 | */ 253 | void Error_Handler(void) 254 | { 255 | /* USER CODE BEGIN Error_Handler_Debug */ 256 | /* User can add his own implementation to report the HAL error return state */ 257 | 258 | /* USER CODE END Error_Handler_Debug */ 259 | } 260 | 261 | #ifdef USE_FULL_ASSERT 262 | /** 263 | * @brief Reports the name of the source file and the source line number 264 | * where the assert_param error has occurred. 265 | * @param file: pointer to the source file name 266 | * @param line: assert_param error line source number 267 | * @retval None 268 | */ 269 | void assert_failed(uint8_t *file, uint32_t line) 270 | { 271 | /* USER CODE BEGIN 6 */ 272 | /* User can add his own implementation to report the file name and line number, 273 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 274 | /* USER CODE END 6 */ 275 | } 276 | #endif /* USE_FULL_ASSERT */ 277 | 278 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 279 | -------------------------------------------------------------------------------- /Src/max44009.c: -------------------------------------------------------------------------------- 1 | /* 2 | * max44009.c 3 | * 4 | * The MIT License. 5 | * Created on: 06.12.2018 6 | * Author: Mateusz Salamon 7 | * www.msalamon.pl 8 | * mateusz@msalamon.pl 9 | * 10 | * https://msalamon.pl/pomiar-natezenia-swiatla-z-wykorzystaniem-stm32/ 11 | * https://github.com/lamik/Light_Sensors_STM32 12 | */ 13 | 14 | 15 | #include "main.h" 16 | #include "i2c.h" 17 | 18 | #include 19 | #include "max44009.h" 20 | 21 | I2C_HandleTypeDef *max44009_i2c; // Handler to I2C interface 22 | 23 | // 24 | // Initialization. 25 | // 26 | MAX44009_STATUS MAX44009_Init(I2C_HandleTypeDef *hi2c) 27 | { 28 | max44009_i2c = hi2c; 29 | 30 | return MAX44009_OK; 31 | } 32 | 33 | // 34 | // Read from Interrupt Status register. 35 | // 0 - No interrupt occurred. 36 | // 1 - Interrupt occurred. 37 | // 38 | MAX44009_STATUS MAX44009_ReadInterruptStatus(uint8_t *Status) 39 | { 40 | if(HAL_OK == HAL_I2C_Mem_Read(max44009_i2c, MAX44009_ADDRESS, MAX44009_INTERRUPT_STATUS_REGISTER, 1, Status, 1, 10)) 41 | { 42 | return MAX44009_OK; 43 | } 44 | 45 | return MAX44009_ERROR; 46 | } 47 | 48 | // 49 | // Write to Interrupt Enable register. 50 | // 0 - Interrupt disable. 51 | // 1 - Interrupt Enable. 52 | // 53 | MAX44009_STATUS MAX44009_WriteInterruptEnable(uint8_t Enable) 54 | { 55 | Enable = (Enable? 1:0); 56 | if(HAL_OK == HAL_I2C_Mem_Write(max44009_i2c, MAX44009_ADDRESS, MAX44009_INTERRPUT_ENABLE_REGISTER, 1, &Enable, 1, 10)) 57 | { 58 | return MAX44009_OK; 59 | } 60 | 61 | return MAX44009_ERROR; 62 | } 63 | 64 | // 65 | // Read from Configuration register. 66 | // 67 | MAX44009_STATUS MAX44009_ReadConfigurationRegister(uint8_t *Config) 68 | { 69 | if(HAL_OK == HAL_I2C_Mem_Read(max44009_i2c, MAX44009_ADDRESS, MAX44009_CONFIGURATION_REGISTER, 1, Config, 1, 10)) 70 | { 71 | return MAX44009_OK; 72 | } 73 | 74 | return MAX44009_ERROR; 75 | } 76 | 77 | // 78 | // Write to Configuration register. 79 | // 80 | MAX44009_STATUS MAX44009_WriteConfigurationRegister(uint8_t Config) 81 | { 82 | if(HAL_OK == HAL_I2C_Mem_Write(max44009_i2c, MAX44009_ADDRESS, MAX44009_CONFIGURATION_REGISTER, 1, &Config, 1, 10)) 83 | { 84 | return MAX44009_OK; 85 | } 86 | 87 | return MAX44009_ERROR; 88 | } 89 | 90 | // 91 | // Set Continuous Mode bit in Configuration register. 92 | // 0 - Continuous mode disable. 93 | // 1 - Continuous mode enable. 94 | // 95 | MAX44009_STATUS MAX44009_ContinuousMode(uint8_t Enable) 96 | { 97 | uint8_t Config; 98 | 99 | Enable = (Enable? 1:0); 100 | 101 | if(MAX44009_OK == MAX44009_ReadConfigurationRegister(&Config)) 102 | { 103 | Config &= 0x7F; // Clear BIT7 104 | Config |= (Enable<<7); 105 | if(MAX44009_OK == MAX44009_WriteConfigurationRegister(Config)) 106 | { 107 | return MAX44009_OK; 108 | } 109 | } 110 | return MAX44009_ERROR; 111 | } 112 | 113 | // 114 | // Set Manual Convertion bit in Configuration register. 115 | // 0 - Manual Convertion mode disable. 116 | // 1 - Manual Convertion mode enable. 117 | // 118 | MAX44009_STATUS MAX44009_ManualConfiguration(uint8_t Enable) 119 | { 120 | uint8_t Config; 121 | 122 | Enable = (Enable? 1:0); 123 | 124 | if(MAX44009_OK == MAX44009_ReadConfigurationRegister(&Config)) 125 | { 126 | Config &= 0xBF; // Clear BIT6 127 | Config |= (Enable<<6); 128 | if(MAX44009_OK == MAX44009_WriteConfigurationRegister(Config)) 129 | { 130 | return MAX44009_OK; 131 | } 132 | } 133 | return MAX44009_ERROR; 134 | } 135 | 136 | // 137 | // Set Current Division Ratio bit in Configuration register. 138 | // 0 - Convertion Ratio disable. 139 | // 1 - Convertion Ratio enable. ADC Current is divided by 8. 140 | // 141 | MAX44009_STATUS MAX44009_CurrentDivisionRatio(uint8_t Enable) 142 | { 143 | uint8_t Config; 144 | 145 | Enable = (Enable? 1:0); 146 | 147 | if(MAX44009_OK == MAX44009_ReadConfigurationRegister(&Config)) 148 | { 149 | Config &= 0xF7; // Clear BIT3 150 | Config |= (Enable<<3); 151 | if(MAX44009_OK == MAX44009_WriteConfigurationRegister(Config)) 152 | { 153 | return MAX44009_OK; 154 | } 155 | } 156 | return MAX44009_ERROR; 157 | } 158 | 159 | // 160 | // Set signal integration time. 161 | // In automatic mode (MANUAL = 0), integration time is automatically selected by the on-chip algorithm to be either 162 | // 100ms/200ms/400ms/800ms. In manual mode, integration time can be varied by the user all the way from 6.25ms to 163 | // 800ms. See max44009_timer enum. 164 | // 165 | MAX44009_STATUS MAX44009_IntegrationTime(max44009_timer Timer) 166 | { 167 | uint8_t Config; 168 | 169 | if(Timer > 7) Timer = 7; 170 | 171 | if(MAX44009_OK == MAX44009_ReadConfigurationRegister(&Config)) 172 | { 173 | Config &= 0xF8; // Clear BIT[0:2] 174 | Config |= Timer; 175 | if(MAX44009_OK == MAX44009_WriteConfigurationRegister(Config)) 176 | { 177 | return MAX44009_OK; 178 | } 179 | } 180 | return MAX44009_ERROR; 181 | } 182 | 183 | // 184 | // Read converted value. 185 | // There is read only higher register which only allows to use lower resolution. 186 | // 187 | MAX44009_STATUS MAX44009_ReadLightLowResolution(float *Result) 188 | { 189 | uint8_t tmp; 190 | 191 | if(HAL_OK == HAL_I2C_Mem_Read(max44009_i2c, MAX44009_ADDRESS, MAX44009_LUX_HIGH_BYTE_REGISTER, 1, &tmp, 1, 10)) 192 | { 193 | uint8_t exponent = tmp>>4; 194 | uint32_t mantisa = tmp & 0x0F; 195 | mantisa <<= exponent; 196 | 197 | *Result = ((float)mantisa * 0.72); 198 | return MAX44009_OK; 199 | } 200 | return MAX44009_ERROR; 201 | } 202 | 203 | // 204 | // Read converted value. 205 | // There is read both value registers. Full resolution. 206 | // 207 | MAX44009_STATUS MAX44009_ReadLightHighResolution(float *Result) 208 | { 209 | uint8_t tmp[2]; 210 | 211 | if(HAL_OK == HAL_I2C_Mem_Read(max44009_i2c, MAX44009_ADDRESS, MAX44009_LUX_HIGH_BYTE_REGISTER, 1, tmp, 1, 10)) 212 | { 213 | if(HAL_OK == HAL_I2C_Mem_Read(max44009_i2c, MAX44009_ADDRESS, MAX44009_LUX_LOW_BYTE_REGISTER, 1, tmp+1, 1, 10)) 214 | { 215 | uint8_t exponent = tmp[0]>>4; 216 | uint32_t mantisa = ((tmp[0] & 0x0F)<<4) + (tmp[1] & 0x0F); 217 | mantisa <<= exponent; 218 | 219 | *Result = ((float)(mantisa) * 0.045); 220 | return MAX44009_OK; 221 | } 222 | } 223 | return MAX44009_ERROR; 224 | } 225 | 226 | // 227 | // Helper function. 228 | // Set Threshold register. 229 | // 230 | MAX44009_STATUS MAX44009_SetThreshold(uint8_t Register, float Threshold) 231 | { 232 | uint8_t result; 233 | uint32_t mantisa = (uint32_t)(round(Threshold * 22.222222)); 234 | uint8_t exponent = 0; 235 | 236 | while(mantisa > 255) 237 | { 238 | mantisa >>= 1; 239 | exponent++; 240 | } 241 | 242 | mantisa = (mantisa>>4) & 0x0F; 243 | exponent = (exponent<<4); 244 | result = exponent | mantisa; 245 | 246 | if(HAL_OK == HAL_I2C_Mem_Write(max44009_i2c, MAX44009_ADDRESS, Register, 1, &result, 1, 10)) 247 | { 248 | return MAX44009_OK; 249 | } 250 | return MAX44009_ERROR; 251 | } 252 | 253 | // 254 | // Set Upper Threshold register value. 255 | // If measurement is above this value, interrupt is generated. 256 | // 257 | MAX44009_STATUS MAX44009_SetUpperThreshold(float Threshold) 258 | { 259 | if(MAX44009_OK == MAX44009_SetThreshold(MAX44009_UPPER_THRESHOLD_REGISTER, Threshold)) 260 | { 261 | return MAX44009_OK; 262 | } 263 | return MAX44009_ERROR; 264 | } 265 | 266 | // 267 | // Set Lower Threshold register value. 268 | // If measurement is below this value, interrupt is generated. 269 | // 270 | MAX44009_STATUS MAX44009_SetLowerThreshold(float Threshold) 271 | { 272 | if(MAX44009_OK == MAX44009_SetThreshold(MAX44009_LOWER_THRESHOLD_REGISTER, Threshold)) 273 | { 274 | return MAX44009_OK; 275 | } 276 | return MAX44009_ERROR; 277 | } 278 | 279 | // 280 | // Set Threshold Timer register value. 281 | // Time in light value must be higher/lower than set Threshold registers to generate the interrupt. 282 | // 283 | MAX44009_STATUS MAX44009_SetThresholdTimer(uint8_t Timer) 284 | { 285 | if(HAL_OK == HAL_I2C_Mem_Write(max44009_i2c, MAX44009_ADDRESS, MAX44009_THRESHOLD_TIMER_REGISTER, 1, &Timer, 1, 10)) 286 | { 287 | return MAX44009_OK; 288 | } 289 | return MAX44009_ERROR; 290 | } 291 | 292 | 293 | 294 | -------------------------------------------------------------------------------- /Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : stm32f4xx_hal_msp.c 5 | * Description : This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | ** This notice applies to any and all portions of this file 9 | * that are not between comment pairs USER CODE BEGIN and 10 | * USER CODE END. Other portions of this file, whether 11 | * inserted by the user or by software development tools 12 | * are owned by their respective copyright owners. 13 | * 14 | * COPYRIGHT(c) 2018 STMicroelectronics 15 | * 16 | * Redistribution and use in source and binary forms, with or without modification, 17 | * are permitted provided that the following conditions are met: 18 | * 1. Redistributions of source code must retain the above copyright notice, 19 | * this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, 21 | * this list of conditions and the following disclaimer in the documentation 22 | * and/or other materials provided with the distribution. 23 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | ****************************************************************************** 39 | */ 40 | /* USER CODE END Header */ 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "main.h" 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | /* Private typedef -----------------------------------------------------------*/ 49 | /* USER CODE BEGIN TD */ 50 | 51 | /* USER CODE END TD */ 52 | 53 | /* Private define ------------------------------------------------------------*/ 54 | /* USER CODE BEGIN Define */ 55 | 56 | /* USER CODE END Define */ 57 | 58 | /* Private macro -------------------------------------------------------------*/ 59 | /* USER CODE BEGIN Macro */ 60 | 61 | /* USER CODE END Macro */ 62 | 63 | /* Private variables ---------------------------------------------------------*/ 64 | /* USER CODE BEGIN PV */ 65 | 66 | /* USER CODE END PV */ 67 | 68 | /* Private function prototypes -----------------------------------------------*/ 69 | /* USER CODE BEGIN PFP */ 70 | 71 | /* USER CODE END PFP */ 72 | 73 | /* External functions --------------------------------------------------------*/ 74 | /* USER CODE BEGIN ExternalFunctions */ 75 | 76 | /* USER CODE END ExternalFunctions */ 77 | 78 | /* USER CODE BEGIN 0 */ 79 | 80 | /* USER CODE END 0 */ 81 | /** 82 | * Initializes the Global MSP. 83 | */ 84 | void HAL_MspInit(void) 85 | { 86 | /* USER CODE BEGIN MspInit 0 */ 87 | 88 | /* USER CODE END MspInit 0 */ 89 | 90 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 91 | __HAL_RCC_PWR_CLK_ENABLE(); 92 | 93 | /* System interrupt init*/ 94 | 95 | /* USER CODE BEGIN MspInit 1 */ 96 | 97 | /* USER CODE END MspInit 1 */ 98 | } 99 | 100 | /* USER CODE BEGIN 1 */ 101 | 102 | /* USER CODE END 1 */ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /Src/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2018 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* USER CODE END Header */ 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "main.h" 38 | #include "stm32f4xx_it.h" 39 | /* Private includes ----------------------------------------------------------*/ 40 | /* USER CODE BEGIN Includes */ 41 | /* USER CODE END Includes */ 42 | 43 | /* Private typedef -----------------------------------------------------------*/ 44 | /* USER CODE BEGIN TD */ 45 | 46 | /* USER CODE END TD */ 47 | 48 | /* Private define ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN PD */ 50 | 51 | /* USER CODE END PD */ 52 | 53 | /* Private macro -------------------------------------------------------------*/ 54 | /* USER CODE BEGIN PM */ 55 | 56 | /* USER CODE END PM */ 57 | 58 | /* Private variables ---------------------------------------------------------*/ 59 | /* USER CODE BEGIN PV */ 60 | 61 | /* USER CODE END PV */ 62 | 63 | /* Private function prototypes -----------------------------------------------*/ 64 | /* USER CODE BEGIN PFP */ 65 | 66 | /* USER CODE END PFP */ 67 | 68 | /* Private user code ---------------------------------------------------------*/ 69 | /* USER CODE BEGIN 0 */ 70 | 71 | /* USER CODE END 0 */ 72 | 73 | /* External variables --------------------------------------------------------*/ 74 | extern DMA_HandleTypeDef hdma_adc1; 75 | /* USER CODE BEGIN EV */ 76 | 77 | /* USER CODE END EV */ 78 | 79 | /******************************************************************************/ 80 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 81 | /******************************************************************************/ 82 | /** 83 | * @brief This function handles Non maskable interrupt. 84 | */ 85 | void NMI_Handler(void) 86 | { 87 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 88 | 89 | /* USER CODE END NonMaskableInt_IRQn 0 */ 90 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 91 | 92 | /* USER CODE END NonMaskableInt_IRQn 1 */ 93 | } 94 | 95 | /** 96 | * @brief This function handles Hard fault interrupt. 97 | */ 98 | void HardFault_Handler(void) 99 | { 100 | /* USER CODE BEGIN HardFault_IRQn 0 */ 101 | 102 | /* USER CODE END HardFault_IRQn 0 */ 103 | while (1) 104 | { 105 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 106 | /* USER CODE END W1_HardFault_IRQn 0 */ 107 | } 108 | } 109 | 110 | /** 111 | * @brief This function handles Memory management fault. 112 | */ 113 | void MemManage_Handler(void) 114 | { 115 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 116 | 117 | /* USER CODE END MemoryManagement_IRQn 0 */ 118 | while (1) 119 | { 120 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 121 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 122 | } 123 | } 124 | 125 | /** 126 | * @brief This function handles Pre-fetch fault, memory access fault. 127 | */ 128 | void BusFault_Handler(void) 129 | { 130 | /* USER CODE BEGIN BusFault_IRQn 0 */ 131 | 132 | /* USER CODE END BusFault_IRQn 0 */ 133 | while (1) 134 | { 135 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 136 | /* USER CODE END W1_BusFault_IRQn 0 */ 137 | } 138 | } 139 | 140 | /** 141 | * @brief This function handles Undefined instruction or illegal state. 142 | */ 143 | void UsageFault_Handler(void) 144 | { 145 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 146 | 147 | /* USER CODE END UsageFault_IRQn 0 */ 148 | while (1) 149 | { 150 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 151 | /* USER CODE END W1_UsageFault_IRQn 0 */ 152 | } 153 | } 154 | 155 | /** 156 | * @brief This function handles System service call via SWI instruction. 157 | */ 158 | void SVC_Handler(void) 159 | { 160 | /* USER CODE BEGIN SVCall_IRQn 0 */ 161 | 162 | /* USER CODE END SVCall_IRQn 0 */ 163 | /* USER CODE BEGIN SVCall_IRQn 1 */ 164 | 165 | /* USER CODE END SVCall_IRQn 1 */ 166 | } 167 | 168 | /** 169 | * @brief This function handles Debug monitor. 170 | */ 171 | void DebugMon_Handler(void) 172 | { 173 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 174 | 175 | /* USER CODE END DebugMonitor_IRQn 0 */ 176 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 177 | 178 | /* USER CODE END DebugMonitor_IRQn 1 */ 179 | } 180 | 181 | /** 182 | * @brief This function handles Pendable request for system service. 183 | */ 184 | void PendSV_Handler(void) 185 | { 186 | /* USER CODE BEGIN PendSV_IRQn 0 */ 187 | 188 | /* USER CODE END PendSV_IRQn 0 */ 189 | /* USER CODE BEGIN PendSV_IRQn 1 */ 190 | 191 | /* USER CODE END PendSV_IRQn 1 */ 192 | } 193 | 194 | /** 195 | * @brief This function handles System tick timer. 196 | */ 197 | void SysTick_Handler(void) 198 | { 199 | /* USER CODE BEGIN SysTick_IRQn 0 */ 200 | 201 | /* USER CODE END SysTick_IRQn 0 */ 202 | HAL_IncTick(); 203 | /* USER CODE BEGIN SysTick_IRQn 1 */ 204 | 205 | /* USER CODE END SysTick_IRQn 1 */ 206 | } 207 | 208 | /******************************************************************************/ 209 | /* STM32F4xx Peripheral Interrupt Handlers */ 210 | /* Add here the Interrupt Handlers for the used peripherals. */ 211 | /* For the available peripheral interrupt handler names, */ 212 | /* please refer to the startup file (startup_stm32f4xx.s). */ 213 | /******************************************************************************/ 214 | 215 | /** 216 | * @brief This function handles EXTI line[15:10] interrupts. 217 | */ 218 | void EXTI15_10_IRQHandler(void) 219 | { 220 | /* USER CODE BEGIN EXTI15_10_IRQn 0 */ 221 | 222 | /* USER CODE END EXTI15_10_IRQn 0 */ 223 | HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10); 224 | /* USER CODE BEGIN EXTI15_10_IRQn 1 */ 225 | 226 | /* USER CODE END EXTI15_10_IRQn 1 */ 227 | } 228 | 229 | /** 230 | * @brief This function handles DMA2 stream0 global interrupt. 231 | */ 232 | void DMA2_Stream0_IRQHandler(void) 233 | { 234 | /* USER CODE BEGIN DMA2_Stream0_IRQn 0 */ 235 | 236 | /* USER CODE END DMA2_Stream0_IRQn 0 */ 237 | HAL_DMA_IRQHandler(&hdma_adc1); 238 | /* USER CODE BEGIN DMA2_Stream0_IRQn 1 */ 239 | 240 | /* USER CODE END DMA2_Stream0_IRQn 1 */ 241 | } 242 | 243 | /* USER CODE BEGIN 1 */ 244 | 245 | /* USER CODE END 1 */ 246 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 247 | -------------------------------------------------------------------------------- /Src/temt6000.c: -------------------------------------------------------------------------------- 1 | /* 2 | * temt6000.c 3 | * 4 | * The MIT License. 5 | * Created on: 19.01.2019 6 | * Author: Mateusz Salamon 7 | * www.msalamon.pl 8 | * mateusz@msalamon.pl 9 | * 10 | * https://msalamon.pl/pomiar-natezenia-swiatla-z-wykorzystaniem-stm32/ 11 | * https://github.com/lamik/Light_Sensors_STM32 12 | */ 13 | 14 | #include "main.h" 15 | #include "adc.h" 16 | 17 | #include "temt6000.h" 18 | 19 | ADC_HandleTypeDef *temt6000_adc; 20 | 21 | volatile uint16_t AdcValue[TEMT6000_ADC_SAMPLES]; 22 | 23 | TEMT6000_STATUS TEMT6000_Init(ADC_HandleTypeDef *hadc) 24 | { 25 | temt6000_adc = hadc; 26 | 27 | if(HAL_OK == HAL_ADC_Start_DMA(temt6000_adc, (uint32_t*)AdcValue, TEMT6000_ADC_SAMPLES)) 28 | return TEMT6000_OK; 29 | 30 | return TEMT6000_ERROR; 31 | } 32 | 33 | TEMT6000_STATUS TEMT6000_ReadLight(float *Result) 34 | { 35 | uint32_t AdcAverage; 36 | uint8_t i; 37 | 38 | AdcAverage = 0; 39 | 40 | for(i = 0; i < TEMT6000_ADC_SAMPLES; i++) 41 | { 42 | AdcAverage += AdcValue[i]; 43 | } 44 | 45 | AdcAverage /= TEMT6000_ADC_SAMPLES; 46 | 47 | *Result = ((((float)AdcAverage / (float)TEMT6000_ADC_MAX_VALUE) * (float)TEMT6000_POWER_SUPPLY) / TEMT6000_RESISTOR_OHMS) * 2000000.0; 48 | 49 | return TEMT6000_OK; 50 | } 51 | -------------------------------------------------------------------------------- /Src/usart.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.c 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Includes ------------------------------------------------------------------*/ 41 | #include "usart.h" 42 | 43 | /* USER CODE BEGIN 0 */ 44 | 45 | /* USER CODE END 0 */ 46 | 47 | UART_HandleTypeDef huart2; 48 | 49 | /* USART2 init function */ 50 | 51 | void MX_USART2_UART_Init(void) 52 | { 53 | 54 | huart2.Instance = USART2; 55 | huart2.Init.BaudRate = 115200; 56 | huart2.Init.WordLength = UART_WORDLENGTH_8B; 57 | huart2.Init.StopBits = UART_STOPBITS_1; 58 | huart2.Init.Parity = UART_PARITY_NONE; 59 | huart2.Init.Mode = UART_MODE_TX_RX; 60 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 61 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 62 | if (HAL_UART_Init(&huart2) != HAL_OK) 63 | { 64 | Error_Handler(); 65 | } 66 | 67 | } 68 | 69 | void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) 70 | { 71 | 72 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 73 | if(uartHandle->Instance==USART2) 74 | { 75 | /* USER CODE BEGIN USART2_MspInit 0 */ 76 | 77 | /* USER CODE END USART2_MspInit 0 */ 78 | /* USART2 clock enable */ 79 | __HAL_RCC_USART2_CLK_ENABLE(); 80 | 81 | __HAL_RCC_GPIOA_CLK_ENABLE(); 82 | /**USART2 GPIO Configuration 83 | PA2 ------> USART2_TX 84 | PA3 ------> USART2_RX 85 | */ 86 | GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; 87 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 88 | GPIO_InitStruct.Pull = GPIO_PULLUP; 89 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 90 | GPIO_InitStruct.Alternate = GPIO_AF7_USART2; 91 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 92 | 93 | /* USER CODE BEGIN USART2_MspInit 1 */ 94 | 95 | /* USER CODE END USART2_MspInit 1 */ 96 | } 97 | } 98 | 99 | void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) 100 | { 101 | 102 | if(uartHandle->Instance==USART2) 103 | { 104 | /* USER CODE BEGIN USART2_MspDeInit 0 */ 105 | 106 | /* USER CODE END USART2_MspDeInit 0 */ 107 | /* Peripheral clock disable */ 108 | __HAL_RCC_USART2_CLK_DISABLE(); 109 | 110 | /**USART2 GPIO Configuration 111 | PA2 ------> USART2_TX 112 | PA3 ------> USART2_RX 113 | */ 114 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); 115 | 116 | /* USER CODE BEGIN USART2_MspDeInit 1 */ 117 | 118 | /* USER CODE END USART2_MspDeInit 1 */ 119 | } 120 | } 121 | 122 | /* USER CODE BEGIN 1 */ 123 | 124 | /* USER CODE END 1 */ 125 | 126 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 127 | -------------------------------------------------------------------------------- /syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : syscalls.c 5 | ** 6 | ** Abstract : System Workbench Minimal System calls file 7 | ** 8 | ** For more information about which c-functions 9 | ** need which of these lowlevel functions 10 | ** please consult the Newlib libc-manual 11 | ** 12 | ** Environment : System Workbench for MCU 13 | ** 14 | ** Distribution: The file is distributed as is without any warranty 15 | ** of any kind. 16 | ** 17 | ***************************************************************************** 18 | ** 19 | **

© COPYRIGHT(c) 2014 Ac6

20 | ** 21 | ** Redistribution and use in source and binary forms, with or without modification, 22 | ** are permitted provided that the following conditions are met: 23 | ** 1. Redistributions of source code must retain the above copyright notice, 24 | ** this list of conditions and the following disclaimer. 25 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 26 | ** this list of conditions and the following disclaimer in the documentation 27 | ** and/or other materials provided with the distribution. 28 | ** 3. Neither the name of Ac6 nor the names of its contributors 29 | ** may be used to endorse or promote products derived from this software 30 | ** without specific prior written permission. 31 | ** 32 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 33 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 36 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 38 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 39 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 40 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | ** 43 | ***************************************************************************** 44 | */ 45 | 46 | /* Includes */ 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | 57 | /* Variables */ 58 | //#undef errno 59 | extern int errno; 60 | extern int __io_putchar(int ch) __attribute__((weak)); 61 | extern int __io_getchar(void) __attribute__((weak)); 62 | 63 | register char * stack_ptr asm("sp"); 64 | 65 | char *__env[1] = { 0 }; 66 | char **environ = __env; 67 | 68 | 69 | /* Functions */ 70 | void initialise_monitor_handles() 71 | { 72 | } 73 | 74 | int _getpid(void) 75 | { 76 | return 1; 77 | } 78 | 79 | int _kill(int pid, int sig) 80 | { 81 | errno = EINVAL; 82 | return -1; 83 | } 84 | 85 | void _exit (int status) 86 | { 87 | _kill(status, -1); 88 | while (1) {} /* Make sure we hang here */ 89 | } 90 | 91 | int _read (int file, char *ptr, int len) 92 | { 93 | int DataIdx; 94 | 95 | for (DataIdx = 0; DataIdx < len; DataIdx++) 96 | { 97 | *ptr++ = __io_getchar(); 98 | } 99 | 100 | return len; 101 | } 102 | 103 | int _write(int file, char *ptr, int len) 104 | { 105 | int DataIdx; 106 | 107 | for (DataIdx = 0; DataIdx < len; DataIdx++) 108 | { 109 | __io_putchar(*ptr++); 110 | } 111 | return len; 112 | } 113 | 114 | caddr_t _sbrk(int incr) 115 | { 116 | extern char end asm("end"); 117 | static char *heap_end; 118 | char *prev_heap_end; 119 | 120 | if (heap_end == 0) 121 | heap_end = &end; 122 | 123 | prev_heap_end = heap_end; 124 | if (heap_end + incr > stack_ptr) 125 | { 126 | // write(1, "Heap and stack collision\n", 25); 127 | // abort(); 128 | errno = ENOMEM; 129 | return (caddr_t) -1; 130 | } 131 | 132 | heap_end += incr; 133 | 134 | return (caddr_t) prev_heap_end; 135 | } 136 | 137 | int _close(int file) 138 | { 139 | return -1; 140 | } 141 | 142 | 143 | int _fstat(int file, struct stat *st) 144 | { 145 | st->st_mode = S_IFCHR; 146 | return 0; 147 | } 148 | 149 | int _isatty(int file) 150 | { 151 | return 1; 152 | } 153 | 154 | int _lseek(int file, int ptr, int dir) 155 | { 156 | return 0; 157 | } 158 | 159 | int _open(char *path, int flags, ...) 160 | { 161 | /* Pretend like we always fail */ 162 | return -1; 163 | } 164 | 165 | int _wait(int *status) 166 | { 167 | errno = ECHILD; 168 | return -1; 169 | } 170 | 171 | int _unlink(char *name) 172 | { 173 | errno = ENOENT; 174 | return -1; 175 | } 176 | 177 | int _times(struct tms *buf) 178 | { 179 | return -1; 180 | } 181 | 182 | int _stat(char *file, struct stat *st) 183 | { 184 | st->st_mode = S_IFCHR; 185 | return 0; 186 | } 187 | 188 | int _link(char *old, char *new) 189 | { 190 | errno = EMLINK; 191 | return -1; 192 | } 193 | 194 | int _fork(void) 195 | { 196 | errno = EAGAIN; 197 | return -1; 198 | } 199 | 200 | int _execve(char *name, char **argv, char **env) 201 | { 202 | errno = ENOMEM; 203 | return -1; 204 | } 205 | --------------------------------------------------------------------------------