├── design ├── 3DCapacitiveSensor.sch.pdf ├── 3DCapacitiveSensor.kicad_pcb.pdf ├── 3DCapacitiveSensor.pro ├── 3DCapacitiveSensor.sch └── 3DCapacitiveSensor.net ├── mcu ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F0xx │ │ │ │ └── Include │ │ │ │ ├── stm32f0xx.h │ │ │ │ ├── stm32f072xb.h │ │ │ │ └── system_stm32f0xx.h │ │ └── Include │ │ │ ├── cmsis_version.h │ │ │ ├── tz_context.h │ │ │ ├── cmsis_compiler.h │ │ │ └── mpu_armv8.h │ └── STM32F0xx_HAL_Driver │ │ ├── Inc │ │ ├── stm32f0xx_hal_cortex.h │ │ ├── stm32f0xx_hal_pwr.h │ │ ├── stm32f0xx_hal_def.h │ │ ├── stm32f0xx_hal_i2c_ex.h │ │ ├── stm32f0xx_hal_tim_ex.h │ │ └── stm32f0xx_hal_flash.h │ │ └── Src │ │ ├── stm32f0xx_hal_pwr_ex.c │ │ └── stm32f0xx_hal_i2c_ex.c ├── format-source.sh ├── MDK-ARM │ ├── RTE │ │ └── _3DCapacitiveSensor │ │ │ └── RTE_Components.h │ └── startup_stm32f072xb.s ├── Core │ ├── Inc │ │ ├── motor.h │ │ ├── stm32f0xx_it.h │ │ └── main.h │ └── Src │ │ ├── stm32f0xx_hal_msp.c │ │ ├── stm32f0xx_it.c │ │ ├── motor.c │ │ └── system_stm32f0xx.c ├── 3DCapacitiveSensor.ioc └── .mxproject ├── client ├── View │ ├── View.csproj │ ├── ViewController.cs │ ├── InitialForm.resx │ ├── InitialForm.cs │ ├── CursorController.cs │ └── InitialForm.Designer.cs ├── Controller │ ├── Controller.csproj │ ├── SerialInterface.cs │ └── Controller.cs └── Client3DCapacitiveSensor.sln ├── README.md ├── .gitignore └── .gitattributes /design/3DCapacitiveSensor.sch.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Petersoj/STM32-3DCapacitiveSensor/main/design/3DCapacitiveSensor.sch.pdf -------------------------------------------------------------------------------- /design/3DCapacitiveSensor.kicad_pcb.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Petersoj/STM32-3DCapacitiveSensor/main/design/3DCapacitiveSensor.kicad_pcb.pdf -------------------------------------------------------------------------------- /mcu/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Petersoj/STM32-3DCapacitiveSensor/main/mcu/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h -------------------------------------------------------------------------------- /mcu/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f072xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Petersoj/STM32-3DCapacitiveSensor/main/mcu/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f072xb.h -------------------------------------------------------------------------------- /mcu/format-source.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find Core/ -iname *.c -o -iname *.h | xargs clang-format -i --style="{BasedOnStyle: LLVM, ColumnLimit: 100, IndentWidth: 4, IndentCaseLabels: true}" 3 | -------------------------------------------------------------------------------- /client/View/View.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Library 5 | net5.0-windows 6 | true 7 | 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 3DCapacitiveSensor 2 | 3 | This project uses the STM32F072RB MCU on the 32F072BDISCOVERY board and a large "3D" capacitor to measure the XYZ coordinates of a user's hand in physical space so that a user can move/click a computer mouse without touching anything. This project was inspired by [this](https://www.youtube.com/watch?v=ikD_3Vemkf0) video. 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | .DS_Store 3 | 4 | # KiCad 5 | fp-info-cache 6 | *-cache.lib 7 | *.kicad_pcb-bak 8 | *.sch-bak 9 | 10 | # Visual Studio 11 | *.csproj.user 12 | client/**/obj/ 13 | client/**/.vs/ 14 | client/**/bin/ 15 | 16 | # uVision 17 | mcu/MDK-ARM/DebugConfig/ 18 | mcu/MDK-ARM/3DCapacitiveSensor/ 19 | *.uvoptx 20 | *.uvguix.* 21 | *.o 22 | *.d 23 | *.axf 24 | *.build_log.* 25 | *.hex 26 | *.htm 27 | *.lnp 28 | *.dep 29 | *.lst 30 | -------------------------------------------------------------------------------- /client/Controller/Controller.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0-windows 5 | WinExe 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /mcu/MDK-ARM/RTE/_3DCapacitiveSensor/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: '3DCapacitiveSensor' 7 | * Target: '3DCapacitiveSensor' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f0xx.h" 18 | 19 | 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # https://www.gitattributes.io/api/java 2 | # 3 | # Handle line endings automatically for files detected as text 4 | # and leave all files detected as binary untouched. 5 | * text=auto 6 | 7 | # 8 | # The above will handle all files NOT found below 9 | # 10 | # These files are text and should be normalized (Convert crlf => lf) 11 | *.css text 12 | *.df text 13 | *.htm text 14 | *.html text 15 | *.java text 16 | *.js text 17 | *.json text 18 | *.jsp text 19 | *.jspf text 20 | *.jspx text 21 | *.properties text 22 | *.sh text 23 | *.tld text 24 | *.txt text 25 | *.tag text 26 | *.tagx text 27 | *.xml text 28 | *.yml text 29 | 30 | # Declare files that will always have CRLF line endings on checkout. 31 | *.sln text eol=crlf 32 | *.bat text eol=crlf 33 | 34 | # These files are binary and should be left untouched 35 | # (binary is a macro for -text -diff) 36 | *.class binary 37 | *.dll binary 38 | *.ear binary 39 | *.gif binary 40 | *.ico binary 41 | *.jar binary 42 | *.jpg binary 43 | *.jpeg binary 44 | *.png binary 45 | *.so binary 46 | *.war binary 47 | 48 | -------------------------------------------------------------------------------- /client/Client3DCapacitiveSensor.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31129.286 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "View", "View\View.csproj", "{1FD30E38-7A9B-4799-BB24-3519C3F564E0}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controller", "Controller\Controller.csproj", "{DBCD3266-FAB9-43C2-89A5-FD08BDDA76DE}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1FD30E38-7A9B-4799-BB24-3519C3F564E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {1FD30E38-7A9B-4799-BB24-3519C3F564E0}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {1FD30E38-7A9B-4799-BB24-3519C3F564E0}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {1FD30E38-7A9B-4799-BB24-3519C3F564E0}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {DBCD3266-FAB9-43C2-89A5-FD08BDDA76DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {DBCD3266-FAB9-43C2-89A5-FD08BDDA76DE}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {DBCD3266-FAB9-43C2-89A5-FD08BDDA76DE}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {DBCD3266-FAB9-43C2-89A5-FD08BDDA76DE}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {DD9A37DF-5560-43B5-91F4-8EBB14803BF8} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /mcu/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /mcu/Core/Inc/motor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MOTOR_H_ 3 | #define MOTOR_H_ 4 | 5 | #include "stm32f0xx.h" 6 | #include 7 | #include 8 | 9 | /* ------------------------------------------------------------------------------------------------------------- 10 | * Global Variable and Type Declarations 11 | * ------------------------------------------------------------------------------------------------------------- 12 | */ 13 | extern volatile int16_t error_integral; // Integrated error signal 14 | extern volatile uint8_t duty_cycle; // Output PWM duty cycle 15 | extern volatile int16_t target_rpm; // Desired speed target 16 | extern volatile int16_t motor_speed; // Measured motor speed 17 | extern volatile int8_t adc_value; // ADC measured motor current 18 | extern volatile int16_t error; // Speed error signal 19 | extern volatile uint8_t Kp; // Proportional gain 20 | extern volatile uint8_t Ki; // Integral gain 21 | 22 | /* ------------------------------------------------------------------------------------------------------------- 23 | * Motor Control and Initialization Functions 24 | * ------------------------------------------------------------------------------------------------------------- 25 | */ 26 | 27 | // Sets up the entire motor drive system 28 | void motor_init(void); 29 | 30 | // Set the duty cycle of the PWM, accepts (0-100) 31 | void pwm_setDutyCycle(uint8_t duty); 32 | 33 | // PI control code is called within a timer interrupt 34 | void PI_update(void); 35 | 36 | /* ------------------------------------------------------------------------------------------------------------- 37 | * Internal-Use Initialization Functions 38 | * ------------------------------------------------------------------------------------------------------------- 39 | */ 40 | 41 | // Sets up the PWM and direction signals to drive the H-Bridge 42 | void pwm_init(void); 43 | 44 | // Sets up encoder interface to read motor speed 45 | void encoder_init(void); 46 | 47 | // Sets up ADC to measure motor current 48 | void ADC_init(void); 49 | 50 | #endif /* MOTOR_H_ */ 51 | -------------------------------------------------------------------------------- /client/View/ViewController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace Client3DCapacitiveSensor.View { 5 | 6 | /// 7 | /// Controls the view. 8 | /// 9 | public class ViewController { 10 | 11 | private InitialForm initialForm; 12 | private bool isErrorShown; 13 | 14 | /// 15 | /// Instantiates a new . 16 | /// 17 | /// 18 | /// 19 | public ViewController(InitialForm.StartButtonClickHandler startButtonClickHandler, 20 | InitialForm.StopButtonClickHandler stopButtonClickHandler) { 21 | Application.SetHighDpiMode(HighDpiMode.SystemAware); 22 | Application.EnableVisualStyles(); 23 | Application.SetCompatibleTextRenderingDefault(false); 24 | 25 | initialForm = new InitialForm(startButtonClickHandler, stopButtonClickHandler); 26 | isErrorShown = false; 27 | } 28 | 29 | /// 30 | /// Starts the synchronously. 31 | /// 32 | public void Start() { 33 | Application.Run(initialForm); 34 | } 35 | 36 | /// 37 | /// Shows an error to the user. Not thread safe. 38 | /// 39 | /// 40 | /// 41 | public bool ShowError(string message) { 42 | if (isErrorShown) { 43 | Console.WriteLine(""); 44 | return false; 45 | } 46 | 47 | isErrorShown = true; 48 | initialForm.Invoke(new Action(() => { 49 | MessageBox.Show(message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); 50 | isErrorShown = false; 51 | })); 52 | return true; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /mcu/Core/Inc/stm32f0xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f0xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F0xx_IT_H 23 | #define __STM32F0xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void SVC_Handler(void); 53 | void PendSV_Handler(void); 54 | void SysTick_Handler(void); 55 | /* USER CODE BEGIN EFP */ 56 | 57 | /* USER CODE END EFP */ 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* __STM32F0xx_IT_H */ 64 | 65 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 66 | -------------------------------------------------------------------------------- /mcu/Core/Src/stm32f0xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f0xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) { 65 | /* USER CODE BEGIN MspInit 0 */ 66 | 67 | /* USER CODE END MspInit 0 */ 68 | 69 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 70 | __HAL_RCC_PWR_CLK_ENABLE(); 71 | 72 | /* System interrupt init*/ 73 | 74 | /* USER CODE BEGIN MspInit 1 */ 75 | 76 | /* USER CODE END MspInit 1 */ 77 | } 78 | 79 | /* USER CODE BEGIN 1 */ 80 | 81 | /* USER CODE END 1 */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /client/View/InitialForm.resx: -------------------------------------------------------------------------------- 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 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | text/microsoft-resx 50 | 51 | 52 | 2.0 53 | 54 | 55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 56 | 57 | 58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 59 | 60 | -------------------------------------------------------------------------------- /mcu/Drivers/CMSIS/Device/ST/STM32F0xx/Include/system_stm32f0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M0 Device System Source File for STM32F0xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup CMSIS 21 | * @{ 22 | */ 23 | 24 | /** @addtogroup stm32f0xx_system 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Define to prevent recursive inclusion 30 | */ 31 | #ifndef __SYSTEM_STM32F0XX_H 32 | #define __SYSTEM_STM32F0XX_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** @addtogroup STM32F0xx_System_Includes 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @} 44 | */ 45 | 46 | 47 | /** @addtogroup STM32F0xx_System_Exported_types 48 | * @{ 49 | */ 50 | /* This variable is updated in three ways: 51 | 1) by calling CMSIS function SystemCoreClockUpdate() 52 | 3) by calling HAL API function HAL_RCC_GetHCLKFreq() 53 | 3) by calling HAL API function HAL_RCC_ClockConfig() 54 | Note: If you use this function to configure the system clock; then there 55 | is no need to call the 2 first functions listed above, since SystemCoreClock 56 | variable is updated automatically. 57 | */ 58 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 59 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 60 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F0xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F0xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F0xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F0XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /mcu/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /mcu/3DCapacitiveSensor.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | File.Version=6 3 | GPIO.groupedBy= 4 | KeepUserPlacement=false 5 | Mcu.Family=STM32F0 6 | Mcu.IP0=NVIC 7 | Mcu.IP1=RCC 8 | Mcu.IP2=SYS 9 | Mcu.IPNb=3 10 | Mcu.Name=STM32F072R(8-B)Tx 11 | Mcu.Package=LQFP64 12 | Mcu.Pin0=VP_SYS_VS_Systick 13 | Mcu.PinsNb=1 14 | Mcu.ThirdPartyNb=0 15 | Mcu.UserConstants= 16 | Mcu.UserName=STM32F072RBTx 17 | MxCube.Version=6.1.1 18 | MxDb.Version=DB.6.0.10 19 | NVIC.ForceEnableDMAVector=true 20 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 21 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 22 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 23 | NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false 24 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true 25 | PinOutPanel.RotationAngle=0 26 | ProjectManager.AskForMigrate=true 27 | ProjectManager.BackupPrevious=false 28 | ProjectManager.CompilerOptimize=6 29 | ProjectManager.ComputerToolchain=false 30 | ProjectManager.CoupleFile=false 31 | ProjectManager.CustomerFirmwarePackage= 32 | ProjectManager.DefaultFWLocation=true 33 | ProjectManager.DeletePrevious=true 34 | ProjectManager.DeviceId=STM32F072RBTx 35 | ProjectManager.FirmwarePackage=STM32Cube FW_F0 V1.11.2 36 | ProjectManager.FreePins=false 37 | ProjectManager.HalAssertFull=false 38 | ProjectManager.HeapSize=0x200 39 | ProjectManager.KeepUserCode=true 40 | ProjectManager.LastFirmware=true 41 | ProjectManager.LibraryCopy=1 42 | ProjectManager.MainLocation=Core/Src 43 | ProjectManager.NoMain=false 44 | ProjectManager.PreviousToolchain= 45 | ProjectManager.ProjectBuild=false 46 | ProjectManager.ProjectFileName=3DCapacitiveSensor.ioc 47 | ProjectManager.ProjectName=3DCapacitiveSensor 48 | ProjectManager.RegisterCallBack= 49 | ProjectManager.StackSize=0x400 50 | ProjectManager.TargetToolchain=MDK-ARM V5 51 | ProjectManager.ToolChainLocation= 52 | ProjectManager.UnderRoot=false 53 | ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false 54 | RCC.AHBFreq_Value=48000000 55 | RCC.APB1Freq_Value=48000000 56 | RCC.APB1TimFreq_Value=48000000 57 | RCC.CECFreq_Value=32786.88524590164 58 | RCC.FCLKCortexFreq_Value=48000000 59 | RCC.FamilyName=M 60 | RCC.HCLKFreq_Value=48000000 61 | RCC.HSICECFreq_Value=32786.88524590164 62 | RCC.I2SFreq_Value=48000000 63 | RCC.IPParameters=AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,CECFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSICECFreq_Value,I2SFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USART1Freq_Value,USART2Freq_Value,VCOOutput2Freq_Value 64 | RCC.MCOFreq_Value=48000000 65 | RCC.PLLCLKFreq_Value=48000000 66 | RCC.PLLMCOFreq_Value=48000000 67 | RCC.PLLMUL=RCC_PLL_MUL6 68 | RCC.SYSCLKFreq_VALUE=48000000 69 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 70 | RCC.TimSysFreq_Value=48000000 71 | RCC.USART1Freq_Value=48000000 72 | RCC.USART2Freq_Value=48000000 73 | RCC.VCOOutput2Freq_Value=8000000 74 | VP_SYS_VS_Systick.Mode=SysTick 75 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 76 | board=custom 77 | -------------------------------------------------------------------------------- /client/Controller/SerialInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO.Ports; 3 | 4 | namespace Client3DCapacitiveSensor.Controller { 5 | 6 | /// 7 | /// This class is for easy interfacing with an asynchronously. 8 | /// 9 | public class SerialInterface { 10 | 11 | /// 12 | /// The COM port number. 13 | /// 14 | public string COMPortNumber { get; private set; } 15 | /// 16 | /// The serial baud rate. 17 | /// 18 | public int BaudRate { get; private set; } 19 | /// 20 | /// The serial parity. 21 | /// 22 | public Parity Parity { get; private set; } 23 | /// 24 | /// The number of data bits. 25 | /// 26 | public int DataBits { get; private set; } 27 | /// 28 | /// The number of stop bits. 29 | /// 30 | public StopBits StopBits { get; private set; } 31 | 32 | private readonly SerialPort serialPort; 33 | 34 | /// 35 | /// Instantiates a new . 36 | /// 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// 42 | public SerialInterface(string comPortNumber, int baudRate, Parity parity, int dataBits, StopBits stopBits) { 43 | COMPortNumber = comPortNumber; 44 | BaudRate = baudRate; 45 | Parity = parity; 46 | DataBits = dataBits; 47 | StopBits = stopBits; 48 | 49 | // Create and configure 'serialPort' 50 | serialPort = new SerialPort("COM" + COMPortNumber, BaudRate, Parity, DataBits, StopBits); 51 | serialPort.NewLine = "\n"; 52 | serialPort.ReadTimeout = 5 * 60 * 1000; // Timeout on read after not seeing data for 5 minutes. 53 | } 54 | 55 | /// 56 | /// Establishes a serial interface connection. 57 | /// 58 | /// Thrown for a variety of exceptions. 59 | public void Start() { 60 | serialPort.Open(); 61 | } 62 | 63 | /// 64 | /// Closes the serial interface connection. 65 | /// 66 | /// Thrown for s 67 | public void Stop() { 68 | if (serialPort.IsOpen) { 69 | serialPort.Close(); 70 | } 71 | } 72 | 73 | /// 74 | /// Reads a line (a string ending with '\n' (LF)) from the . 75 | /// 76 | /// The line read from the 77 | /// Thrown for a variety of exceptions. 78 | public string ReadLine() { 79 | return serialPort.ReadLine(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /client/View/InitialForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace Client3DCapacitiveSensor.View { 5 | 6 | /// 7 | /// is the that prompts the user for data at the 8 | /// start of the program. 9 | /// 10 | public partial class InitialForm : Form { 11 | 12 | /// 13 | /// Handles the start button click. 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// True if the start was sucessful. 21 | public delegate bool StartButtonClickHandler(string comPortNumber, string baudRate, string parity, 22 | string dataBits, string stopBits); 23 | 24 | /// 25 | /// Handles the stop button click. 26 | /// 27 | /// True if the stop was sucessful. 28 | public delegate bool StopButtonClickHandler(); 29 | 30 | private static readonly string START_BUTTON_START_TEXT = "Start"; 31 | private static readonly string START_BUTTON_STOP_TEXT = "Stop"; 32 | 33 | private StartButtonClickHandler startButtonClickHandler; 34 | private StopButtonClickHandler stopButtonClickHandler; 35 | 36 | /// 37 | /// Instantiates a new . 38 | /// 39 | /// 40 | /// 41 | public InitialForm(StartButtonClickHandler startButtonClickHandler, StopButtonClickHandler stopButtonClickHandler) { 42 | this.startButtonClickHandler = startButtonClickHandler; 43 | this.stopButtonClickHandler = stopButtonClickHandler; 44 | 45 | InitializeComponent(); 46 | 47 | // Set default values 48 | baudRateTextBox.Text = "115200"; 49 | parityComboBox.SelectedIndex = 0; 50 | dataBitsTextBox.Text = "8"; 51 | stopBitsComboBox.SelectedIndex = 0; 52 | } 53 | 54 | /// 55 | /// Handles click for . 56 | /// 57 | /// 58 | /// 59 | private void OnStartButtonClick(object sender, EventArgs eventArgs) { 60 | if (startButton.Text.Equals(START_BUTTON_START_TEXT)) { 61 | bool startSuccess = startButtonClickHandler.Invoke( 62 | comPortNumberTextBox.Text, 63 | baudRateTextBox.Text, 64 | (string)parityComboBox.SelectedItem, 65 | dataBitsTextBox.Text, 66 | (string)stopBitsComboBox.SelectedItem); 67 | 68 | if (startSuccess) { 69 | // Minimize window 70 | WindowState = FormWindowState.Minimized; 71 | 72 | startButton.Text = START_BUTTON_STOP_TEXT; 73 | } 74 | } else { 75 | if (stopButtonClickHandler.Invoke()) { 76 | startButton.Text = START_BUTTON_START_TEXT; 77 | } 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /client/View/CursorController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using System.Drawing; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Client3DCapacitiveSensor.View { 7 | 8 | /// 9 | /// This class is for easy controlling of the user's mouse. 10 | /// 11 | public class CursorController { 12 | 13 | private readonly int maxInputX; 14 | private readonly int maxInputY; 15 | private readonly int minScreenX; 16 | private readonly int minScreenY; 17 | private readonly int screenWidth; 18 | private readonly int screenHeight; 19 | private bool leftButtonDown; 20 | 21 | /// 22 | /// Instantiates a new 23 | /// 24 | /// The max X value that will get. 25 | /// The max Y value that will get. 26 | public CursorController(int maxInputX, int maxInputY) { 27 | this.maxInputX = maxInputX; 28 | this.maxInputY = maxInputY; 29 | 30 | Rectangle primaryScreenBounds = Screen.PrimaryScreen.Bounds; 31 | minScreenX = primaryScreenBounds.X; 32 | minScreenY = primaryScreenBounds.Y; 33 | screenWidth = primaryScreenBounds.Width; 34 | screenHeight = primaryScreenBounds.Height; 35 | 36 | leftButtonDown = false; 37 | } 38 | 39 | /// 40 | /// Sets the X,Y coordinates of the cursor. 41 | /// 42 | /// 43 | /// 44 | public void SetXY(int x, int y) { 45 | Cursor.Position = new Point( 46 | (int)((double)x / maxInputX * screenWidth + minScreenX), 47 | (int)((double)y / maxInputY * screenHeight + minScreenY)); 48 | } 49 | 50 | /// 51 | /// Simulates the user's left mouse button presseing down. 52 | /// 53 | public void LeftButtonDown() { 54 | mouse_event((int)MouseEventFlags.LeftDown, GetX(), GetY(), 0, 0); 55 | leftButtonDown = true; 56 | } 57 | 58 | /// 59 | /// Simulates the user's left mouse button presseing up. 60 | /// 61 | public void LeftButtonUp() { 62 | mouse_event((int)MouseEventFlags.LeftUp, GetX(), GetY(), 0, 0); 63 | leftButtonDown = false; 64 | } 65 | 66 | /// 67 | /// 68 | /// 69 | /// 70 | /// 71 | /// 72 | /// 73 | /// 74 | [DllImport("user32.dll")] 75 | private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); 76 | 77 | /// 78 | /// Gets . 79 | /// 80 | /// 81 | public int GetX() { 82 | return Cursor.Position.X; 83 | } 84 | 85 | /// 86 | /// Gets . 87 | /// 88 | /// 89 | public int GetY() { 90 | return Cursor.Position.Y; 91 | } 92 | 93 | /// 94 | /// True if . 95 | /// 96 | /// 97 | public bool IsLeftButtonDown() { 98 | return leftButtonDown; 99 | } 100 | 101 | /// 102 | /// Bit fields for . 103 | /// 104 | [Flags] 105 | private enum MouseEventFlags { 106 | LeftDown = 0x00000002, 107 | LeftUp = 0x00000004, 108 | MiddleDown = 0x00000020, 109 | MiddleUp = 0x00000040, 110 | RightDown = 0x00000008, 111 | RightUp = 0x00000010 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_cortex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_cortex.h 4 | * @author MCD Application Team 5 | * @brief Header file of CORTEX HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F0xx_HAL_CORTEX_H 22 | #define __STM32F0xx_HAL_CORTEX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup CORTEX CORTEX 36 | * @{ 37 | */ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | 41 | /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants 42 | * @{ 43 | */ 44 | 45 | /** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source 46 | * @{ 47 | */ 48 | #define SYSTICK_CLKSOURCE_HCLK_DIV8 (0x00000000U) 49 | #define SYSTICK_CLKSOURCE_HCLK (0x00000004U) 50 | 51 | /** 52 | * @} 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported Macros -----------------------------------------------------------*/ 60 | 61 | /* Exported functions --------------------------------------------------------*/ 62 | /** @addtogroup CORTEX_Exported_Functions CORTEX Exported Functions 63 | * @{ 64 | */ 65 | /** @addtogroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions 66 | * @brief Initialization and Configuration functions 67 | * @{ 68 | */ 69 | /* Initialization and de-initialization functions *******************************/ 70 | void HAL_NVIC_SetPriority(IRQn_Type IRQn,uint32_t PreemptPriority, uint32_t SubPriority); 71 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); 72 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); 73 | void HAL_NVIC_SystemReset(void); 74 | uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb); 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @addtogroup CORTEX_Exported_Functions_Group2 Peripheral Control functions 80 | * @brief Cortex control functions 81 | * @{ 82 | */ 83 | 84 | /* Peripheral Control functions *************************************************/ 85 | uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn); 86 | uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn); 87 | void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn); 88 | void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn); 89 | void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource); 90 | void HAL_SYSTICK_IRQHandler(void); 91 | void HAL_SYSTICK_Callback(void); 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /* Private types -------------------------------------------------------------*/ 101 | /* Private variables ---------------------------------------------------------*/ 102 | /* Private constants ---------------------------------------------------------*/ 103 | /* Private macros ------------------------------------------------------------*/ 104 | /** @defgroup CORTEX_Private_Macros CORTEX Private Macros 105 | * @{ 106 | */ 107 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x4) 108 | 109 | #define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00) 110 | 111 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \ 112 | ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8)) 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | 129 | #endif /* __STM32F0xx_HAL_CORTEX_H */ 130 | 131 | 132 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 133 | 134 | -------------------------------------------------------------------------------- /mcu/Core/Src/stm32f0xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f0xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f0xx_it.h" 23 | #include "main.h" 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | 56 | /* USER CODE END 0 */ 57 | 58 | /* External variables --------------------------------------------------------*/ 59 | 60 | /* USER CODE BEGIN EV */ 61 | 62 | /* USER CODE END EV */ 63 | 64 | /******************************************************************************/ 65 | /* Cortex-M0 Processor Interruption and Exception Handlers */ 66 | /******************************************************************************/ 67 | /** 68 | * @brief This function handles Non maskable interrupt. 69 | */ 70 | void NMI_Handler(void) { 71 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 72 | 73 | /* USER CODE END NonMaskableInt_IRQn 0 */ 74 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 75 | while (1) { 76 | } 77 | /* USER CODE END NonMaskableInt_IRQn 1 */ 78 | } 79 | 80 | /** 81 | * @brief This function handles Hard fault interrupt. 82 | */ 83 | void HardFault_Handler(void) { 84 | /* USER CODE BEGIN HardFault_IRQn 0 */ 85 | 86 | /* USER CODE END HardFault_IRQn 0 */ 87 | while (1) { 88 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 89 | /* USER CODE END W1_HardFault_IRQn 0 */ 90 | } 91 | } 92 | 93 | /** 94 | * @brief This function handles System service call via SWI instruction. 95 | */ 96 | void SVC_Handler(void) { 97 | /* USER CODE BEGIN SVC_IRQn 0 */ 98 | 99 | /* USER CODE END SVC_IRQn 0 */ 100 | /* USER CODE BEGIN SVC_IRQn 1 */ 101 | 102 | /* USER CODE END SVC_IRQn 1 */ 103 | } 104 | 105 | /** 106 | * @brief This function handles Pendable request for system service. 107 | */ 108 | void PendSV_Handler(void) { 109 | /* USER CODE BEGIN PendSV_IRQn 0 */ 110 | 111 | /* USER CODE END PendSV_IRQn 0 */ 112 | /* USER CODE BEGIN PendSV_IRQn 1 */ 113 | 114 | /* USER CODE END PendSV_IRQn 1 */ 115 | } 116 | 117 | /** 118 | * @brief This function handles System tick timer. 119 | */ 120 | void SysTick_Handler(void) { 121 | /* USER CODE BEGIN SysTick_IRQn 0 */ 122 | 123 | /* USER CODE END SysTick_IRQn 0 */ 124 | HAL_IncTick(); 125 | /* USER CODE BEGIN SysTick_IRQn 1 */ 126 | 127 | /* USER CODE END SysTick_IRQn 1 */ 128 | } 129 | 130 | /******************************************************************************/ 131 | /* STM32F0xx Peripheral Interrupt Handlers */ 132 | /* Add here the Interrupt Handlers for the used peripherals. */ 133 | /* For the available peripheral interrupt handler names, */ 134 | /* please refer to the startup file (startup_stm32f0xx.s). */ 135 | /******************************************************************************/ 136 | 137 | /* USER CODE BEGIN 1 */ 138 | 139 | /* USER CODE END 1 */ 140 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 141 | -------------------------------------------------------------------------------- /design/3DCapacitiveSensor.pro: -------------------------------------------------------------------------------- 1 | update=Friday, April 30, 2021 at 06:39:25 PM 2 | version=1 3 | last_client=kicad 4 | [general] 5 | version=1 6 | RootSch= 7 | BoardNm= 8 | [cvpcb] 9 | version=1 10 | NetIExt=net 11 | [eeschema] 12 | version=1 13 | LibDir= 14 | [eeschema/libraries] 15 | [pcbnew] 16 | version=1 17 | PageLayoutDescrFile= 18 | LastNetListRead=3DCapacitiveSensor.net 19 | CopperLayerCount=2 20 | BoardThickness=1.6 21 | AllowMicroVias=0 22 | AllowBlindVias=0 23 | RequireCourtyardDefinitions=0 24 | ProhibitOverlappingCourtyards=1 25 | MinTrackWidth=0.2 26 | MinViaDiameter=0.4 27 | MinViaDrill=0.3 28 | MinMicroViaDiameter=0.2 29 | MinMicroViaDrill=0.09999999999999999 30 | MinHoleToHole=0.25 31 | TrackWidth1=0.25 32 | TrackWidth2=1 33 | ViaDiameter1=0.8 34 | ViaDrill1=0.4 35 | dPairWidth1=0.2 36 | dPairGap1=0.25 37 | dPairViaGap1=0.25 38 | SilkLineWidth=0.12 39 | SilkTextSizeV=1 40 | SilkTextSizeH=1 41 | SilkTextSizeThickness=0.15 42 | SilkTextItalic=0 43 | SilkTextUpright=1 44 | CopperLineWidth=0.2 45 | CopperTextSizeV=1.5 46 | CopperTextSizeH=1.5 47 | CopperTextThickness=0.3 48 | CopperTextItalic=0 49 | CopperTextUpright=1 50 | EdgeCutLineWidth=0.05 51 | CourtyardLineWidth=0.05 52 | OthersLineWidth=0.15 53 | OthersTextSizeV=1 54 | OthersTextSizeH=1 55 | OthersTextSizeThickness=0.15 56 | OthersTextItalic=0 57 | OthersTextUpright=1 58 | SolderMaskClearance=0 59 | SolderMaskMinWidth=0 60 | SolderPasteClearance=0 61 | SolderPasteRatio=-0 62 | [pcbnew/Layer.F.Cu] 63 | Name=F.Cu 64 | Type=0 65 | Enabled=1 66 | [pcbnew/Layer.In1.Cu] 67 | Name=In1.Cu 68 | Type=0 69 | Enabled=0 70 | [pcbnew/Layer.In2.Cu] 71 | Name=In2.Cu 72 | Type=0 73 | Enabled=0 74 | [pcbnew/Layer.In3.Cu] 75 | Name=In3.Cu 76 | Type=0 77 | Enabled=0 78 | [pcbnew/Layer.In4.Cu] 79 | Name=In4.Cu 80 | Type=0 81 | Enabled=0 82 | [pcbnew/Layer.In5.Cu] 83 | Name=In5.Cu 84 | Type=0 85 | Enabled=0 86 | [pcbnew/Layer.In6.Cu] 87 | Name=In6.Cu 88 | Type=0 89 | Enabled=0 90 | [pcbnew/Layer.In7.Cu] 91 | Name=In7.Cu 92 | Type=0 93 | Enabled=0 94 | [pcbnew/Layer.In8.Cu] 95 | Name=In8.Cu 96 | Type=0 97 | Enabled=0 98 | [pcbnew/Layer.In9.Cu] 99 | Name=In9.Cu 100 | Type=0 101 | Enabled=0 102 | [pcbnew/Layer.In10.Cu] 103 | Name=In10.Cu 104 | Type=0 105 | Enabled=0 106 | [pcbnew/Layer.In11.Cu] 107 | Name=In11.Cu 108 | Type=0 109 | Enabled=0 110 | [pcbnew/Layer.In12.Cu] 111 | Name=In12.Cu 112 | Type=0 113 | Enabled=0 114 | [pcbnew/Layer.In13.Cu] 115 | Name=In13.Cu 116 | Type=0 117 | Enabled=0 118 | [pcbnew/Layer.In14.Cu] 119 | Name=In14.Cu 120 | Type=0 121 | Enabled=0 122 | [pcbnew/Layer.In15.Cu] 123 | Name=In15.Cu 124 | Type=0 125 | Enabled=0 126 | [pcbnew/Layer.In16.Cu] 127 | Name=In16.Cu 128 | Type=0 129 | Enabled=0 130 | [pcbnew/Layer.In17.Cu] 131 | Name=In17.Cu 132 | Type=0 133 | Enabled=0 134 | [pcbnew/Layer.In18.Cu] 135 | Name=In18.Cu 136 | Type=0 137 | Enabled=0 138 | [pcbnew/Layer.In19.Cu] 139 | Name=In19.Cu 140 | Type=0 141 | Enabled=0 142 | [pcbnew/Layer.In20.Cu] 143 | Name=In20.Cu 144 | Type=0 145 | Enabled=0 146 | [pcbnew/Layer.In21.Cu] 147 | Name=In21.Cu 148 | Type=0 149 | Enabled=0 150 | [pcbnew/Layer.In22.Cu] 151 | Name=In22.Cu 152 | Type=0 153 | Enabled=0 154 | [pcbnew/Layer.In23.Cu] 155 | Name=In23.Cu 156 | Type=0 157 | Enabled=0 158 | [pcbnew/Layer.In24.Cu] 159 | Name=In24.Cu 160 | Type=0 161 | Enabled=0 162 | [pcbnew/Layer.In25.Cu] 163 | Name=In25.Cu 164 | Type=0 165 | Enabled=0 166 | [pcbnew/Layer.In26.Cu] 167 | Name=In26.Cu 168 | Type=0 169 | Enabled=0 170 | [pcbnew/Layer.In27.Cu] 171 | Name=In27.Cu 172 | Type=0 173 | Enabled=0 174 | [pcbnew/Layer.In28.Cu] 175 | Name=In28.Cu 176 | Type=0 177 | Enabled=0 178 | [pcbnew/Layer.In29.Cu] 179 | Name=In29.Cu 180 | Type=0 181 | Enabled=0 182 | [pcbnew/Layer.In30.Cu] 183 | Name=In30.Cu 184 | Type=0 185 | Enabled=0 186 | [pcbnew/Layer.B.Cu] 187 | Name=B.Cu 188 | Type=0 189 | Enabled=1 190 | [pcbnew/Layer.B.Adhes] 191 | Enabled=1 192 | [pcbnew/Layer.F.Adhes] 193 | Enabled=1 194 | [pcbnew/Layer.B.Paste] 195 | Enabled=1 196 | [pcbnew/Layer.F.Paste] 197 | Enabled=1 198 | [pcbnew/Layer.B.SilkS] 199 | Enabled=1 200 | [pcbnew/Layer.F.SilkS] 201 | Enabled=1 202 | [pcbnew/Layer.B.Mask] 203 | Enabled=1 204 | [pcbnew/Layer.F.Mask] 205 | Enabled=1 206 | [pcbnew/Layer.Dwgs.User] 207 | Enabled=1 208 | [pcbnew/Layer.Cmts.User] 209 | Enabled=1 210 | [pcbnew/Layer.Eco1.User] 211 | Enabled=1 212 | [pcbnew/Layer.Eco2.User] 213 | Enabled=1 214 | [pcbnew/Layer.Edge.Cuts] 215 | Enabled=1 216 | [pcbnew/Layer.Margin] 217 | Enabled=1 218 | [pcbnew/Layer.B.CrtYd] 219 | Enabled=1 220 | [pcbnew/Layer.F.CrtYd] 221 | Enabled=1 222 | [pcbnew/Layer.B.Fab] 223 | Enabled=1 224 | [pcbnew/Layer.F.Fab] 225 | Enabled=1 226 | [pcbnew/Layer.Rescue] 227 | Enabled=0 228 | [pcbnew/Netclasses] 229 | [pcbnew/Netclasses/Default] 230 | Name=Default 231 | Clearance=0.2 232 | TrackWidth=0.25 233 | ViaDiameter=0.8 234 | ViaDrill=0.4 235 | uViaDiameter=0.3 236 | uViaDrill=0.1 237 | dPairWidth=0.2 238 | dPairGap=0.25 239 | dPairViaGap=0.25 240 | [schematic_editor] 241 | version=1 242 | PageLayoutDescrFile= 243 | PlotDirectoryName=./ 244 | SubpartIdSeparator=0 245 | SubpartFirstId=65 246 | NetFmtName=Pcbnew 247 | SpiceAjustPassiveValues=0 248 | LabSize=50 249 | ERC_TestSimilarLabels=1 250 | -------------------------------------------------------------------------------- /mcu/Core/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 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f0xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /** 47 | * @brief Represents a type of line ending. 48 | */ 49 | enum LineEnding { 50 | /** @brief '\r' */ 51 | CR, 52 | 53 | /** @brief '\n' */ 54 | LF, 55 | 56 | /** @brief '\r\n' */ 57 | CRLF 58 | }; 59 | 60 | /* USER CODE END EC */ 61 | 62 | /* Exported macro ------------------------------------------------------------*/ 63 | /* USER CODE BEGIN EM */ 64 | 65 | /* USER CODE END EM */ 66 | 67 | /* Exported functions prototypes ---------------------------------------------*/ 68 | void Error_Handler(void); 69 | 70 | /* USER CODE BEGIN EFP */ 71 | 72 | /** 73 | * @brief Configures the RCC. 74 | */ 75 | void configure_rcc(void); 76 | 77 | /** 78 | * @brief Configures the USART3 peripheral for transmission. 79 | */ 80 | void configure_usart3_tx(void); 81 | 82 | /** 83 | * @brief Configures a GPIO pin. 84 | * @param gpio_pointer: a pointer to the GPIO_TypeDef struct base 85 | * @param gpio_number: the GPIO port number 86 | */ 87 | void configure_gpio(GPIO_TypeDef *gpio_pointer, uint8_t gpio_number); 88 | 89 | /** 90 | * @brief Pulls a GPIO pin low. 91 | * @param gpio_pointer: a pointer to the GPIO_TypeDef struct base 92 | * @param gpio_number: the GPIO port number 93 | */ 94 | void gpio_pull_low(GPIO_TypeDef *gpio_pointer, uint8_t gpio_number); 95 | 96 | /** 97 | * @brief Configures a GPIO pin as an input. 98 | * @param gpio_pointer: a pointer to the GPIO_TypeDef struct base 99 | * @param gpio_number: the GPIO port number 100 | */ 101 | void gpio_configure_input(GPIO_TypeDef *gpio_pointer, uint8_t gpio_number); 102 | 103 | /** 104 | * @brief Gets a GPIO pin input. 105 | * @param gpio_pointer: a pointer to the GPIO_TypeDef struct base 106 | * @param gpio_number: the GPIO port number 107 | */ 108 | uint8_t gpio_get_input(GPIO_TypeDef *gpio_pointer, uint8_t gpio_number); 109 | 110 | /** 111 | * @brief Polls the measured capacitance of the given GPIO pin. 112 | * @param gpio_pointer: a pointer to the GPIO_TypeDef struct base 113 | * @param gpio_number: the GPIO port number 114 | */ 115 | uint32_t poll_capacitance(GPIO_TypeDef *gpio_pointer, uint8_t gpio_number); 116 | 117 | /** 118 | * @brief Transmits a character on the USART3 peripheral. This is a blocking call. 119 | * @param character: the character 120 | */ 121 | void usart3_transmit_char(char character); 122 | 123 | /** 124 | * @brief Transmits a string on the USART3 peripheral. This is a blocking call. 125 | * @param string: the string 126 | */ 127 | void usart3_transmit_string(char string[]); 128 | 129 | /** 130 | * @brief Transmits a new line on the USART3 peripheral. 131 | * @param lineEnding: the type of line ending 132 | */ 133 | void usart3_transmit_newline(enum LineEnding lineEnding); 134 | 135 | /** 136 | * @brief C++ version 0.4 char* style "itoa": 137 | * Written by Lukas Chmela (https://stackoverflow.com/a/23840699) 138 | * Released under GPLv3. 139 | * @retval the converted ASCII character 140 | */ 141 | char *to_string(int value, char *result, int base); 142 | 143 | /** 144 | * @brief Sets 'number' inside 'to_set' at the bits defined by MSB and LSB. 145 | * @param to_set: a pointer to the bits to set 146 | * @param number: the number to set inside 'to_set' 147 | * @param msb: the MSB (0 - 31) (inclusive) 148 | * @param lsb: the LSB (0 - 31) (inclusive) 149 | * @author Jacob Peterson 150 | */ 151 | static inline void set_bits(volatile uint32_t *to_set, uint32_t number, uint8_t msb, uint8_t lsb); 152 | 153 | /** 154 | * @brief Sets 'bit' inside 'to_set' at index. 155 | * @param to_set: a pointer to the bits to set 156 | * @param bit: the bit to set inside 'to_set' 157 | * @param index: the index (0 - 31) (inclusive) 158 | * @author Jacob Peterson 159 | */ 160 | static inline void set_bit(volatile uint32_t *to_set, uint32_t bit, uint8_t index); 161 | 162 | /** 163 | * @brief Gets the bits inside 'to_get' at the bits defined by MSB and LSB. 164 | * @param to_get: a pointer to the bits to get 165 | * @param msb: the MSB (0 - 31) (inclusive) 166 | * @param lsb: the LSB (0 - 31) (inclusive) 167 | * @retval the bits 168 | * @author Jacob Peterson 169 | */ 170 | static inline uint32_t get_bits(volatile uint32_t *to_get, uint8_t msb, uint8_t lsb); 171 | 172 | /** 173 | * @brief Gets the bit inside 'to_get' at the bits at the index. 174 | * @param to_get: a pointer to the bits to get 175 | * @param index: the MSB (0 - 31) 176 | * @retval the bit 177 | * @author Jacob Peterson 178 | */ 179 | static inline uint32_t get_bit(volatile uint32_t *to_get, uint8_t index); 180 | 181 | /* USER CODE END EFP */ 182 | 183 | /* Private defines -----------------------------------------------------------*/ 184 | /* USER CODE BEGIN Private defines */ 185 | 186 | /* USER CODE END Private defines */ 187 | 188 | #ifdef __cplusplus 189 | } 190 | #endif 191 | 192 | #endif /* __MAIN_H */ 193 | 194 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 195 | -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pwr.h 4 | * @author MCD Application Team 5 | * @brief Header file of PWR HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F0xx_HAL_PWR_H 22 | #define __STM32F0xx_HAL_PWR_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup PWR PWR 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | 42 | /** @defgroup PWR_Exported_Constants PWR Exported Constants 43 | * @{ 44 | */ 45 | 46 | /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in STOP mode 47 | * @{ 48 | */ 49 | #define PWR_MAINREGULATOR_ON (0x00000000U) 50 | #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPDS 51 | 52 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ 53 | ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry 59 | * @{ 60 | */ 61 | #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01U) 62 | #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02U) 63 | #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry 69 | * @{ 70 | */ 71 | #define PWR_STOPENTRY_WFI ((uint8_t)0x01U) 72 | #define PWR_STOPENTRY_WFE ((uint8_t)0x02U) 73 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE)) 74 | /** 75 | * @} 76 | */ 77 | 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /* Exported macro ------------------------------------------------------------*/ 84 | /** @defgroup PWR_Exported_Macro PWR Exported Macro 85 | * @{ 86 | */ 87 | 88 | /** @brief Check PWR flag is set or not. 89 | * @param __FLAG__ specifies the flag to check. 90 | * This parameter can be one of the following values: 91 | * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event 92 | * was received from the WKUP pin or from the RTC alarm (Alarm A), 93 | * RTC Tamper event, RTC TimeStamp event or RTC Wakeup. 94 | * An additional wakeup event is detected if the WKUP pin is enabled 95 | * (by setting the EWUP bit) when the WKUP pin level is already high. 96 | * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was 97 | * resumed from StandBy mode. 98 | * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled 99 | * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode 100 | * For this reason, this bit is equal to 0 after Standby or reset 101 | * until the PVDE bit is set. 102 | * Warning: this Flag is not available on STM32F030x8 products 103 | * @arg PWR_FLAG_VREFINTRDY: This flag indicates that the internal reference 104 | * voltage VREFINT is ready. 105 | * Warning: this Flag is not available on STM32F030x8 products 106 | * @retval The new state of __FLAG__ (TRUE or FALSE). 107 | */ 108 | #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__)) 109 | 110 | /** @brief Clear the PWR's pending flags. 111 | * @param __FLAG__ specifies the flag to clear. 112 | * This parameter can be one of the following values: 113 | * @arg PWR_FLAG_WU: Wake Up flag 114 | * @arg PWR_FLAG_SB: StandBy flag 115 | */ 116 | #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR |= (__FLAG__) << 2U) 117 | 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | /* Include PWR HAL Extension module */ 124 | #include "stm32f0xx_hal_pwr_ex.h" 125 | 126 | /* Exported functions --------------------------------------------------------*/ 127 | 128 | /** @addtogroup PWR_Exported_Functions PWR Exported Functions 129 | * @{ 130 | */ 131 | 132 | /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 133 | * @{ 134 | */ 135 | 136 | /* Initialization and de-initialization functions *****************************/ 137 | void HAL_PWR_DeInit(void); 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 144 | * @{ 145 | */ 146 | 147 | /* Peripheral Control functions **********************************************/ 148 | void HAL_PWR_EnableBkUpAccess(void); 149 | void HAL_PWR_DisableBkUpAccess(void); 150 | 151 | /* WakeUp pins configuration functions ****************************************/ 152 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx); 153 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); 154 | 155 | /* Low Power modes configuration functions ************************************/ 156 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); 157 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); 158 | void HAL_PWR_EnterSTANDBYMode(void); 159 | 160 | void HAL_PWR_EnableSleepOnExit(void); 161 | void HAL_PWR_DisableSleepOnExit(void); 162 | void HAL_PWR_EnableSEVOnPend(void); 163 | void HAL_PWR_DisableSEVOnPend(void); 164 | 165 | /** 166 | * @} 167 | */ 168 | 169 | /** 170 | * @} 171 | */ 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | /** 178 | * @} 179 | */ 180 | 181 | #ifdef __cplusplus 182 | } 183 | #endif 184 | 185 | 186 | #endif /* __STM32F0xx_HAL_PWR_H */ 187 | 188 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 189 | 190 | -------------------------------------------------------------------------------- /mcu/.mxproject: -------------------------------------------------------------------------------- 1 | [PreviousLibFiles] 2 | LibFiles=Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h;Drivers/STM32F0xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_cortex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_flash.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_flash_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_exti.h;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c;Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_exti.c;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h;Drivers/STM32F0xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_dma.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_cortex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pwr_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_flash.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_flash_ex.h;Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_exti.h;Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f072xb.h;Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h;Drivers/CMSIS/Device/ST/STM32F0xx/Include/system_stm32f0xx.h;Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/system_stm32f0xx.c;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/tz_context.h; 3 | 4 | [PreviousUsedKeilFiles] 5 | SourceFiles=..\Core\Src\main.c;..\Core\Src\stm32f0xx_it.c;..\Core\Src\stm32f0xx_hal_msp.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_exti.c;..\Core\Src/system_stm32f0xx.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c;..\Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_exti.c;..\Core\Src/system_stm32f0xx.c;..\Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/system_stm32f0xx.c;; 6 | HeaderPath=..\Drivers\STM32F0xx_HAL_Driver\Inc;..\Drivers\STM32F0xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32F0xx\Include;..\Drivers\CMSIS\Include;..\Core\Inc; 7 | CDefines=USE_HAL_DRIVER;STM32F072xB;USE_HAL_DRIVER;USE_HAL_DRIVER; 8 | 9 | [PreviousGenFiles] 10 | AdvancedFolderStructure=true 11 | HeaderFileListSize=3 12 | HeaderFiles#0=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Inc/stm32f0xx_it.h 13 | HeaderFiles#1=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Inc/stm32f0xx_hal_conf.h 14 | HeaderFiles#2=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Inc/main.h 15 | HeaderFolderListSize=1 16 | HeaderPath#0=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Inc 17 | HeaderFiles=; 18 | SourceFileListSize=3 19 | SourceFiles#0=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Src/stm32f0xx_it.c 20 | SourceFiles#1=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Src/stm32f0xx_hal_msp.c 21 | SourceFiles#2=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Src/main.c 22 | SourceFolderListSize=1 23 | SourcePath#0=C:/Users/Jacob Peterson/Documents/ECE 5780/3DCapacitiveSensor/mcu/Core/Src 24 | SourceFiles=; 25 | 26 | -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_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) 2016 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F0xx_HAL_DEF 23 | #define __STM32F0xx_HAL_DEF 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f0xx.h" 31 | #include "Legacy/stm32_hal_legacy.h" 32 | #include 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /** 37 | * @brief HAL Status structures definition 38 | */ 39 | typedef enum 40 | { 41 | HAL_OK = 0x00U, 42 | HAL_ERROR = 0x01U, 43 | HAL_BUSY = 0x02U, 44 | HAL_TIMEOUT = 0x03U 45 | } HAL_StatusTypeDef; 46 | 47 | /** 48 | * @brief HAL Lock structures definition 49 | */ 50 | typedef enum 51 | { 52 | HAL_UNLOCKED = 0x00U, 53 | HAL_LOCKED = 0x01U 54 | } HAL_LockTypeDef; 55 | 56 | /* Exported macro ------------------------------------------------------------*/ 57 | 58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 59 | 60 | #define HAL_MAX_DELAY 0xFFFFFFFFU 61 | 62 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 63 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 64 | 65 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 66 | do{ \ 67 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 68 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 69 | } while(0U) 70 | 71 | /** @brief Reset the Handle's State field. 72 | * @param __HANDLE__ specifies the Peripheral Handle. 73 | * @note This macro can be used for the following purpose: 74 | * - When the Handle is declared as local variable; before passing it as parameter 75 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 76 | * to set to 0 the Handle's "State" field. 77 | * Otherwise, "State" field may have any random value and the first time the function 78 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 79 | * (i.e. HAL_PPP_MspInit() will not be executed). 80 | * - When there is a need to reconfigure the low level hardware: instead of calling 81 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 82 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 83 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 84 | * @retval None 85 | */ 86 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 87 | 88 | #if (USE_RTOS == 1U) 89 | /* Reserved for future use */ 90 | #error " USE_RTOS should be 0 in the current HAL release " 91 | #else 92 | #define __HAL_LOCK(__HANDLE__) \ 93 | do{ \ 94 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 95 | { \ 96 | return HAL_BUSY; \ 97 | } \ 98 | else \ 99 | { \ 100 | (__HANDLE__)->Lock = HAL_LOCKED; \ 101 | } \ 102 | }while (0U) 103 | 104 | #define __HAL_UNLOCK(__HANDLE__) \ 105 | do{ \ 106 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 107 | }while (0U) 108 | #endif /* USE_RTOS */ 109 | 110 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 111 | #ifndef __weak 112 | #define __weak __attribute__((weak)) 113 | #endif 114 | #ifndef __packed 115 | #define __packed __attribute__((packed)) 116 | #endif 117 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 118 | #ifndef __weak 119 | #define __weak __attribute__((weak)) 120 | #endif /* __weak */ 121 | #ifndef __packed 122 | #define __packed __attribute__((__packed__)) 123 | #endif /* __packed */ 124 | #endif /* __GNUC__ */ 125 | 126 | 127 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 128 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 129 | #ifndef __ALIGN_BEGIN 130 | #define __ALIGN_BEGIN 131 | #endif 132 | #ifndef __ALIGN_END 133 | #define __ALIGN_END __attribute__ ((aligned (4))) 134 | #endif 135 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 136 | #ifndef __ALIGN_END 137 | #define __ALIGN_END __attribute__ ((aligned (4))) 138 | #endif /* __ALIGN_END */ 139 | #ifndef __ALIGN_BEGIN 140 | #define __ALIGN_BEGIN 141 | #endif /* __ALIGN_BEGIN */ 142 | #else 143 | #ifndef __ALIGN_END 144 | #define __ALIGN_END 145 | #endif /* __ALIGN_END */ 146 | #ifndef __ALIGN_BEGIN 147 | #if defined (__CC_ARM) /* ARM Compiler V5*/ 148 | #define __ALIGN_BEGIN __align(4) 149 | #elif defined (__ICCARM__) /* IAR Compiler */ 150 | #define __ALIGN_BEGIN 151 | #endif /* __CC_ARM */ 152 | #endif /* __ALIGN_BEGIN */ 153 | #endif /* __GNUC__ */ 154 | 155 | /** 156 | * @brief __NOINLINE definition 157 | */ 158 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 159 | /* ARM V4/V5 and V6 & GNU Compiler 160 | ------------------------------- 161 | */ 162 | #define __NOINLINE __attribute__ ( (noinline) ) 163 | 164 | #elif defined ( __ICCARM__ ) 165 | /* ICCARM Compiler 166 | --------------- 167 | */ 168 | #define __NOINLINE _Pragma("optimize = no_inline") 169 | 170 | #endif 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | 176 | #endif /* ___STM32F0xx_HAL_DEF */ 177 | 178 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 179 | -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_i2c_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_i2c_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of I2C HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F0xx_HAL_I2C_EX_H 22 | #define STM32F0xx_HAL_I2C_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup I2CEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | 42 | /** @defgroup I2CEx_Exported_Constants I2C Extended Exported Constants 43 | * @{ 44 | */ 45 | 46 | /** @defgroup I2CEx_Analog_Filter I2C Extended Analog Filter 47 | * @{ 48 | */ 49 | #define I2C_ANALOGFILTER_ENABLE 0x00000000U 50 | #define I2C_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF 51 | /** 52 | * @} 53 | */ 54 | 55 | /** @defgroup I2CEx_FastModePlus I2C Extended Fast Mode Plus 56 | * @{ 57 | */ 58 | #define I2C_FMP_NOT_SUPPORTED 0xAAAA0000U /*!< Fast Mode Plus not supported */ 59 | #if defined(SYSCFG_CFGR1_I2C_FMP_PA9) 60 | #define I2C_FASTMODEPLUS_PA9 SYSCFG_CFGR1_I2C_FMP_PA9 /*!< Enable Fast Mode Plus on PA9 */ 61 | #define I2C_FASTMODEPLUS_PA10 SYSCFG_CFGR1_I2C_FMP_PA10 /*!< Enable Fast Mode Plus on PA10 */ 62 | #else 63 | #define I2C_FASTMODEPLUS_PA9 (uint32_t)(0x00000001U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus PA9 not supported */ 64 | #define I2C_FASTMODEPLUS_PA10 (uint32_t)(0x00000002U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus PA10 not supported */ 65 | #endif 66 | #define I2C_FASTMODEPLUS_PB6 SYSCFG_CFGR1_I2C_FMP_PB6 /*!< Enable Fast Mode Plus on PB6 */ 67 | #define I2C_FASTMODEPLUS_PB7 SYSCFG_CFGR1_I2C_FMP_PB7 /*!< Enable Fast Mode Plus on PB7 */ 68 | #define I2C_FASTMODEPLUS_PB8 SYSCFG_CFGR1_I2C_FMP_PB8 /*!< Enable Fast Mode Plus on PB8 */ 69 | #define I2C_FASTMODEPLUS_PB9 SYSCFG_CFGR1_I2C_FMP_PB9 /*!< Enable Fast Mode Plus on PB9 */ 70 | #if defined(SYSCFG_CFGR1_I2C_FMP_I2C1) 71 | #define I2C_FASTMODEPLUS_I2C1 SYSCFG_CFGR1_I2C_FMP_I2C1 /*!< Enable Fast Mode Plus on I2C1 pins */ 72 | #else 73 | #define I2C_FASTMODEPLUS_I2C1 (uint32_t)(0x00000100U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C1 not supported */ 74 | #endif 75 | #if defined(SYSCFG_CFGR1_I2C_FMP_I2C2) 76 | #define I2C_FASTMODEPLUS_I2C2 SYSCFG_CFGR1_I2C_FMP_I2C2 /*!< Enable Fast Mode Plus on I2C2 pins */ 77 | #else 78 | #define I2C_FASTMODEPLUS_I2C2 (uint32_t)(0x00000200U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C2 not supported */ 79 | #endif 80 | /** 81 | * @} 82 | */ 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /* Exported macro ------------------------------------------------------------*/ 89 | /* Exported functions --------------------------------------------------------*/ 90 | 91 | /** @addtogroup I2CEx_Exported_Functions I2C Extended Exported Functions 92 | * @{ 93 | */ 94 | 95 | /** @addtogroup I2CEx_Exported_Functions_Group1 Extended features functions 96 | * @brief Extended features functions 97 | * @{ 98 | */ 99 | 100 | /* Peripheral Control functions ************************************************/ 101 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, 102 | uint32_t AnalogFilter); 103 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, 104 | uint32_t DigitalFilter); 105 | #if defined(I2C_CR1_WUPEN) 106 | HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c); 107 | HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c); 108 | #endif 109 | void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus); 110 | void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus); 111 | 112 | /* Private constants ---------------------------------------------------------*/ 113 | /** @defgroup I2CEx_Private_Constants I2C Extended Private Constants 114 | * @{ 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /* Private macros ------------------------------------------------------------*/ 122 | /** @defgroup I2CEx_Private_Macro I2C Extended Private Macros 123 | * @{ 124 | */ 125 | #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ 126 | ((FILTER) == I2C_ANALOGFILTER_DISABLE)) 127 | 128 | #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU) 129 | 130 | #define IS_I2C_FASTMODEPLUS(__CONFIG__) ((((__CONFIG__) & I2C_FMP_NOT_SUPPORTED) != I2C_FMP_NOT_SUPPORTED) && \ 131 | ((((__CONFIG__) & (I2C_FASTMODEPLUS_PA9)) == I2C_FASTMODEPLUS_PA9) || \ 132 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PA10)) == I2C_FASTMODEPLUS_PA10) || \ 133 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB6)) == I2C_FASTMODEPLUS_PB6) || \ 134 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB7)) == I2C_FASTMODEPLUS_PB7) || \ 135 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB8)) == I2C_FASTMODEPLUS_PB8) || \ 136 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB9)) == I2C_FASTMODEPLUS_PB9) || \ 137 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C1)) == I2C_FASTMODEPLUS_I2C1) || \ 138 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C2)) == I2C_FASTMODEPLUS_I2C2))) 139 | /** 140 | * @} 141 | */ 142 | 143 | /* Private Functions ---------------------------------------------------------*/ 144 | /** @defgroup I2CEx_Private_Functions I2C Extended Private Functions 145 | * @{ 146 | */ 147 | /* Private functions are defined in stm32f0xx_hal_i2c_ex.c file */ 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | #ifdef __cplusplus 169 | } 170 | #endif 171 | 172 | #endif /* STM32F0xx_HAL_I2C_EX_H */ 173 | 174 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 175 | -------------------------------------------------------------------------------- /design/3DCapacitiveSensor.sch: -------------------------------------------------------------------------------- 1 | EESchema Schematic File Version 4 2 | EELAYER 30 0 3 | EELAYER END 4 | $Descr A4 11693 8268 5 | encoding utf-8 6 | Sheet 1 1 7 | Title "" 8 | Date "" 9 | Rev "" 10 | Comp "" 11 | Comment1 "" 12 | Comment2 "" 13 | Comment3 "" 14 | Comment4 "" 15 | $EndDescr 16 | Text Notes 7400 7500 0 50 ~ 0 17 | 3DCapacitiveSensor perfboard design 18 | Wire Wire Line 19 | 4500 2450 4500 2650 20 | Wire Wire Line 21 | 4500 2850 5000 2850 22 | Wire Wire Line 23 | 5000 2850 5000 2950 24 | Connection ~ 4500 2850 25 | Wire Wire Line 26 | 4500 2850 4500 2950 27 | Wire Wire Line 28 | 4500 2850 4000 2850 29 | Wire Wire Line 30 | 4000 2850 4000 2950 31 | $Comp 32 | L Device:R_US R1 33 | U 1 1 607267D1 34 | P 4000 3100 35 | F 0 "R1" H 4068 3146 50 0000 L CNN 36 | F 1 "220K" H 4068 3055 50 0000 L CNN 37 | F 2 "Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal" V 4040 3090 50 0001 C CNN 38 | F 3 "~" H 4000 3100 50 0001 C CNN 39 | 1 4000 3100 40 | 1 0 0 -1 41 | $EndComp 42 | $Comp 43 | L Device:R_US R3 44 | U 1 1 60726F97 45 | P 4500 3100 46 | F 0 "R3" H 4568 3146 50 0000 L CNN 47 | F 1 "220K" H 4568 3055 50 0000 L CNN 48 | F 2 "Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal" V 4540 3090 50 0001 C CNN 49 | F 3 "~" H 4500 3100 50 0001 C CNN 50 | 1 4500 3100 51 | 1 0 0 -1 52 | $EndComp 53 | $Comp 54 | L Device:R_US R5 55 | U 1 1 60727144 56 | P 5000 3100 57 | F 0 "R5" H 5068 3146 50 0000 L CNN 58 | F 1 "220K" H 5068 3055 50 0000 L CNN 59 | F 2 "Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal" V 5040 3090 50 0001 C CNN 60 | F 3 "~" H 5000 3100 50 0001 C CNN 61 | 1 5000 3100 62 | 1 0 0 -1 63 | $EndComp 64 | $Comp 65 | L Device:R_US R4 66 | U 1 1 6072B2A7 67 | P 4500 4100 68 | F 0 "R4" H 4568 4146 50 0000 L CNN 69 | F 1 "10K" H 4568 4055 50 0000 L CNN 70 | F 2 "Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal" V 4540 4090 50 0001 C CNN 71 | F 3 "~" H 4500 4100 50 0001 C CNN 72 | 1 4500 4100 73 | 1 0 0 -1 74 | $EndComp 75 | Wire Wire Line 76 | 5000 3250 5000 3350 77 | Wire Wire Line 78 | 4500 3250 4500 3600 79 | Wire Wire Line 80 | 4000 3250 4000 3850 81 | Connection ~ 5000 3350 82 | Wire Wire Line 83 | 5000 3350 5000 3950 84 | Connection ~ 4500 3600 85 | Wire Wire Line 86 | 4500 3600 4500 3950 87 | Connection ~ 4000 3850 88 | Wire Wire Line 89 | 4000 3850 4000 3950 90 | Wire Wire Line 91 | 4500 4250 4500 4600 92 | Wire Wire Line 93 | 4000 4250 4000 4600 94 | Wire Wire Line 95 | 5000 4250 5000 4600 96 | Wire Wire Line 97 | 5000 3350 6000 3350 98 | Wire Wire Line 99 | 4500 3600 6000 3600 100 | Wire Wire Line 101 | 4000 3850 6000 3850 102 | Wire Wire Line 103 | 4500 2650 5500 2650 104 | Wire Wire Line 105 | 5500 2650 5500 3300 106 | Wire Wire Line 107 | 5500 3300 5350 3300 108 | Connection ~ 4500 2650 109 | Wire Wire Line 110 | 4500 2650 4500 2850 111 | Wire Wire Line 112 | 5500 3300 5650 3300 113 | Connection ~ 5500 3300 114 | Wire Wire Line 115 | 5500 3300 5500 3400 116 | Wire Wire Line 117 | 5500 3400 5350 3400 118 | Wire Wire Line 119 | 5500 3400 5650 3400 120 | Connection ~ 5500 3400 121 | Wire Wire Line 122 | 5500 3400 5500 3550 123 | Wire Wire Line 124 | 5500 3550 5650 3550 125 | Wire Wire Line 126 | 5500 3550 5350 3550 127 | Connection ~ 5500 3550 128 | Wire Wire Line 129 | 5500 3550 5500 3650 130 | Wire Wire Line 131 | 5500 3650 5650 3650 132 | Wire Wire Line 133 | 5500 3650 5350 3650 134 | Connection ~ 5500 3650 135 | Wire Wire Line 136 | 5500 3650 5500 3800 137 | Wire Wire Line 138 | 5500 3800 5650 3800 139 | Wire Wire Line 140 | 5500 3800 5350 3800 141 | Connection ~ 5500 3800 142 | Wire Wire Line 143 | 5500 3800 5500 3900 144 | Wire Wire Line 145 | 5500 3900 5650 3900 146 | Wire Wire Line 147 | 5500 3900 5350 3900 148 | Connection ~ 5500 3900 149 | Text Label 5050 2650 0 50 ~ 0 150 | shield_wire 151 | $Comp 152 | L Connector:Conn_01x01_Male J6 153 | U 1 1 60735CD0 154 | P 6200 3850 155 | F 0 "J6" H 6172 3782 50 0001 R CNN 156 | F 1 "Z_plate" H 6172 3828 50 0000 R CNN 157 | F 2 "Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical" H 6200 3850 50 0001 C CNN 158 | F 3 "~" H 6200 3850 50 0001 C CNN 159 | 1 6200 3850 160 | -1 0 0 1 161 | $EndComp 162 | $Comp 163 | L Connector:Conn_01x01_Male J5 164 | U 1 1 607354B4 165 | P 6200 3600 166 | F 0 "J5" H 6172 3532 50 0001 R CNN 167 | F 1 "Y_plate" H 6172 3578 50 0000 R CNN 168 | F 2 "Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical" H 6200 3600 50 0001 C CNN 169 | F 3 "~" H 6200 3600 50 0001 C CNN 170 | 1 6200 3600 171 | -1 0 0 1 172 | $EndComp 173 | $Comp 174 | L Connector:Conn_01x01_Male J4 175 | U 1 1 607342FB 176 | P 6200 3350 177 | F 0 "J4" H 6172 3282 50 0001 R CNN 178 | F 1 "X_plate" H 6172 3328 50 0000 R CNN 179 | F 2 "Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical" H 6200 3350 50 0001 C CNN 180 | F 3 "~" H 6200 3350 50 0001 C CNN 181 | 1 6200 3350 182 | -1 0 0 1 183 | $EndComp 184 | $Comp 185 | L Connector:Conn_01x01_Male J7 186 | U 1 1 60742720 187 | P 4500 2250 188 | F 0 "J7" V 4562 2294 50 0001 L CNN 189 | F 1 "3V" V 4608 2294 50 0000 L CNN 190 | F 2 "Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical" H 4500 2250 50 0001 C CNN 191 | F 3 "~" H 4500 2250 50 0001 C CNN 192 | 1 4500 2250 193 | 0 1 1 0 194 | $EndComp 195 | $Comp 196 | L Connector:Conn_01x06_Female J1 197 | U 1 1 60746578 198 | P 4550 5250 199 | F 0 "J1" V 4396 5498 50 0001 L CNN 200 | F 1 "Pin Socket" V 4487 5498 50 0000 L CNN 201 | F 2 "Connector_PinSocket_2.54mm:PinSocket_1x06_P2.54mm_Vertical" H 4550 5250 50 0001 C CNN 202 | F 3 "~" H 4550 5250 50 0001 C CNN 203 | 1 4550 5250 204 | 0 1 1 0 205 | $EndComp 206 | Wire Wire Line 207 | 4350 4600 4350 5050 208 | Wire Wire Line 209 | 4500 4600 4550 4600 210 | Wire Wire Line 211 | 4550 4600 4550 5050 212 | Wire Wire Line 213 | 5000 4600 4750 4600 214 | Wire Wire Line 215 | 4750 5050 4750 4600 216 | Text Label 4350 5000 1 50 ~ 0 217 | Z_pin 218 | Text Label 4550 5000 1 50 ~ 0 219 | Y_pin 220 | Text Label 4750 5000 1 50 ~ 0 221 | X_pin 222 | $Comp 223 | L Device:R_US R6 224 | U 1 1 6072B5B0 225 | P 5000 4100 226 | F 0 "R6" H 5068 4146 50 0000 L CNN 227 | F 1 "10K" H 5068 4055 50 0000 L CNN 228 | F 2 "Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal" V 5040 4090 50 0001 C CNN 229 | F 3 "~" H 5000 4100 50 0001 C CNN 230 | 1 5000 4100 231 | 1 0 0 -1 232 | $EndComp 233 | $Comp 234 | L Device:R_US R2 235 | U 1 1 6072A903 236 | P 4000 4100 237 | F 0 "R2" H 4068 4146 50 0000 L CNN 238 | F 1 "10K" H 4068 4055 50 0000 L CNN 239 | F 2 "Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal" V 4040 4090 50 0001 C CNN 240 | F 3 "~" H 4000 4100 50 0001 C CNN 241 | 1 4000 4100 242 | 1 0 0 -1 243 | $EndComp 244 | $Comp 245 | L Connector:Conn_01x01_Male J2 246 | U 1 1 60768D29 247 | P 5850 3400 248 | F 0 "J2" H 5822 3332 50 0001 R CNN 249 | F 1 "X_shield" H 5822 3378 50 0000 R CNN 250 | F 2 "Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical" H 5850 3400 50 0001 C CNN 251 | F 3 "~" H 5850 3400 50 0001 C CNN 252 | 1 5850 3400 253 | -1 0 0 1 254 | $EndComp 255 | $Comp 256 | L Connector:Conn_01x01_Male J3 257 | U 1 1 6076926F 258 | P 5850 3650 259 | F 0 "J3" H 5822 3582 50 0001 R CNN 260 | F 1 "Y_shield" H 5822 3628 50 0000 R CNN 261 | F 2 "Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical" H 5850 3650 50 0001 C CNN 262 | F 3 "~" H 5850 3650 50 0001 C CNN 263 | 1 5850 3650 264 | -1 0 0 1 265 | $EndComp 266 | $Comp 267 | L Connector:Conn_01x01_Male J8 268 | U 1 1 60769800 269 | P 5850 3900 270 | F 0 "J8" H 5822 3832 50 0001 R CNN 271 | F 1 "Z_shield" H 5822 3878 50 0000 R CNN 272 | F 2 "Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical" H 5850 3900 50 0001 C CNN 273 | F 3 "~" H 5850 3900 50 0001 C CNN 274 | 1 5850 3900 275 | -1 0 0 1 276 | $EndComp 277 | Wire Wire Line 278 | 4000 4600 4350 4600 279 | $EndSCHEMATC 280 | -------------------------------------------------------------------------------- /design/3DCapacitiveSensor.net: -------------------------------------------------------------------------------- 1 | (export (version D) 2 | (design 3 | (source "/Users/jacob/Documents/School/2021 Spring/Embedded System Design ECE 5780/Mini Project/3DCapacitiveSensor/design/3DCapacitiveSensor.sch") 4 | (date "Friday, April 30, 2021 at 06:33:45 PM") 5 | (tool "Eeschema (5.1.9-0-10_14)") 6 | (sheet (number 1) (name /) (tstamps /) 7 | (title_block 8 | (title) 9 | (company) 10 | (rev) 11 | (date) 12 | (source 3DCapacitiveSensor.sch) 13 | (comment (number 1) (value "")) 14 | (comment (number 2) (value "")) 15 | (comment (number 3) (value "")) 16 | (comment (number 4) (value ""))))) 17 | (components 18 | (comp (ref R1) 19 | (value 220K) 20 | (footprint Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal) 21 | (datasheet ~) 22 | (libsource (lib Device) (part R_US) (description "Resistor, US symbol")) 23 | (sheetpath (names /) (tstamps /)) 24 | (tstamp 607267D1)) 25 | (comp (ref R3) 26 | (value 220K) 27 | (footprint Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal) 28 | (datasheet ~) 29 | (libsource (lib Device) (part R_US) (description "Resistor, US symbol")) 30 | (sheetpath (names /) (tstamps /)) 31 | (tstamp 60726F97)) 32 | (comp (ref R5) 33 | (value 220K) 34 | (footprint Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal) 35 | (datasheet ~) 36 | (libsource (lib Device) (part R_US) (description "Resistor, US symbol")) 37 | (sheetpath (names /) (tstamps /)) 38 | (tstamp 60727144)) 39 | (comp (ref R4) 40 | (value 10K) 41 | (footprint Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal) 42 | (datasheet ~) 43 | (libsource (lib Device) (part R_US) (description "Resistor, US symbol")) 44 | (sheetpath (names /) (tstamps /)) 45 | (tstamp 6072B2A7)) 46 | (comp (ref J6) 47 | (value Z_plate) 48 | (footprint Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical) 49 | (datasheet ~) 50 | (libsource (lib Connector) (part Conn_01x01_Male) (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)")) 51 | (sheetpath (names /) (tstamps /)) 52 | (tstamp 60735CD0)) 53 | (comp (ref J5) 54 | (value Y_plate) 55 | (footprint Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical) 56 | (datasheet ~) 57 | (libsource (lib Connector) (part Conn_01x01_Male) (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)")) 58 | (sheetpath (names /) (tstamps /)) 59 | (tstamp 607354B4)) 60 | (comp (ref J4) 61 | (value X_plate) 62 | (footprint Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical) 63 | (datasheet ~) 64 | (libsource (lib Connector) (part Conn_01x01_Male) (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)")) 65 | (sheetpath (names /) (tstamps /)) 66 | (tstamp 607342FB)) 67 | (comp (ref J7) 68 | (value 3V) 69 | (footprint Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical) 70 | (datasheet ~) 71 | (libsource (lib Connector) (part Conn_01x01_Male) (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)")) 72 | (sheetpath (names /) (tstamps /)) 73 | (tstamp 60742720)) 74 | (comp (ref J1) 75 | (value "Pin Socket") 76 | (footprint Connector_PinSocket_2.54mm:PinSocket_1x06_P2.54mm_Vertical) 77 | (datasheet ~) 78 | (libsource (lib Connector) (part Conn_01x06_Female) (description "Generic connector, single row, 01x06, script generated (kicad-library-utils/schlib/autogen/connector/)")) 79 | (sheetpath (names /) (tstamps /)) 80 | (tstamp 60746578)) 81 | (comp (ref R6) 82 | (value 10K) 83 | (footprint Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal) 84 | (datasheet ~) 85 | (libsource (lib Device) (part R_US) (description "Resistor, US symbol")) 86 | (sheetpath (names /) (tstamps /)) 87 | (tstamp 6072B5B0)) 88 | (comp (ref R2) 89 | (value 10K) 90 | (footprint Resistor_THT:R_Axial_DIN0411_L9.9mm_D3.6mm_P12.70mm_Horizontal) 91 | (datasheet ~) 92 | (libsource (lib Device) (part R_US) (description "Resistor, US symbol")) 93 | (sheetpath (names /) (tstamps /)) 94 | (tstamp 6072A903)) 95 | (comp (ref J2) 96 | (value X_shield) 97 | (footprint Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical) 98 | (datasheet ~) 99 | (libsource (lib Connector) (part Conn_01x01_Male) (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)")) 100 | (sheetpath (names /) (tstamps /)) 101 | (tstamp 60768D29)) 102 | (comp (ref J3) 103 | (value Y_shield) 104 | (footprint Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical) 105 | (datasheet ~) 106 | (libsource (lib Connector) (part Conn_01x01_Male) (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)")) 107 | (sheetpath (names /) (tstamps /)) 108 | (tstamp 6076926F)) 109 | (comp (ref J8) 110 | (value Z_shield) 111 | (footprint Connector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_Vertical) 112 | (datasheet ~) 113 | (libsource (lib Connector) (part Conn_01x01_Male) (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)")) 114 | (sheetpath (names /) (tstamps /)) 115 | (tstamp 60769800))) 116 | (libparts 117 | (libpart (lib Connector) (part Conn_01x01_Male) 118 | (description "Generic connector, single row, 01x01, script generated (kicad-library-utils/schlib/autogen/connector/)") 119 | (docs ~) 120 | (footprints 121 | (fp Connector*:*)) 122 | (fields 123 | (field (name Reference) J) 124 | (field (name Value) Conn_01x01_Male)) 125 | (pins 126 | (pin (num 1) (name Pin_1) (type passive)))) 127 | (libpart (lib Connector) (part Conn_01x06_Female) 128 | (description "Generic connector, single row, 01x06, script generated (kicad-library-utils/schlib/autogen/connector/)") 129 | (docs ~) 130 | (footprints 131 | (fp Connector*:*_1x??_*)) 132 | (fields 133 | (field (name Reference) J) 134 | (field (name Value) Conn_01x06_Female)) 135 | (pins 136 | (pin (num 1) (name Pin_1) (type passive)) 137 | (pin (num 2) (name Pin_2) (type passive)) 138 | (pin (num 3) (name Pin_3) (type passive)) 139 | (pin (num 4) (name Pin_4) (type passive)) 140 | (pin (num 5) (name Pin_5) (type passive)) 141 | (pin (num 6) (name Pin_6) (type passive)))) 142 | (libpart (lib Device) (part R_US) 143 | (description "Resistor, US symbol") 144 | (docs ~) 145 | (footprints 146 | (fp R_*)) 147 | (fields 148 | (field (name Reference) R) 149 | (field (name Value) R_US)) 150 | (pins 151 | (pin (num 1) (name ~) (type passive)) 152 | (pin (num 2) (name ~) (type passive))))) 153 | (libraries 154 | (library (logical Connector) 155 | (uri "/Library/Application Support/kicad/library/Connector.lib")) 156 | (library (logical Device) 157 | (uri "/Library/Application Support/kicad/library/Device.lib"))) 158 | (nets 159 | (net (code 1) (name "Net-(J6-Pad1)") 160 | (node (ref R2) (pin 1)) 161 | (node (ref J6) (pin 1)) 162 | (node (ref R1) (pin 2))) 163 | (net (code 2) (name "Net-(J5-Pad1)") 164 | (node (ref J5) (pin 1)) 165 | (node (ref R3) (pin 2)) 166 | (node (ref R4) (pin 1))) 167 | (net (code 3) (name "Net-(J4-Pad1)") 168 | (node (ref R6) (pin 1)) 169 | (node (ref J4) (pin 1)) 170 | (node (ref R5) (pin 2))) 171 | (net (code 4) (name /shield_wire) 172 | (node (ref R5) (pin 1)) 173 | (node (ref R3) (pin 1)) 174 | (node (ref J8) (pin 1)) 175 | (node (ref J3) (pin 1)) 176 | (node (ref J2) (pin 1)) 177 | (node (ref R1) (pin 1)) 178 | (node (ref J7) (pin 1))) 179 | (net (code 5) (name "Net-(J1-Pad2)") 180 | (node (ref J1) (pin 2))) 181 | (net (code 6) (name "Net-(J1-Pad4)") 182 | (node (ref J1) (pin 4))) 183 | (net (code 7) (name "Net-(J1-Pad6)") 184 | (node (ref J1) (pin 6))) 185 | (net (code 8) (name /Z_pin) 186 | (node (ref J1) (pin 5)) 187 | (node (ref R2) (pin 2))) 188 | (net (code 9) (name /Y_pin) 189 | (node (ref J1) (pin 3)) 190 | (node (ref R4) (pin 2))) 191 | (net (code 10) (name /X_pin) 192 | (node (ref J1) (pin 1)) 193 | (node (ref R6) (pin 2))))) -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pwr_ex.c 4 | * @author MCD Application Team 5 | * @brief Extended PWR HAL module driver. 6 | * This file provides firmware functions to manage the following 7 | * functionalities of the Power Controller (PWR) peripheral: 8 | * + Extended Initialization and de-initialization functions 9 | * + Extended Peripheral Control functions 10 | * 11 | ****************************************************************************** 12 | * @attention 13 | * 14 | *

© Copyright (c) 2016 STMicroelectronics. 15 | * All rights reserved.

16 | * 17 | * This software component is licensed by ST under BSD 3-Clause license, 18 | * the "License"; You may not use this file except in compliance with the 19 | * License. You may obtain a copy of the License at: 20 | * opensource.org/licenses/BSD-3-Clause 21 | * 22 | ****************************************************************************** 23 | */ 24 | 25 | /* Includes ------------------------------------------------------------------*/ 26 | #include "stm32f0xx_hal.h" 27 | 28 | /** @addtogroup STM32F0xx_HAL_Driver 29 | * @{ 30 | */ 31 | 32 | /** @defgroup PWREx PWREx 33 | * @brief PWREx HAL module driver 34 | * @{ 35 | */ 36 | 37 | #ifdef HAL_PWR_MODULE_ENABLED 38 | 39 | /* Private typedef -----------------------------------------------------------*/ 40 | /* Private define ------------------------------------------------------------*/ 41 | /** @defgroup PWREx_Private_Constants PWREx Private Constants 42 | * @{ 43 | */ 44 | #define PVD_MODE_IT (0x00010000U) 45 | #define PVD_MODE_EVT (0x00020000U) 46 | #define PVD_RISING_EDGE (0x00000001U) 47 | #define PVD_FALLING_EDGE (0x00000002U) 48 | /** 49 | * @} 50 | */ 51 | 52 | /* Private macro -------------------------------------------------------------*/ 53 | /* Private variables ---------------------------------------------------------*/ 54 | /* Private function prototypes -----------------------------------------------*/ 55 | /* Exported functions ---------------------------------------------------------*/ 56 | 57 | /** @defgroup PWREx_Exported_Functions PWREx Exported Functions 58 | * @{ 59 | */ 60 | 61 | /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Control Functions 62 | * @brief Extended Peripheral Control functions 63 | * 64 | @verbatim 65 | 66 | =============================================================================== 67 | ##### Peripheral extended control functions ##### 68 | =============================================================================== 69 | 70 | *** PVD configuration *** 71 | ========================= 72 | [..] 73 | (+) The PVD is used to monitor the VDD power supply by comparing it to a 74 | threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR). 75 | (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower 76 | than the PVD threshold. This event is internally connected to the EXTI 77 | line16 and can generate an interrupt if enabled. This is done through 78 | HAL_PWR_ConfigPVD(), HAL_PWR_EnablePVD() functions. 79 | (+) The PVD is stopped in Standby mode. 80 | -@- PVD is not available on STM32F030x4/x6/x8 81 | 82 | *** VDDIO2 Monitor Configuration *** 83 | ==================================== 84 | [..] 85 | (+) VDDIO2 monitor is used to monitor the VDDIO2 power supply by comparing it 86 | to VREFInt Voltage 87 | (+) This monitor is internally connected to the EXTI line31 88 | and can generate an interrupt if enabled. This is done through 89 | HAL_PWREx_EnableVddio2Monitor() function. 90 | -@- VDDIO2 is available on STM32F07x/09x/04x 91 | 92 | @endverbatim 93 | * @{ 94 | */ 95 | 96 | #if defined (STM32F031x6) || defined (STM32F051x8) || \ 97 | defined (STM32F071xB) || defined (STM32F091xC) || \ 98 | defined (STM32F042x6) || defined (STM32F072xB) 99 | /** 100 | * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD). 101 | * @param sConfigPVD pointer to an PWR_PVDTypeDef structure that contains the configuration 102 | * information for the PVD. 103 | * @note Refer to the electrical characteristics of your device datasheet for 104 | * more details about the voltage threshold corresponding to each 105 | * detection level. 106 | * @retval None 107 | */ 108 | void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD) 109 | { 110 | /* Check the parameters */ 111 | assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel)); 112 | assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode)); 113 | 114 | /* Set PLS[7:5] bits according to PVDLevel value */ 115 | MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel); 116 | 117 | /* Clear any previous config. Keep it clear if no event or IT mode is selected */ 118 | __HAL_PWR_PVD_EXTI_DISABLE_EVENT(); 119 | __HAL_PWR_PVD_EXTI_DISABLE_IT(); 120 | __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); 121 | 122 | /* Configure interrupt mode */ 123 | if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT) 124 | { 125 | __HAL_PWR_PVD_EXTI_ENABLE_IT(); 126 | } 127 | 128 | /* Configure event mode */ 129 | if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT) 130 | { 131 | __HAL_PWR_PVD_EXTI_ENABLE_EVENT(); 132 | } 133 | 134 | /* Configure the edge */ 135 | if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE) 136 | { 137 | __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); 138 | } 139 | 140 | if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE) 141 | { 142 | __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); 143 | } 144 | } 145 | 146 | /** 147 | * @brief Enables the Power Voltage Detector(PVD). 148 | * @retval None 149 | */ 150 | void HAL_PWR_EnablePVD(void) 151 | { 152 | PWR->CR |= (uint32_t)PWR_CR_PVDE; 153 | } 154 | 155 | /** 156 | * @brief Disables the Power Voltage Detector(PVD). 157 | * @retval None 158 | */ 159 | void HAL_PWR_DisablePVD(void) 160 | { 161 | PWR->CR &= ~((uint32_t)PWR_CR_PVDE); 162 | } 163 | 164 | /** 165 | * @brief This function handles the PWR PVD interrupt request. 166 | * @note This API should be called under the PVD_IRQHandler() or PVD_VDDIO2_IRQHandler(). 167 | * @retval None 168 | */ 169 | void HAL_PWR_PVD_IRQHandler(void) 170 | { 171 | /* Check PWR exti flag */ 172 | if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET) 173 | { 174 | /* PWR PVD interrupt user callback */ 175 | HAL_PWR_PVDCallback(); 176 | 177 | /* Clear PWR Exti pending bit */ 178 | __HAL_PWR_PVD_EXTI_CLEAR_FLAG(); 179 | } 180 | } 181 | 182 | /** 183 | * @brief PWR PVD interrupt callback 184 | * @retval None 185 | */ 186 | __weak void HAL_PWR_PVDCallback(void) 187 | { 188 | /* NOTE : This function Should not be modified, when the callback is needed, 189 | the HAL_PWR_PVDCallback could be implemented in the user file 190 | */ 191 | } 192 | 193 | #endif /* defined (STM32F031x6) || defined (STM32F051x8) || */ 194 | /* defined (STM32F071xB) || defined (STM32F091xC) || */ 195 | /* defined (STM32F042x6) || defined (STM32F072xB) */ 196 | 197 | #if defined (STM32F042x6) || defined (STM32F048xx) || \ 198 | defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \ 199 | defined (STM32F091xC) || defined (STM32F098xx) 200 | /** 201 | * @brief Enable VDDIO2 monitor: enable Exti 31 and falling edge detection. 202 | * @note If Exti 31 is enable correlty and VDDIO2 voltage goes below Vrefint, 203 | an interrupt is generated Irq line 1. 204 | NVIS has to be enable by user. 205 | * @retval None 206 | */ 207 | void HAL_PWREx_EnableVddio2Monitor(void) 208 | { 209 | __HAL_PWR_VDDIO2_EXTI_ENABLE_IT(); 210 | __HAL_PWR_VDDIO2_EXTI_ENABLE_FALLING_EDGE(); 211 | } 212 | 213 | /** 214 | * @brief Disable the Vddio2 Monitor. 215 | * @retval None 216 | */ 217 | void HAL_PWREx_DisableVddio2Monitor(void) 218 | { 219 | __HAL_PWR_VDDIO2_EXTI_DISABLE_IT(); 220 | __HAL_PWR_VDDIO2_EXTI_DISABLE_FALLING_EDGE(); 221 | 222 | } 223 | 224 | /** 225 | * @brief This function handles the PWR Vddio2 monitor interrupt request. 226 | * @note This API should be called under the VDDIO2_IRQHandler() PVD_VDDIO2_IRQHandler(). 227 | * @retval None 228 | */ 229 | void HAL_PWREx_Vddio2Monitor_IRQHandler(void) 230 | { 231 | /* Check PWR exti flag */ 232 | if(__HAL_PWR_VDDIO2_EXTI_GET_FLAG() != RESET) 233 | { 234 | /* PWR Vddio2 monitor interrupt user callback */ 235 | HAL_PWREx_Vddio2MonitorCallback(); 236 | 237 | /* Clear PWR Exti pending bit */ 238 | __HAL_PWR_VDDIO2_EXTI_CLEAR_FLAG(); 239 | } 240 | } 241 | 242 | /** 243 | * @brief PWR Vddio2 Monitor interrupt callback 244 | * @retval None 245 | */ 246 | __weak void HAL_PWREx_Vddio2MonitorCallback(void) 247 | { 248 | /* NOTE : This function Should not be modified, when the callback is needed, 249 | the HAL_PWREx_Vddio2MonitorCallback could be implemented in the user file 250 | */ 251 | } 252 | 253 | #endif /* defined (STM32F042x6) || defined (STM32F048xx) || \ 254 | defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \ 255 | defined (STM32F091xC) || defined (STM32F098xx) */ 256 | 257 | /** 258 | * @} 259 | */ 260 | 261 | /** 262 | * @} 263 | */ 264 | 265 | #endif /* HAL_PWR_MODULE_ENABLED */ 266 | /** 267 | * @} 268 | */ 269 | 270 | /** 271 | * @} 272 | */ 273 | 274 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 275 | -------------------------------------------------------------------------------- /mcu/Drivers/CMSIS/Include/cmsis_compiler.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_compiler.h 3 | * @brief CMSIS compiler generic header file 4 | * @version V5.0.4 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef __CMSIS_COMPILER_H 26 | #define __CMSIS_COMPILER_H 27 | 28 | #include 29 | 30 | /* 31 | * Arm Compiler 4/5 32 | */ 33 | #if defined ( __CC_ARM ) 34 | #include "cmsis_armcc.h" 35 | 36 | 37 | /* 38 | * Arm Compiler 6 (armclang) 39 | */ 40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 41 | #include "cmsis_armclang.h" 42 | 43 | 44 | /* 45 | * GNU Compiler 46 | */ 47 | #elif defined ( __GNUC__ ) 48 | #include "cmsis_gcc.h" 49 | 50 | 51 | /* 52 | * IAR Compiler 53 | */ 54 | #elif defined ( __ICCARM__ ) 55 | #include 56 | 57 | 58 | /* 59 | * TI Arm Compiler 60 | */ 61 | #elif defined ( __TI_ARM__ ) 62 | #include 63 | 64 | #ifndef __ASM 65 | #define __ASM __asm 66 | #endif 67 | #ifndef __INLINE 68 | #define __INLINE inline 69 | #endif 70 | #ifndef __STATIC_INLINE 71 | #define __STATIC_INLINE static inline 72 | #endif 73 | #ifndef __STATIC_FORCEINLINE 74 | #define __STATIC_FORCEINLINE __STATIC_INLINE 75 | #endif 76 | #ifndef __NO_RETURN 77 | #define __NO_RETURN __attribute__((noreturn)) 78 | #endif 79 | #ifndef __USED 80 | #define __USED __attribute__((used)) 81 | #endif 82 | #ifndef __WEAK 83 | #define __WEAK __attribute__((weak)) 84 | #endif 85 | #ifndef __PACKED 86 | #define __PACKED __attribute__((packed)) 87 | #endif 88 | #ifndef __PACKED_STRUCT 89 | #define __PACKED_STRUCT struct __attribute__((packed)) 90 | #endif 91 | #ifndef __PACKED_UNION 92 | #define __PACKED_UNION union __attribute__((packed)) 93 | #endif 94 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 95 | struct __attribute__((packed)) T_UINT32 { uint32_t v; }; 96 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 97 | #endif 98 | #ifndef __UNALIGNED_UINT16_WRITE 99 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 100 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 101 | #endif 102 | #ifndef __UNALIGNED_UINT16_READ 103 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 104 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 105 | #endif 106 | #ifndef __UNALIGNED_UINT32_WRITE 107 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 108 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 109 | #endif 110 | #ifndef __UNALIGNED_UINT32_READ 111 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 112 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 113 | #endif 114 | #ifndef __ALIGNED 115 | #define __ALIGNED(x) __attribute__((aligned(x))) 116 | #endif 117 | #ifndef __RESTRICT 118 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 119 | #define __RESTRICT 120 | #endif 121 | 122 | 123 | /* 124 | * TASKING Compiler 125 | */ 126 | #elif defined ( __TASKING__ ) 127 | /* 128 | * The CMSIS functions have been implemented as intrinsics in the compiler. 129 | * Please use "carm -?i" to get an up to date list of all intrinsics, 130 | * Including the CMSIS ones. 131 | */ 132 | 133 | #ifndef __ASM 134 | #define __ASM __asm 135 | #endif 136 | #ifndef __INLINE 137 | #define __INLINE inline 138 | #endif 139 | #ifndef __STATIC_INLINE 140 | #define __STATIC_INLINE static inline 141 | #endif 142 | #ifndef __STATIC_FORCEINLINE 143 | #define __STATIC_FORCEINLINE __STATIC_INLINE 144 | #endif 145 | #ifndef __NO_RETURN 146 | #define __NO_RETURN __attribute__((noreturn)) 147 | #endif 148 | #ifndef __USED 149 | #define __USED __attribute__((used)) 150 | #endif 151 | #ifndef __WEAK 152 | #define __WEAK __attribute__((weak)) 153 | #endif 154 | #ifndef __PACKED 155 | #define __PACKED __packed__ 156 | #endif 157 | #ifndef __PACKED_STRUCT 158 | #define __PACKED_STRUCT struct __packed__ 159 | #endif 160 | #ifndef __PACKED_UNION 161 | #define __PACKED_UNION union __packed__ 162 | #endif 163 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 164 | struct __packed__ T_UINT32 { uint32_t v; }; 165 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 166 | #endif 167 | #ifndef __UNALIGNED_UINT16_WRITE 168 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 169 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 170 | #endif 171 | #ifndef __UNALIGNED_UINT16_READ 172 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 173 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 174 | #endif 175 | #ifndef __UNALIGNED_UINT32_WRITE 176 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 177 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 178 | #endif 179 | #ifndef __UNALIGNED_UINT32_READ 180 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 181 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 182 | #endif 183 | #ifndef __ALIGNED 184 | #define __ALIGNED(x) __align(x) 185 | #endif 186 | #ifndef __RESTRICT 187 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 188 | #define __RESTRICT 189 | #endif 190 | 191 | 192 | /* 193 | * COSMIC Compiler 194 | */ 195 | #elif defined ( __CSMC__ ) 196 | #include 197 | 198 | #ifndef __ASM 199 | #define __ASM _asm 200 | #endif 201 | #ifndef __INLINE 202 | #define __INLINE inline 203 | #endif 204 | #ifndef __STATIC_INLINE 205 | #define __STATIC_INLINE static inline 206 | #endif 207 | #ifndef __STATIC_FORCEINLINE 208 | #define __STATIC_FORCEINLINE __STATIC_INLINE 209 | #endif 210 | #ifndef __NO_RETURN 211 | // NO RETURN is automatically detected hence no warning here 212 | #define __NO_RETURN 213 | #endif 214 | #ifndef __USED 215 | #warning No compiler specific solution for __USED. __USED is ignored. 216 | #define __USED 217 | #endif 218 | #ifndef __WEAK 219 | #define __WEAK __weak 220 | #endif 221 | #ifndef __PACKED 222 | #define __PACKED @packed 223 | #endif 224 | #ifndef __PACKED_STRUCT 225 | #define __PACKED_STRUCT @packed struct 226 | #endif 227 | #ifndef __PACKED_UNION 228 | #define __PACKED_UNION @packed union 229 | #endif 230 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 231 | @packed struct T_UINT32 { uint32_t v; }; 232 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 233 | #endif 234 | #ifndef __UNALIGNED_UINT16_WRITE 235 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 236 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 237 | #endif 238 | #ifndef __UNALIGNED_UINT16_READ 239 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 240 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 241 | #endif 242 | #ifndef __UNALIGNED_UINT32_WRITE 243 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 244 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 245 | #endif 246 | #ifndef __UNALIGNED_UINT32_READ 247 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 248 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 249 | #endif 250 | #ifndef __ALIGNED 251 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 252 | #define __ALIGNED(x) 253 | #endif 254 | #ifndef __RESTRICT 255 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 256 | #define __RESTRICT 257 | #endif 258 | 259 | 260 | #else 261 | #error Unknown compiler. 262 | #endif 263 | 264 | 265 | #endif /* __CMSIS_COMPILER_H */ 266 | 267 | -------------------------------------------------------------------------------- /mcu/Core/Src/motor.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------------------------------------------- 2 | * Motor Control and Initialization Functions 3 | * ------------------------------------------------------------------------------------------------------------- 4 | */ 5 | #include "motor.h" 6 | 7 | volatile int16_t error_integral = 0; // Integrated error signal 8 | volatile uint8_t duty_cycle = 0; // Output PWM duty cycle 9 | volatile int16_t target_rpm = 0; // Desired speed target 10 | volatile int16_t motor_speed = 0; // Measured motor speed 11 | volatile int8_t adc_value = 0; // ADC measured motor current 12 | volatile int16_t error = 0; // Speed error signal 13 | volatile uint8_t Kp = 1; // Proportional gain 14 | volatile uint8_t Ki = 1; // Integral gain 15 | 16 | // Sets up the entire motor drive system 17 | void motor_init(void) { 18 | pwm_init(); 19 | encoder_init(); 20 | ADC_init(); 21 | } 22 | 23 | // Sets up the PWM and direction signals to drive the H-Bridge 24 | void pwm_init(void) { 25 | 26 | // Set up pin PA4 for H-bridge PWM output (TIMER 14 CH1) 27 | GPIOA->MODER |= (1 << 9); 28 | GPIOA->MODER &= ~(1 << 8); 29 | 30 | // Set PA4 to AF4, 31 | GPIOA->AFR[0] &= 0xFFF0FFFF; // clear PA4 bits, 32 | GPIOA->AFR[0] |= (1 << 18); 33 | 34 | // Set up a PA5, PA6 as GPIO output pins for motor direction control 35 | GPIOA->MODER &= 0xFFFFC3FF; // clear PA5, PA6 bits, 36 | GPIOA->MODER |= (1 << 10) | (1 << 12); 37 | 38 | // Initialize one direction pin to high, the other low 39 | GPIOA->ODR |= (1 << 5); 40 | GPIOA->ODR &= ~(1 << 6); 41 | 42 | // Set up PWM timer 43 | RCC->APB1ENR |= RCC_APB1ENR_TIM14EN; 44 | TIM14->CR1 = 0; // Clear control registers 45 | TIM14->CCMR1 = 0; // (prevents having to manually clear bits) 46 | TIM14->CCER = 0; 47 | 48 | // Set output-compare CH1 to PWM1 mode and enable CCR1 preload buffer 49 | TIM14->CCMR1 |= (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE); 50 | TIM14->CCER |= TIM_CCER_CC1E; // Enable capture-compare channel 1 51 | TIM14->PSC = 1; // Run timer on 24Mhz 52 | TIM14->ARR = 1200; // PWM at 20kHz 53 | TIM14->CCR1 = 0; // Start PWM at 0% duty cycle 54 | 55 | TIM14->CR1 |= TIM_CR1_CEN; // Enable timer 56 | } 57 | 58 | // Set the duty cycle of the PWM, accepts (0-100) 59 | void pwm_setDutyCycle(uint8_t duty) { 60 | if (duty <= 100) { 61 | TIM14->CCR1 = 62 | ((uint32_t)duty * TIM14->ARR) / 100; // Use linear transform to produce CCR1 value 63 | // (CCR1 == "pulse" parameter in PWM struct used by peripheral library) 64 | } 65 | } 66 | 67 | // Sets up encoder interface to read motor speed 68 | void encoder_init(void) { 69 | 70 | // Set up encoder input pins (TIMER 3 CH1 and CH2) 71 | RCC->AHBENR |= RCC_AHBENR_GPIOBEN; 72 | 73 | GPIOB->MODER &= ~(GPIO_MODER_MODER4_0 | GPIO_MODER_MODER5_0); 74 | GPIOB->MODER |= (GPIO_MODER_MODER4_1 | GPIO_MODER_MODER5_1); 75 | GPIOB->AFR[0] |= ((1 << 16) | (1 << 20)); 76 | 77 | // Set up encoder interface (TIM3 encoder input mode) 78 | RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; 79 | TIM3->CCMR1 = 0; 80 | TIM3->CCER = 0; 81 | TIM3->SMCR = 0; 82 | TIM3->CR1 = 0; 83 | 84 | TIM3->CCMR1 |= 85 | (TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0); // TI1FP1 and TI2FP2 signals connected to CH1 and CH2 86 | TIM3->SMCR |= 87 | (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0); // Capture encoder on both rising and falling edges 88 | TIM3->ARR = 0xFFFF; // Set ARR to top of timer (longest possible period) 89 | TIM3->CNT = 0x7FFF; // Bias at midpoint to allow for negative rotation 90 | // (Could also cast unsigned register to signed number to get negative numbers if it rotates 91 | // backwards past zero 92 | // just another option, the mid-bias is a bit simpler to understand though.) 93 | TIM3->CR1 |= TIM_CR1_CEN; // Enable timer 94 | 95 | // Configure a second timer (TIM6) to fire an ISR on update event 96 | // Used to periodically check and update speed variable 97 | RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; 98 | 99 | // Select PSC and ARR values that give an appropriate interrupt rate 100 | TIM6->PSC = 15; 101 | TIM6->ARR = 50000 / 2; 102 | 103 | TIM6->DIER |= TIM_DIER_UIE; // Enable update event interrupt 104 | TIM6->CR1 |= TIM_CR1_CEN; // Enable Timer 105 | 106 | NVIC_EnableIRQ(TIM6_DAC_IRQn); // Enable interrupt in NVIC 107 | NVIC_SetPriority(TIM6_DAC_IRQn, 2); 108 | } 109 | 110 | // Encoder interrupt to calculate motor speed, also manages PI controller 111 | void TIM6_DAC_IRQHandler(void) { 112 | /* Calculate the motor speed in raw encoder counts 113 | * Note the motor speed is signed! Motor can be run in reverse. 114 | * Speed is measured by how far the counter moved from center point 115 | */ 116 | motor_speed = (TIM3->CNT - 0x7FFF); 117 | TIM3->CNT = 0x7FFF; // Reset back to center point 118 | 119 | // Call the PI update function 120 | PI_update(); 121 | 122 | TIM6->SR &= ~TIM_SR_UIF; // Acknowledge the interrupt 123 | } 124 | 125 | void ADC_init(void) { 126 | 127 | // Configure PA1 for ADC input (used for current monitoring) 128 | GPIOA->MODER |= (GPIO_MODER_MODER1_0 | GPIO_MODER_MODER1_1); 129 | 130 | // Configure ADC to 8-bit continuous-run mode, (asynchronous clock mode) 131 | RCC->APB2ENR |= RCC_APB2ENR_ADCEN; 132 | 133 | ADC1->CFGR1 = 0; // Default resolution is 12-bit (RES[1:0] = 00 --> 12-bit) 134 | ADC1->CFGR1 |= ADC_CFGR1_CONT; // Set to continuous mode 135 | ADC1->CHSELR |= ADC_CHSELR_CHSEL1; // Enable channel 1 136 | 137 | ADC1->CR = 0; 138 | ADC1->CR |= ADC_CR_ADCAL; // Perform self calibration 139 | while (ADC1->CR & ADC_CR_ADCAL) 140 | ; // Delay until calibration is complete 141 | 142 | ADC1->CR |= ADC_CR_ADEN; // Enable ADC 143 | while (!(ADC1->ISR & ADC_ISR_ADRDY)) 144 | ; // Wait until ADC ready 145 | ADC1->CR |= ADC_CR_ADSTART; // Signal conversion start 146 | } 147 | 148 | void PI_update(void) { 149 | 150 | /* Run PI control loop 151 | * 152 | * Make sure to use the indicated variable names. This allows STMStudio to monitor 153 | * the condition of the system! 154 | * 155 | * target_rpm -> target motor speed in RPM 156 | * motor_speed -> raw motor speed in encoder counts 157 | * error -> error signal (difference between measured speed and target) 158 | * error_integral -> integrated error signal 159 | * Kp -> Proportional Gain 160 | * Ki -> Integral Gain 161 | * output -> raw output signal from PI controller 162 | * duty_cycle -> used to report the duty cycle of the system 163 | * adc_value -> raw ADC counts to report current 164 | * 165 | */ 166 | 167 | /// Calculate error signal and write to "error" variable 168 | 169 | // My motor says 540-ish pulses per revolution, but reports more like 625-ish pulses. 170 | // It also only has a max RPM of 48 at 6 Volts. 171 | // motor_speed is count of ENCA and ENCB posedge's and negedge's 172 | error = (target_rpm * 625 * 4 / 60) - (motor_speed * 20); 173 | 174 | /* Hint: Remember that your calculated motor speed may not be directly in RPM! 175 | * You will need to convert the target or encoder speeds to the same units. 176 | * I recommend converting to whatever units result in larger values, gives 177 | * more resolution. 178 | */ 179 | 180 | /// Calculate integral portion of PI controller, write to "error_integral" variable 181 | error_integral += Ki * error; 182 | 183 | /// Clamp the value of the integral to a limited positive range 184 | if (error_integral < 0) { 185 | error_integral = 0; 186 | } else if (error_integral > 3200) { 187 | error_integral = 3200; 188 | } 189 | 190 | /* Hint: The value clamp is needed to prevent excessive "windup" in the integral. 191 | * You'll read more about this for the post-lab. The exact value is arbitrary 192 | * but affects the PI tuning. 193 | * Recommend that you clamp between 0 and 3200 (what is used in the lab solution) 194 | */ 195 | 196 | /// Calculate proportional portion, add integral and write to "output" variable 197 | int16_t output = Kp * error + error_integral; 198 | 199 | /* Because the calculated values for the PI controller are significantly larger than 200 | * the allowable range for duty cycle, you'll need to divide the result down into 201 | * an appropriate range. (Maximum integral clamp / X = 100% duty cycle) 202 | * 203 | * Hint: If you chose 3200 for the integral clamp you should divide by 32 (right shift by 5 204 | * bits), this will give you an output of 100 at maximum integral "windup". 205 | * 206 | * This division also turns the above calculations into pseudo fixed-point. This is because 207 | * the lowest 5 bits act as if they were below the decimal point until the division where they 208 | * were truncated off to result in an integer value. 209 | * 210 | * Technically most of this is arbitrary, in a real system you would want to use a fixed-point 211 | * math library. The main difference that these values make is the difference in the gain values 212 | * required for tuning. 213 | */ 214 | 215 | /// Divide the output into the proper range for output adjustment 216 | output >>= 5; 217 | 218 | /// Clamp the output value between 0 and 100 219 | if (output < 0) { 220 | output = 0; 221 | } else if (output > 100) { 222 | output = 100; 223 | } 224 | 225 | pwm_setDutyCycle(output); 226 | duty_cycle = output; // For debug viewing 227 | 228 | // Read the ADC value for current monitoring, actual conversion into meaningful units 229 | // will be performed by STMStudio 230 | if (ADC1->ISR & ADC_ISR_EOC) { // If the ADC has new data for us 231 | adc_value = ADC1->DR; // Read the motor current for debug viewing 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /mcu/Core/Src/system_stm32f0xx.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.c 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File. 6 | * 7 | * 1. This file provides two functions and one global variable to be called from 8 | * user application: 9 | * - SystemInit(): This function is called at startup just after reset and 10 | * before branch to main program. This call is made inside 11 | * the "startup_stm32f0xx.s" file. 12 | * 13 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used 14 | * by the user application to setup the SysTick 15 | * timer or configure other parameters. 16 | * 17 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must 18 | * be called whenever the core clock is changed 19 | * during program execution. 20 | * 21 | * 22 | ****************************************************************************** 23 | * @attention 24 | * 25 | *

© Copyright (c) 2016 STMicroelectronics. 26 | * All rights reserved.

27 | * 28 | * This software component is licensed by ST under BSD 3-Clause license, 29 | * the "License"; You may not use this file except in compliance with the 30 | * License. You may obtain a copy of the License at: 31 | * opensource.org/licenses/BSD-3-Clause 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f0xx_system 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup STM32F0xx_System_Private_Includes 45 | * @{ 46 | */ 47 | 48 | #include "stm32f0xx.h" 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | /** @addtogroup STM32F0xx_System_Private_TypesDefinitions 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @addtogroup STM32F0xx_System_Private_Defines 63 | * @{ 64 | */ 65 | #if !defined(HSE_VALUE) 66 | #define HSE_VALUE \ 67 | ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz. \ 68 | This value can be provided and adapted by the user application. */ 69 | #endif /* HSE_VALUE */ 70 | 71 | #if !defined(HSI_VALUE) 72 | #define HSI_VALUE \ 73 | ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz. \ 74 | This value can be provided and adapted by the user application. */ 75 | #endif /* HSI_VALUE */ 76 | 77 | #if !defined(HSI48_VALUE) 78 | #define HSI48_VALUE \ 79 | ((uint32_t)48000000) /*!< Default value of the HSI48 Internal oscillator in Hz. \ 80 | This value can be provided and adapted by the user application. */ 81 | #endif /* HSI48_VALUE */ 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @addtogroup STM32F0xx_System_Private_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @addtogroup STM32F0xx_System_Private_Variables 95 | * @{ 96 | */ 97 | /* This variable is updated in three ways: 98 | 1) by calling CMSIS function SystemCoreClockUpdate() 99 | 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 100 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 101 | Note: If you use this function to configure the system clock; then there 102 | is no need to call the 2 first functions listed above, since SystemCoreClock 103 | variable is updated automatically. 104 | */ 105 | uint32_t SystemCoreClock = 8000000; 106 | 107 | const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; 108 | const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; 109 | 110 | /** 111 | * @} 112 | */ 113 | 114 | /** @addtogroup STM32F0xx_System_Private_FunctionPrototypes 115 | * @{ 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** @addtogroup STM32F0xx_System_Private_Functions 123 | * @{ 124 | */ 125 | 126 | /** 127 | * @brief Setup the microcontroller system 128 | * @param None 129 | * @retval None 130 | */ 131 | void SystemInit(void) { 132 | /* NOTE :SystemInit(): This function is called at startup just after reset and 133 | before branch to main program. This call is made inside 134 | the "startup_stm32f0xx.s" file. 135 | User can setups the default system clock (System clock source, PLL 136 | Multiplier and Divider factors, AHB/APBx prescalers and Flash settings). 137 | */ 138 | } 139 | 140 | /** 141 | * @brief Update SystemCoreClock variable according to Clock Register Values. 142 | * The SystemCoreClock variable contains the core clock (HCLK), it can 143 | * be used by the user application to setup the SysTick timer or configure 144 | * other parameters. 145 | * 146 | * @note Each time the core clock (HCLK) changes, this function must be called 147 | * to update SystemCoreClock variable value. Otherwise, any configuration 148 | * based on this variable will be incorrect. 149 | * 150 | * @note - The system frequency computed by this function is not the real 151 | * frequency in the chip. It is calculated based on the predefined 152 | * constant and the selected clock source: 153 | * 154 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) 155 | * 156 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) 157 | * 158 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 159 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. 160 | * 161 | * (*) HSI_VALUE is a constant defined in stm32f0xx_hal_conf.h file (default value 162 | * 8 MHz) but the real value may vary depending on the variations 163 | * in voltage and temperature. 164 | * 165 | * (**) HSE_VALUE is a constant defined in stm32f0xx_hal_conf.h file (its value 166 | * depends on the application requirements), user has to ensure that HSE_VALUE 167 | * is same as the real frequency of the crystal used. Otherwise, this function 168 | * may have wrong result. 169 | * 170 | * - The result of this function could be not correct when using fractional 171 | * value for HSE crystal. 172 | * 173 | * @param None 174 | * @retval None 175 | */ 176 | void SystemCoreClockUpdate(void) { 177 | uint32_t tmp = 0, pllmull = 0, pllsource = 0, predivfactor = 0; 178 | 179 | /* Get SYSCLK source -------------------------------------------------------*/ 180 | tmp = RCC->CFGR & RCC_CFGR_SWS; 181 | 182 | switch (tmp) { 183 | case RCC_CFGR_SWS_HSI: /* HSI used as system clock */ 184 | SystemCoreClock = HSI_VALUE; 185 | break; 186 | case RCC_CFGR_SWS_HSE: /* HSE used as system clock */ 187 | SystemCoreClock = HSE_VALUE; 188 | break; 189 | case RCC_CFGR_SWS_PLL: /* PLL used as system clock */ 190 | /* Get PLL clock source and multiplication factor ----------------------*/ 191 | pllmull = RCC->CFGR & RCC_CFGR_PLLMUL; 192 | pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; 193 | pllmull = (pllmull >> 18) + 2; 194 | predivfactor = (RCC->CFGR2 & RCC_CFGR2_PREDIV) + 1; 195 | 196 | if (pllsource == RCC_CFGR_PLLSRC_HSE_PREDIV) { 197 | /* HSE used as PLL clock source : SystemCoreClock = HSE/PREDIV * PLLMUL */ 198 | SystemCoreClock = (HSE_VALUE / predivfactor) * pllmull; 199 | } 200 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || \ 201 | defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) 202 | else if (pllsource == RCC_CFGR_PLLSRC_HSI48_PREDIV) { 203 | /* HSI48 used as PLL clock source : SystemCoreClock = HSI48/PREDIV * PLLMUL */ 204 | SystemCoreClock = (HSI48_VALUE / predivfactor) * pllmull; 205 | } 206 | #endif /* STM32F042x6 || STM32F048xx || STM32F072xB || STM32F078xx || STM32F091xC || STM32F098xx \ 207 | */ 208 | else { 209 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6) || \ 210 | defined(STM32F078xx) || defined(STM32F071xB) || defined(STM32F072xB) || \ 211 | defined(STM32F070xB) || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC) 212 | /* HSI used as PLL clock source : SystemCoreClock = HSI/PREDIV * PLLMUL */ 213 | SystemCoreClock = (HSI_VALUE / predivfactor) * pllmull; 214 | #else 215 | /* HSI used as PLL clock source : SystemCoreClock = HSI/2 * PLLMUL */ 216 | SystemCoreClock = (HSI_VALUE >> 1) * pllmull; 217 | #endif /* STM32F042x6 || STM32F048xx || STM32F070x6 || \ 218 | STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || \ 219 | STM32F091xC || STM32F098xx || STM32F030xC */ 220 | } 221 | break; 222 | default: /* HSI used as system clock */ 223 | SystemCoreClock = HSI_VALUE; 224 | break; 225 | } 226 | /* Compute HCLK clock frequency ----------------*/ 227 | /* Get HCLK prescaler */ 228 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; 229 | /* HCLK clock frequency */ 230 | SystemCoreClock >>= tmp; 231 | } 232 | 233 | /** 234 | * @} 235 | */ 236 | 237 | /** 238 | * @} 239 | */ 240 | 241 | /** 242 | * @} 243 | */ 244 | 245 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 246 | -------------------------------------------------------------------------------- /client/Controller/Controller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Client3DCapacitiveSensor.View; 3 | using System.Threading; 4 | using System.IO.Ports; 5 | 6 | namespace Client3DCapacitiveSensor.Controller { 7 | 8 | /// 9 | /// This class serves as the application controller. 10 | /// 11 | public class Controller { 12 | 13 | /* 14 | * Note that no XYZ coordinate inputs should be negative! 15 | * Also note that (0,0,0) is inner-most corner of the cubic 3D Capacitor and that 16 | * ('MAX_X_INPUT','MAX_X_INPUT','MAX_X_INPUT') should be the furthest coordinate from 17 | * the inner-most corner (aka no hand detected in the 3D Capacitor). 18 | */ 19 | private static readonly int MAX_X_INPUT = 100; 20 | private static readonly int MAX_Y_INPUT = 100; 21 | private static readonly int MAX_Z_INPUT = 100; 22 | private static readonly int Z_MIN_OF_MOUSE_LEFT_BUTTON_DOWN = 0; 23 | private static readonly int Z_MAX_OF_MOUSE_LEFT_BUTTON_DOWN = 20; 24 | private static readonly string SERIAL_INPUT_COORDINATES_DELIMITER = ","; 25 | 26 | private ViewController viewController; 27 | private Thread viewControllerthread; 28 | private CursorController cursorController; 29 | private SerialInterface serialInterface; 30 | private Thread serialInterfaceThread; 31 | private bool serialInterfaceStopFlag; 32 | private int xMin, yMin, zMin, xMax, yMax, zMax; 33 | 34 | /// 35 | /// Instantiates a new . 36 | /// 37 | public Controller() { 38 | viewController = new ViewController(StartButtonClickHandler, StopButtonClickHandler); 39 | viewControllerthread = new Thread((ThreadStart)delegate { 40 | viewController.Start(); 41 | }); 42 | cursorController = new CursorController(MAX_X_INPUT, MAX_Y_INPUT); 43 | serialInterfaceStopFlag = false; 44 | xMin = yMin = zMin = xMax = yMax = zMax = -1; 45 | } 46 | 47 | /// 48 | /// Starts the controller. 49 | /// 50 | public void Start() { 51 | viewControllerthread.Start(); 52 | } 53 | 54 | /// 55 | /// 56 | /// 57 | public bool StartButtonClickHandler(string comPortNumber, string baudRate, string parity, string dataBits, string stopBits) { 58 | int parsedBaudRate; 59 | Parity parsedParity; 60 | int parsedDataBits; 61 | StopBits parsedStopBits; 62 | 63 | // Parse UI parameters 64 | try { 65 | parsedBaudRate = int.Parse(baudRate); 66 | 67 | switch (parity) { 68 | case "None": 69 | parsedParity = Parity.None; 70 | break; 71 | case "Even": 72 | parsedParity = Parity.Even; 73 | break; 74 | default: 75 | throw new ArgumentException("Unsupported parity: " + parity); 76 | } 77 | 78 | parsedDataBits = int.Parse(dataBits); 79 | 80 | switch (stopBits) { 81 | case "One": 82 | parsedStopBits = StopBits.One; 83 | break; 84 | case "Two": 85 | parsedStopBits = StopBits.Two; 86 | break; 87 | case "None": 88 | parsedStopBits = StopBits.None; 89 | break; 90 | default: 91 | throw new ArgumentException("Unsupported stop bits: " + stopBits); 92 | } 93 | } catch (Exception exception) { 94 | viewController.ShowError("Invalid inputs!\n" + exception.Message); 95 | return false; 96 | } 97 | 98 | try { 99 | serialInterface = new SerialInterface(comPortNumber, parsedBaudRate, parsedParity, parsedDataBits, parsedStopBits); 100 | serialInterface.Start(); 101 | } catch (Exception exception) { 102 | viewController.ShowError("Could not establish serial interface!\n" + exception.Message); 103 | return false; 104 | } 105 | 106 | serialInterfaceStopFlag = false; 107 | 108 | serialInterfaceThread = new Thread(new ThreadStart(SerialInterfaceHandlerLoop)); 109 | serialInterfaceThread.Start(); 110 | 111 | return true; 112 | } 113 | 114 | /// 115 | /// 116 | /// 117 | public bool StopButtonClickHandler() { 118 | try { 119 | serialInterfaceStopFlag = true; 120 | serialInterface.Stop(); 121 | 122 | // Wait for thread to stop (throw exception if not stopped after 5 seconds) 123 | serialInterfaceThread.Join(5000); 124 | } catch (Exception exception) { 125 | viewController.ShowError("Error stopping serial interface!\n" + exception.Message); 126 | } 127 | 128 | return true; 129 | } 130 | 131 | /// 132 | /// Handles the serial interface data loop. 133 | /// 134 | private void SerialInterfaceHandlerLoop() { 135 | while (!serialInterfaceStopFlag) { 136 | string serialLine; 137 | try { 138 | serialLine = serialInterface.ReadLine(); 139 | } catch (Exception exception) { 140 | if (!serialInterfaceStopFlag) { 141 | viewController.ShowError("Error reading serial interface!\n" + exception.Message); 142 | } 143 | return; 144 | } 145 | 146 | System.Diagnostics.Debug.WriteLine(serialLine); 147 | 148 | string[] coordinateStrings = serialLine.Split(SERIAL_INPUT_COORDINATES_DELIMITER); 149 | if (serialLine.Contains("min")) { 150 | // Parse the minimum data 151 | try { 152 | xMin = int.Parse(coordinateStrings[1]); 153 | yMin = int.Parse(coordinateStrings[2]); 154 | zMin = int.Parse(coordinateStrings[3]); 155 | } catch (Exception exception) { 156 | System.Diagnostics.Debug.WriteLine("Invalid input: " + serialLine + "\n" + exception.Message); 157 | continue; 158 | } 159 | } else if (serialLine.Contains("max")) { 160 | // Parse the maximum data 161 | try { 162 | xMax = int.Parse(coordinateStrings[1]); 163 | yMax = int.Parse(coordinateStrings[2]); 164 | zMax = int.Parse(coordinateStrings[3]); 165 | } catch (Exception exception) { 166 | System.Diagnostics.Debug.WriteLine("Invalid input: " + serialLine + "\n" + exception.Message); 167 | continue; 168 | } 169 | } else { 170 | if (xMin == -1 || yMin == -1 || zMin == -1 || 171 | xMax == -1 || yMax == -1 || zMax == -1) { 172 | System.Diagnostics.Debug.WriteLine("Minimums and Maximums not received!"); 173 | continue; 174 | } 175 | 176 | int x, y, z; 177 | // Parse the data 178 | try { 179 | x = int.Parse(coordinateStrings[0]); 180 | y = int.Parse(coordinateStrings[1]); 181 | z = int.Parse(coordinateStrings[2]); 182 | } catch (Exception exception) { 183 | System.Diagnostics.Debug.WriteLine("Invalid input: " + serialLine + "\n" + exception.Message); 184 | continue; 185 | } 186 | 187 | System.Diagnostics.Debug.WriteLine(((double)(x - xMin) / (xMax - xMin))); 188 | 189 | // Noramlize coordinates 190 | x = (int)(((double)(x - xMin) / (xMax - xMin)) * (double)MAX_X_INPUT); 191 | y = (int)(((double)(y - yMin) / (yMax - yMin)) * (double)MAX_Y_INPUT); 192 | z = (int)(((double)(z - zMin) / (zMax - zMin)) * (double)MAX_Z_INPUT); 193 | 194 | // Clamp coordinates 195 | if (x < 0) { 196 | x = 0; 197 | } else if (x > MAX_X_INPUT) { 198 | x = MAX_X_INPUT; 199 | } 200 | if (y < 0) { 201 | y = 0; 202 | } else if (y > MAX_Y_INPUT) { 203 | y = MAX_Y_INPUT; 204 | } 205 | if (z < 0) { 206 | z = 0; 207 | } else if (z > MAX_Z_INPUT) { 208 | z = MAX_Z_INPUT; 209 | } 210 | 211 | // Check if z coordinate should change mouse left button state 212 | if (z >= Z_MIN_OF_MOUSE_LEFT_BUTTON_DOWN && z <= Z_MAX_OF_MOUSE_LEFT_BUTTON_DOWN) { 213 | if (!cursorController.IsLeftButtonDown()) { 214 | //cursorController.LeftButtonDown(); 215 | } 216 | } else { 217 | if (cursorController.IsLeftButtonDown()) { 218 | //cursorController.LeftButtonUp(); 219 | } 220 | } 221 | 222 | // Update cursor coordinates 223 | cursorController.SetXY(y, x); 224 | } 225 | } 226 | } 227 | 228 | /// 229 | /// The main entry point for the application. 230 | /// 231 | public static void Main() { 232 | new Controller().Start(); 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /client/View/InitialForm.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Client3DCapacitiveSensor.View { 3 | partial class InitialForm { 4 | /// 5 | /// Required designer variable. 6 | /// 7 | private System.ComponentModel.IContainer components = null; 8 | 9 | /// 10 | /// Clean up any resources being used. 11 | /// 12 | /// true if managed resources should be disposed; otherwise, false. 13 | protected override void Dispose(bool disposing) { 14 | if (disposing && (components != null)) { 15 | components.Dispose(); 16 | } 17 | base.Dispose(disposing); 18 | } 19 | 20 | #region Windows Form Designer generated code 21 | 22 | /// 23 | /// Required method for Designer support - do not modify 24 | /// the contents of this method with the code editor. 25 | /// 26 | private void InitializeComponent() { 27 | this.comPortNumberTextBox = new System.Windows.Forms.TextBox(); 28 | this.titleLabel = new System.Windows.Forms.Label(); 29 | this.comPortNumberLabel = new System.Windows.Forms.Label(); 30 | this.startButton = new System.Windows.Forms.Button(); 31 | this.label1 = new System.Windows.Forms.Label(); 32 | this.baudRateTextBox = new System.Windows.Forms.TextBox(); 33 | this.buadRateLabel = new System.Windows.Forms.Label(); 34 | this.parityLabel = new System.Windows.Forms.Label(); 35 | this.dataBitsTextBox = new System.Windows.Forms.TextBox(); 36 | this.dataBitsLabel = new System.Windows.Forms.Label(); 37 | this.stopBitsLabel = new System.Windows.Forms.Label(); 38 | this.parityComboBox = new System.Windows.Forms.ComboBox(); 39 | this.stopBitsComboBox = new System.Windows.Forms.ComboBox(); 40 | this.SuspendLayout(); 41 | // 42 | // comPortNumberTextBox 43 | // 44 | this.comPortNumberTextBox.Location = new System.Drawing.Point(182, 117); 45 | this.comPortNumberTextBox.MaximumSize = new System.Drawing.Size(400, 4); 46 | this.comPortNumberTextBox.Name = "comPortNumberTextBox"; 47 | this.comPortNumberTextBox.Size = new System.Drawing.Size(150, 23); 48 | this.comPortNumberTextBox.TabIndex = 0; 49 | // 50 | // titleLabel 51 | // 52 | this.titleLabel.AutoSize = true; 53 | this.titleLabel.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 54 | this.titleLabel.Location = new System.Drawing.Point(87, 9); 55 | this.titleLabel.Name = "titleLabel"; 56 | this.titleLabel.Size = new System.Drawing.Size(225, 32); 57 | this.titleLabel.TabIndex = 1; 58 | this.titleLabel.Text = "3DCapacitiveSensor"; 59 | // 60 | // comPortNumberLabel 61 | // 62 | this.comPortNumberLabel.AutoSize = true; 63 | this.comPortNumberLabel.Location = new System.Drawing.Point(38, 120); 64 | this.comPortNumberLabel.Name = "comPortNumberLabel"; 65 | this.comPortNumberLabel.Size = new System.Drawing.Size(108, 15); 66 | this.comPortNumberLabel.TabIndex = 2; 67 | this.comPortNumberLabel.Text = "COM Port number:"; 68 | // 69 | // startButton 70 | // 71 | this.startButton.Location = new System.Drawing.Point(150, 279); 72 | this.startButton.Name = "startButton"; 73 | this.startButton.Size = new System.Drawing.Size(75, 24); 74 | this.startButton.TabIndex = 3; 75 | this.startButton.Text = "Start"; 76 | this.startButton.UseVisualStyleBackColor = true; 77 | this.startButton.Click += new System.EventHandler(this.OnStartButtonClick); 78 | // 79 | // label1 80 | // 81 | this.label1.AutoSize = true; 82 | this.label1.Location = new System.Drawing.Point(65, 58); 83 | this.label1.MaximumSize = new System.Drawing.Size(300, 0); 84 | this.label1.Name = "label1"; 85 | this.label1.Size = new System.Drawing.Size(257, 30); 86 | this.label1.TabIndex = 4; 87 | this.label1.Text = "Uses a large \"3D\" capacitor to measure the XYZ coordinates of a user\'s hand in ph" + 88 | "ysical space."; 89 | // 90 | // baudRateTextBox 91 | // 92 | this.baudRateTextBox.Location = new System.Drawing.Point(182, 146); 93 | this.baudRateTextBox.MaximumSize = new System.Drawing.Size(400, 4); 94 | this.baudRateTextBox.Name = "baudRateTextBox"; 95 | this.baudRateTextBox.Size = new System.Drawing.Size(150, 23); 96 | this.baudRateTextBox.TabIndex = 5; 97 | // 98 | // buadRateLabel 99 | // 100 | this.buadRateLabel.AutoSize = true; 101 | this.buadRateLabel.Location = new System.Drawing.Point(38, 149); 102 | this.buadRateLabel.Name = "buadRateLabel"; 103 | this.buadRateLabel.Size = new System.Drawing.Size(63, 15); 104 | this.buadRateLabel.TabIndex = 6; 105 | this.buadRateLabel.Text = "Baud Rate:"; 106 | // 107 | // parityLabel 108 | // 109 | this.parityLabel.AutoSize = true; 110 | this.parityLabel.Location = new System.Drawing.Point(38, 177); 111 | this.parityLabel.Name = "parityLabel"; 112 | this.parityLabel.Size = new System.Drawing.Size(40, 15); 113 | this.parityLabel.TabIndex = 7; 114 | this.parityLabel.Text = "Parity:"; 115 | // 116 | // dataBitsTextBox 117 | // 118 | this.dataBitsTextBox.Location = new System.Drawing.Point(182, 204); 119 | this.dataBitsTextBox.MaximumSize = new System.Drawing.Size(400, 4); 120 | this.dataBitsTextBox.Name = "dataBitsTextBox"; 121 | this.dataBitsTextBox.Size = new System.Drawing.Size(150, 23); 122 | this.dataBitsTextBox.TabIndex = 9; 123 | // 124 | // dataBitsLabel 125 | // 126 | this.dataBitsLabel.AutoSize = true; 127 | this.dataBitsLabel.Location = new System.Drawing.Point(38, 207); 128 | this.dataBitsLabel.Name = "dataBitsLabel"; 129 | this.dataBitsLabel.Size = new System.Drawing.Size(117, 15); 130 | this.dataBitsLabel.TabIndex = 13; 131 | this.dataBitsLabel.Text = "Number of Data Bits:"; 132 | // 133 | // stopBitsLabel 134 | // 135 | this.stopBitsLabel.AutoSize = true; 136 | this.stopBitsLabel.Location = new System.Drawing.Point(38, 236); 137 | this.stopBitsLabel.Name = "stopBitsLabel"; 138 | this.stopBitsLabel.Size = new System.Drawing.Size(51, 15); 139 | this.stopBitsLabel.TabIndex = 14; 140 | this.stopBitsLabel.Text = "Stop Bit:"; 141 | // 142 | // parityComboBox 143 | // 144 | this.parityComboBox.FormattingEnabled = true; 145 | this.parityComboBox.Items.AddRange(new object[] { 146 | "None", 147 | "Even"}); 148 | this.parityComboBox.Location = new System.Drawing.Point(182, 175); 149 | this.parityComboBox.Name = "parityComboBox"; 150 | this.parityComboBox.Size = new System.Drawing.Size(150, 23); 151 | this.parityComboBox.TabIndex = 15; 152 | this.parityComboBox.UseWaitCursor = true; 153 | // 154 | // stopBitsComboBox 155 | // 156 | this.stopBitsComboBox.FormattingEnabled = true; 157 | this.stopBitsComboBox.Items.AddRange(new object[] { 158 | "One", 159 | "Two", 160 | "None"}); 161 | this.stopBitsComboBox.Location = new System.Drawing.Point(182, 233); 162 | this.stopBitsComboBox.Name = "stopBitsComboBox"; 163 | this.stopBitsComboBox.Size = new System.Drawing.Size(150, 23); 164 | this.stopBitsComboBox.TabIndex = 16; 165 | // 166 | // InitialForm 167 | // 168 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); 169 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 170 | this.ClientSize = new System.Drawing.Size(384, 324); 171 | this.Controls.Add(this.stopBitsComboBox); 172 | this.Controls.Add(this.parityComboBox); 173 | this.Controls.Add(this.stopBitsLabel); 174 | this.Controls.Add(this.dataBitsLabel); 175 | this.Controls.Add(this.dataBitsTextBox); 176 | this.Controls.Add(this.parityLabel); 177 | this.Controls.Add(this.buadRateLabel); 178 | this.Controls.Add(this.baudRateTextBox); 179 | this.Controls.Add(this.label1); 180 | this.Controls.Add(this.startButton); 181 | this.Controls.Add(this.comPortNumberLabel); 182 | this.Controls.Add(this.titleLabel); 183 | this.Controls.Add(this.comPortNumberTextBox); 184 | this.Name = "InitialForm"; 185 | this.Text = "3DCapacitiveSensor"; 186 | this.ResumeLayout(false); 187 | this.PerformLayout(); 188 | 189 | } 190 | 191 | #endregion 192 | 193 | private System.Windows.Forms.TextBox comPortNumberTextBox; 194 | private System.Windows.Forms.Label titleLabel; 195 | private System.Windows.Forms.Label comPortNumberLabel; 196 | private System.Windows.Forms.Button startButton; 197 | private System.Windows.Forms.Label label1; 198 | private System.Windows.Forms.TextBox baudRateTextBox; 199 | private System.Windows.Forms.Label buadRateLabel; 200 | private System.Windows.Forms.Label parityLabel; 201 | private System.Windows.Forms.TextBox dataBitsTextBox; 202 | private System.Windows.Forms.Label dataBitsLabel; 203 | private System.Windows.Forms.Label stopBitsLabel; 204 | private System.Windows.Forms.ComboBox parityComboBox; 205 | private System.Windows.Forms.ComboBox stopBitsComboBox; 206 | } 207 | } 208 | 209 | -------------------------------------------------------------------------------- /mcu/MDK-ARM/startup_stm32f072xb.s: -------------------------------------------------------------------------------- 1 | ;******************************************************************************* 2 | ;* File Name : startup_stm32f072xb.s 3 | ;* Author : MCD Application Team 4 | ;* Description : STM32F072x8/STM32F072xB devices vector table for MDK-ARM toolchain. 5 | ;* This module performs: 6 | ;* - Set the initial SP 7 | ;* - Set the initial PC == Reset_Handler 8 | ;* - Set the vector table entries with the exceptions ISR address 9 | ;* - Branches to __main in the C library (which eventually 10 | ;* calls main()). 11 | ;* After Reset the CortexM0 processor is in Thread mode, 12 | ;* priority is Privileged, and the Stack is set to Main. 13 | ;******************************************************************************** 14 | ;* @attention 15 | ;* 16 | ;* Copyright (c) 2016 STMicroelectronics. 17 | ;* All rights reserved. 18 | ;* 19 | ;* This software component is licensed by ST under BSD 3-Clause license, 20 | ;* the "License"; You may not use this file except in compliance with the 21 | ;* License. You may obtain a copy of the License at: 22 | ;* opensource.org/licenses/BSD-3-Clause 23 | ;* 24 | ;******************************************************************************* 25 | ;* <<< Use Configuration Wizard in Context Menu >>> 26 | ; 27 | 28 | ; Amount of memory (in bytes) allocated for Stack 29 | ; Tailor this value to your application needs 30 | ; Stack Configuration 31 | ; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> 32 | ; 33 | 34 | Stack_Size EQU 0x400 35 | 36 | AREA STACK, NOINIT, READWRITE, ALIGN=3 37 | Stack_Mem SPACE Stack_Size 38 | __initial_sp 39 | 40 | 41 | ; Heap Configuration 42 | ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> 43 | ; 44 | 45 | Heap_Size EQU 0x200 46 | 47 | AREA HEAP, NOINIT, READWRITE, ALIGN=3 48 | __heap_base 49 | Heap_Mem SPACE Heap_Size 50 | __heap_limit 51 | 52 | PRESERVE8 53 | THUMB 54 | 55 | 56 | ; Vector Table Mapped to Address 0 at Reset 57 | AREA RESET, DATA, READONLY 58 | EXPORT __Vectors 59 | EXPORT __Vectors_End 60 | EXPORT __Vectors_Size 61 | 62 | __Vectors DCD __initial_sp ; Top of Stack 63 | DCD Reset_Handler ; Reset Handler 64 | DCD NMI_Handler ; NMI Handler 65 | DCD HardFault_Handler ; Hard Fault Handler 66 | DCD 0 ; Reserved 67 | DCD 0 ; Reserved 68 | DCD 0 ; Reserved 69 | DCD 0 ; Reserved 70 | DCD 0 ; Reserved 71 | DCD 0 ; Reserved 72 | DCD 0 ; Reserved 73 | DCD SVC_Handler ; SVCall Handler 74 | DCD 0 ; Reserved 75 | DCD 0 ; Reserved 76 | DCD PendSV_Handler ; PendSV Handler 77 | DCD SysTick_Handler ; SysTick Handler 78 | 79 | ; External Interrupts 80 | DCD WWDG_IRQHandler ; Window Watchdog 81 | DCD PVD_VDDIO2_IRQHandler ; PVD through EXTI Line detect 82 | DCD RTC_IRQHandler ; RTC through EXTI Line 83 | DCD FLASH_IRQHandler ; FLASH 84 | DCD RCC_CRS_IRQHandler ; RCC and CRS 85 | DCD EXTI0_1_IRQHandler ; EXTI Line 0 and 1 86 | DCD EXTI2_3_IRQHandler ; EXTI Line 2 and 3 87 | DCD EXTI4_15_IRQHandler ; EXTI Line 4 to 15 88 | DCD TSC_IRQHandler ; TS 89 | DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 90 | DCD DMA1_Channel2_3_IRQHandler ; DMA1 Channel 2 and Channel 3 91 | DCD DMA1_Channel4_5_6_7_IRQHandler ; DMA1 Channel 4, Channel 5, Channel 6 and Channel 7 92 | DCD ADC1_COMP_IRQHandler ; ADC1, COMP1 and COMP2 93 | DCD TIM1_BRK_UP_TRG_COM_IRQHandler ; TIM1 Break, Update, Trigger and Commutation 94 | DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare 95 | DCD TIM2_IRQHandler ; TIM2 96 | DCD TIM3_IRQHandler ; TIM3 97 | DCD TIM6_DAC_IRQHandler ; TIM6 and DAC 98 | DCD TIM7_IRQHandler ; TIM7 99 | DCD TIM14_IRQHandler ; TIM14 100 | DCD TIM15_IRQHandler ; TIM15 101 | DCD TIM16_IRQHandler ; TIM16 102 | DCD TIM17_IRQHandler ; TIM17 103 | DCD I2C1_IRQHandler ; I2C1 104 | DCD I2C2_IRQHandler ; I2C2 105 | DCD SPI1_IRQHandler ; SPI1 106 | DCD SPI2_IRQHandler ; SPI2 107 | DCD USART1_IRQHandler ; USART1 108 | DCD USART2_IRQHandler ; USART2 109 | DCD USART3_4_IRQHandler ; USART3 & USART4 110 | DCD CEC_CAN_IRQHandler ; CEC and CAN 111 | DCD USB_IRQHandler ; USB 112 | 113 | __Vectors_End 114 | 115 | __Vectors_Size EQU __Vectors_End - __Vectors 116 | 117 | AREA |.text|, CODE, READONLY 118 | 119 | ; Reset handler routine 120 | Reset_Handler PROC 121 | EXPORT Reset_Handler [WEAK] 122 | IMPORT __main 123 | IMPORT SystemInit 124 | LDR R0, =SystemInit 125 | BLX R0 126 | LDR R0, =__main 127 | BX R0 128 | ENDP 129 | 130 | ; Dummy Exception Handlers (infinite loops which can be modified) 131 | 132 | NMI_Handler PROC 133 | EXPORT NMI_Handler [WEAK] 134 | B . 135 | ENDP 136 | HardFault_Handler\ 137 | PROC 138 | EXPORT HardFault_Handler [WEAK] 139 | B . 140 | ENDP 141 | SVC_Handler PROC 142 | EXPORT SVC_Handler [WEAK] 143 | B . 144 | ENDP 145 | PendSV_Handler PROC 146 | EXPORT PendSV_Handler [WEAK] 147 | B . 148 | ENDP 149 | SysTick_Handler PROC 150 | EXPORT SysTick_Handler [WEAK] 151 | B . 152 | ENDP 153 | 154 | Default_Handler PROC 155 | 156 | EXPORT WWDG_IRQHandler [WEAK] 157 | EXPORT PVD_VDDIO2_IRQHandler [WEAK] 158 | EXPORT RTC_IRQHandler [WEAK] 159 | EXPORT FLASH_IRQHandler [WEAK] 160 | EXPORT RCC_CRS_IRQHandler [WEAK] 161 | EXPORT EXTI0_1_IRQHandler [WEAK] 162 | EXPORT EXTI2_3_IRQHandler [WEAK] 163 | EXPORT EXTI4_15_IRQHandler [WEAK] 164 | EXPORT TSC_IRQHandler [WEAK] 165 | EXPORT DMA1_Channel1_IRQHandler [WEAK] 166 | EXPORT DMA1_Channel2_3_IRQHandler [WEAK] 167 | EXPORT DMA1_Channel4_5_6_7_IRQHandler [WEAK] 168 | EXPORT ADC1_COMP_IRQHandler [WEAK] 169 | EXPORT TIM1_BRK_UP_TRG_COM_IRQHandler [WEAK] 170 | EXPORT TIM1_CC_IRQHandler [WEAK] 171 | EXPORT TIM2_IRQHandler [WEAK] 172 | EXPORT TIM3_IRQHandler [WEAK] 173 | EXPORT TIM6_DAC_IRQHandler [WEAK] 174 | EXPORT TIM7_IRQHandler [WEAK] 175 | EXPORT TIM14_IRQHandler [WEAK] 176 | EXPORT TIM15_IRQHandler [WEAK] 177 | EXPORT TIM16_IRQHandler [WEAK] 178 | EXPORT TIM17_IRQHandler [WEAK] 179 | EXPORT I2C1_IRQHandler [WEAK] 180 | EXPORT I2C2_IRQHandler [WEAK] 181 | EXPORT SPI1_IRQHandler [WEAK] 182 | EXPORT SPI2_IRQHandler [WEAK] 183 | EXPORT USART1_IRQHandler [WEAK] 184 | EXPORT USART2_IRQHandler [WEAK] 185 | EXPORT USART3_4_IRQHandler [WEAK] 186 | EXPORT CEC_CAN_IRQHandler [WEAK] 187 | EXPORT USB_IRQHandler [WEAK] 188 | 189 | 190 | WWDG_IRQHandler 191 | PVD_VDDIO2_IRQHandler 192 | RTC_IRQHandler 193 | FLASH_IRQHandler 194 | RCC_CRS_IRQHandler 195 | EXTI0_1_IRQHandler 196 | EXTI2_3_IRQHandler 197 | EXTI4_15_IRQHandler 198 | TSC_IRQHandler 199 | DMA1_Channel1_IRQHandler 200 | DMA1_Channel2_3_IRQHandler 201 | DMA1_Channel4_5_6_7_IRQHandler 202 | ADC1_COMP_IRQHandler 203 | TIM1_BRK_UP_TRG_COM_IRQHandler 204 | TIM1_CC_IRQHandler 205 | TIM2_IRQHandler 206 | TIM3_IRQHandler 207 | TIM6_DAC_IRQHandler 208 | TIM7_IRQHandler 209 | TIM14_IRQHandler 210 | TIM15_IRQHandler 211 | TIM16_IRQHandler 212 | TIM17_IRQHandler 213 | I2C1_IRQHandler 214 | I2C2_IRQHandler 215 | SPI1_IRQHandler 216 | SPI2_IRQHandler 217 | USART1_IRQHandler 218 | USART2_IRQHandler 219 | USART3_4_IRQHandler 220 | CEC_CAN_IRQHandler 221 | USB_IRQHandler 222 | 223 | B . 224 | 225 | ENDP 226 | 227 | ALIGN 228 | 229 | ;******************************************************************************* 230 | ; User Stack and Heap initialization 231 | ;******************************************************************************* 232 | IF :DEF:__MICROLIB 233 | 234 | EXPORT __initial_sp 235 | EXPORT __heap_base 236 | EXPORT __heap_limit 237 | 238 | ELSE 239 | 240 | IMPORT __use_two_region_memory 241 | EXPORT __user_initial_stackheap 242 | 243 | __user_initial_stackheap 244 | 245 | LDR R0, = Heap_Mem 246 | LDR R1, =(Stack_Mem + Stack_Size) 247 | LDR R2, = (Heap_Mem + Heap_Size) 248 | LDR R3, = Stack_Mem 249 | BX LR 250 | 251 | ALIGN 252 | 253 | ENDIF 254 | 255 | END 256 | 257 | ;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE***** 258 | -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_tim_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of TIM HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F0xx_HAL_TIM_EX_H 22 | #define STM32F0xx_HAL_TIM_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup TIMEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup TIMEx_Exported_Types TIM Extended Exported Types 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief TIM Hall sensor Configuration Structure definition 46 | */ 47 | 48 | typedef struct 49 | { 50 | uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal. 51 | This parameter can be a value of @ref TIM_Input_Capture_Polarity */ 52 | 53 | uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler. 54 | This parameter can be a value of @ref TIM_Input_Capture_Prescaler */ 55 | 56 | uint32_t IC1Filter; /*!< Specifies the input capture filter. 57 | This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */ 58 | 59 | uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. 60 | This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ 61 | } TIM_HallSensor_InitTypeDef; 62 | /** 63 | * @} 64 | */ 65 | /* End of exported types -----------------------------------------------------*/ 66 | 67 | /* Exported constants --------------------------------------------------------*/ 68 | /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants 69 | * @{ 70 | */ 71 | 72 | /** @defgroup TIMEx_Remap TIM Extended Remapping 73 | * @{ 74 | */ 75 | #define TIM_TIM14_GPIO (0x00000000U) /*!< TIM14 TI1 is connected to GPIO */ 76 | #define TIM_TIM14_RTC (0x00000001U) /*!< TIM14 TI1 is connected to RTC_clock */ 77 | #define TIM_TIM14_HSE (0x00000002U) /*!< TIM14 TI1 is connected to HSE/32U */ 78 | #define TIM_TIM14_MCO (0x00000003U) /*!< TIM14 TI1 is connected to MCO */ 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | /* End of exported constants -------------------------------------------------*/ 87 | 88 | /* Exported macro ------------------------------------------------------------*/ 89 | /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros 90 | * @{ 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | /* End of exported macro -----------------------------------------------------*/ 97 | 98 | /* Private macro -------------------------------------------------------------*/ 99 | /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros 100 | * @{ 101 | */ 102 | #define IS_TIM_REMAP(__INSTANCE__, __REMAP__) \ 103 | (((__INSTANCE__) == TIM14) && (((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U)) 104 | 105 | /** 106 | * @} 107 | */ 108 | /* End of private macro ------------------------------------------------------*/ 109 | 110 | /* Exported functions --------------------------------------------------------*/ 111 | /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions 112 | * @{ 113 | */ 114 | 115 | /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions 116 | * @brief Timer Hall Sensor functions 117 | * @{ 118 | */ 119 | /* Timer Hall Sensor functions **********************************************/ 120 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig); 121 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim); 122 | 123 | void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim); 124 | void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim); 125 | 126 | /* Blocking mode: Polling */ 127 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim); 128 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim); 129 | /* Non-Blocking mode: Interrupt */ 130 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim); 131 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim); 132 | /* Non-Blocking mode: DMA */ 133 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length); 134 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim); 135 | /** 136 | * @} 137 | */ 138 | 139 | /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions 140 | * @brief Timer Complementary Output Compare functions 141 | * @{ 142 | */ 143 | /* Timer Complementary Output Compare functions *****************************/ 144 | /* Blocking mode: Polling */ 145 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 146 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 147 | 148 | /* Non-Blocking mode: Interrupt */ 149 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 150 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 151 | 152 | /* Non-Blocking mode: DMA */ 153 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length); 154 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 155 | /** 156 | * @} 157 | */ 158 | 159 | /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions 160 | * @brief Timer Complementary PWM functions 161 | * @{ 162 | */ 163 | /* Timer Complementary PWM functions ****************************************/ 164 | /* Blocking mode: Polling */ 165 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 166 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 167 | 168 | /* Non-Blocking mode: Interrupt */ 169 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 170 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 171 | /* Non-Blocking mode: DMA */ 172 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length); 173 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 174 | /** 175 | * @} 176 | */ 177 | 178 | /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions 179 | * @brief Timer Complementary One Pulse functions 180 | * @{ 181 | */ 182 | /* Timer Complementary One Pulse functions **********************************/ 183 | /* Blocking mode: Polling */ 184 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 185 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 186 | 187 | /* Non-Blocking mode: Interrupt */ 188 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 189 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 190 | /** 191 | * @} 192 | */ 193 | 194 | /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions 195 | * @brief Peripheral Control functions 196 | * @{ 197 | */ 198 | /* Extended Control functions ************************************************/ 199 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 200 | uint32_t CommutationSource); 201 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 202 | uint32_t CommutationSource); 203 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 204 | uint32_t CommutationSource); 205 | HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, 206 | TIM_MasterConfigTypeDef *sMasterConfig); 207 | HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, 208 | TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig); 209 | HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap); 210 | /** 211 | * @} 212 | */ 213 | 214 | /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions 215 | * @brief Extended Callbacks functions 216 | * @{ 217 | */ 218 | /* Extended Callback **********************************************************/ 219 | void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim); 220 | void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim); 221 | void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim); 222 | /** 223 | * @} 224 | */ 225 | 226 | /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions 227 | * @brief Extended Peripheral State functions 228 | * @{ 229 | */ 230 | /* Extended Peripheral State functions ***************************************/ 231 | HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim); 232 | HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim, uint32_t ChannelN); 233 | /** 234 | * @} 235 | */ 236 | 237 | /** 238 | * @} 239 | */ 240 | /* End of exported functions -------------------------------------------------*/ 241 | 242 | /* Private functions----------------------------------------------------------*/ 243 | /** @addtogroup TIMEx_Private_Functions TIMEx Private Functions 244 | * @{ 245 | */ 246 | void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma); 247 | void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma); 248 | /** 249 | * @} 250 | */ 251 | /* End of private functions --------------------------------------------------*/ 252 | 253 | /** 254 | * @} 255 | */ 256 | 257 | /** 258 | * @} 259 | */ 260 | 261 | #ifdef __cplusplus 262 | } 263 | #endif 264 | 265 | 266 | #endif /* STM32F0xx_HAL_TIM_EX_H */ 267 | 268 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 269 | -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_i2c_ex.c 4 | * @author MCD Application Team 5 | * @brief I2C Extended HAL module driver. 6 | * This file provides firmware functions to manage the following 7 | * functionalities of I2C Extended peripheral: 8 | * + Extended features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### I2C peripheral Extended features ##### 13 | ============================================================================== 14 | 15 | [..] Comparing to other previous devices, the I2C interface for STM32F0xx 16 | 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 | (+) Disable or enable wakeup from Stop mode(s) 21 | (+) Disable or enable Fast Mode Plus 22 | 23 | ##### How to use this driver ##### 24 | ============================================================================== 25 | [..] This driver provides functions to configure Noise Filter and Wake Up Feature 26 | (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter() 27 | (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter() 28 | (#) Configure the enable or disable of I2C Wake Up Mode using the functions : 29 | (++) HAL_I2CEx_EnableWakeUp() 30 | (++) HAL_I2CEx_DisableWakeUp() 31 | (#) Configure the enable or disable of fast mode plus driving capability using the functions : 32 | (++) HAL_I2CEx_EnableFastModePlus() 33 | (++) HAL_I2CEx_DisableFastModePlus() 34 | @endverbatim 35 | ****************************************************************************** 36 | * @attention 37 | * 38 | *

© Copyright (c) 2016 STMicroelectronics. 39 | * All rights reserved.

40 | * 41 | * This software component is licensed by ST under BSD 3-Clause license, 42 | * the "License"; You may not use this file except in compliance with the 43 | * License. You may obtain a copy of the License at: 44 | * opensource.org/licenses/BSD-3-Clause 45 | * 46 | ****************************************************************************** 47 | */ 48 | 49 | /* Includes ------------------------------------------------------------------*/ 50 | #include "stm32f0xx_hal.h" 51 | 52 | /** @addtogroup STM32F0xx_HAL_Driver 53 | * @{ 54 | */ 55 | 56 | /** @defgroup I2CEx I2CEx 57 | * @brief I2C Extended HAL module driver 58 | * @{ 59 | */ 60 | 61 | #ifdef HAL_I2C_MODULE_ENABLED 62 | 63 | /* Private typedef -----------------------------------------------------------*/ 64 | /* Private define ------------------------------------------------------------*/ 65 | /* Private macro -------------------------------------------------------------*/ 66 | /* Private variables ---------------------------------------------------------*/ 67 | /* Private function prototypes -----------------------------------------------*/ 68 | /* Private functions ---------------------------------------------------------*/ 69 | 70 | /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions 71 | * @{ 72 | */ 73 | 74 | /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions 75 | * @brief Extended features functions 76 | * 77 | @verbatim 78 | =============================================================================== 79 | ##### Extended features functions ##### 80 | =============================================================================== 81 | [..] This section provides functions allowing to: 82 | (+) Configure Noise Filters 83 | (+) Configure Wake Up Feature 84 | (+) Configure Fast Mode Plus 85 | 86 | @endverbatim 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @brief Configure I2C Analog noise filter. 92 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 93 | * the configuration information for the specified I2Cx peripheral. 94 | * @param AnalogFilter New state of the Analog filter. 95 | * @retval HAL status 96 | */ 97 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) 98 | { 99 | /* Check the parameters */ 100 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 101 | assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); 102 | 103 | if (hi2c->State == HAL_I2C_STATE_READY) 104 | { 105 | /* Process Locked */ 106 | __HAL_LOCK(hi2c); 107 | 108 | hi2c->State = HAL_I2C_STATE_BUSY; 109 | 110 | /* Disable the selected I2C peripheral */ 111 | __HAL_I2C_DISABLE(hi2c); 112 | 113 | /* Reset I2Cx ANOFF bit */ 114 | hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF); 115 | 116 | /* Set analog filter bit*/ 117 | hi2c->Instance->CR1 |= AnalogFilter; 118 | 119 | __HAL_I2C_ENABLE(hi2c); 120 | 121 | hi2c->State = HAL_I2C_STATE_READY; 122 | 123 | /* Process Unlocked */ 124 | __HAL_UNLOCK(hi2c); 125 | 126 | return HAL_OK; 127 | } 128 | else 129 | { 130 | return HAL_BUSY; 131 | } 132 | } 133 | 134 | /** 135 | * @brief Configure I2C Digital noise filter. 136 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 137 | * the configuration information for the specified I2Cx peripheral. 138 | * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F. 139 | * @retval HAL status 140 | */ 141 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 142 | { 143 | uint32_t tmpreg; 144 | 145 | /* Check the parameters */ 146 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 147 | assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); 148 | 149 | if (hi2c->State == HAL_I2C_STATE_READY) 150 | { 151 | /* Process Locked */ 152 | __HAL_LOCK(hi2c); 153 | 154 | hi2c->State = HAL_I2C_STATE_BUSY; 155 | 156 | /* Disable the selected I2C peripheral */ 157 | __HAL_I2C_DISABLE(hi2c); 158 | 159 | /* Get the old register value */ 160 | tmpreg = hi2c->Instance->CR1; 161 | 162 | /* Reset I2Cx DNF bits [11:8] */ 163 | tmpreg &= ~(I2C_CR1_DNF); 164 | 165 | /* Set I2Cx DNF coefficient */ 166 | tmpreg |= DigitalFilter << 8U; 167 | 168 | /* Store the new register value */ 169 | hi2c->Instance->CR1 = tmpreg; 170 | 171 | __HAL_I2C_ENABLE(hi2c); 172 | 173 | hi2c->State = HAL_I2C_STATE_READY; 174 | 175 | /* Process Unlocked */ 176 | __HAL_UNLOCK(hi2c); 177 | 178 | return HAL_OK; 179 | } 180 | else 181 | { 182 | return HAL_BUSY; 183 | } 184 | } 185 | #if defined(I2C_CR1_WUPEN) 186 | 187 | /** 188 | * @brief Enable I2C wakeup from Stop mode(s). 189 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 190 | * the configuration information for the specified I2Cx peripheral. 191 | * @retval HAL status 192 | */ 193 | HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c) 194 | { 195 | /* Check the parameters */ 196 | assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); 197 | 198 | if (hi2c->State == HAL_I2C_STATE_READY) 199 | { 200 | /* Process Locked */ 201 | __HAL_LOCK(hi2c); 202 | 203 | hi2c->State = HAL_I2C_STATE_BUSY; 204 | 205 | /* Disable the selected I2C peripheral */ 206 | __HAL_I2C_DISABLE(hi2c); 207 | 208 | /* Enable wakeup from stop mode */ 209 | hi2c->Instance->CR1 |= I2C_CR1_WUPEN; 210 | 211 | __HAL_I2C_ENABLE(hi2c); 212 | 213 | hi2c->State = HAL_I2C_STATE_READY; 214 | 215 | /* Process Unlocked */ 216 | __HAL_UNLOCK(hi2c); 217 | 218 | return HAL_OK; 219 | } 220 | else 221 | { 222 | return HAL_BUSY; 223 | } 224 | } 225 | 226 | /** 227 | * @brief Disable I2C wakeup from Stop mode(s). 228 | * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 229 | * the configuration information for the specified I2Cx peripheral. 230 | * @retval HAL status 231 | */ 232 | HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c) 233 | { 234 | /* Check the parameters */ 235 | assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); 236 | 237 | if (hi2c->State == HAL_I2C_STATE_READY) 238 | { 239 | /* Process Locked */ 240 | __HAL_LOCK(hi2c); 241 | 242 | hi2c->State = HAL_I2C_STATE_BUSY; 243 | 244 | /* Disable the selected I2C peripheral */ 245 | __HAL_I2C_DISABLE(hi2c); 246 | 247 | /* Enable wakeup from stop mode */ 248 | hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN); 249 | 250 | __HAL_I2C_ENABLE(hi2c); 251 | 252 | hi2c->State = HAL_I2C_STATE_READY; 253 | 254 | /* Process Unlocked */ 255 | __HAL_UNLOCK(hi2c); 256 | 257 | return HAL_OK; 258 | } 259 | else 260 | { 261 | return HAL_BUSY; 262 | } 263 | } 264 | #endif 265 | 266 | /** 267 | * @brief Enable the I2C fast mode plus driving capability. 268 | * @param ConfigFastModePlus Selects the pin. 269 | * This parameter can be one of the @ref I2CEx_FastModePlus values 270 | * @note For I2C1, fast mode plus driving capability can be enabled on all selected 271 | * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 272 | * on each one of the following pins PB6, PB7, PB8 and PB9. 273 | * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 274 | * can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 275 | * @note For all I2C2 pins fast mode plus driving capability can be enabled 276 | * only by using I2C_FASTMODEPLUS_I2C2 parameter. 277 | * @retval None 278 | */ 279 | void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus) 280 | { 281 | /* Check the parameter */ 282 | assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 283 | 284 | /* Enable SYSCFG clock */ 285 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 286 | 287 | /* Enable fast mode plus driving capability for selected pin */ 288 | SET_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); 289 | } 290 | 291 | /** 292 | * @brief Disable the I2C fast mode plus driving capability. 293 | * @param ConfigFastModePlus Selects the pin. 294 | * This parameter can be one of the @ref I2CEx_FastModePlus values 295 | * @note For I2C1, fast mode plus driving capability can be disabled on all selected 296 | * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 297 | * on each one of the following pins PB6, PB7, PB8 and PB9. 298 | * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 299 | * can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 300 | * @note For all I2C2 pins fast mode plus driving capability can be disabled 301 | * only by using I2C_FASTMODEPLUS_I2C2 parameter. 302 | * @retval None 303 | */ 304 | void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus) 305 | { 306 | /* Check the parameter */ 307 | assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 308 | 309 | /* Enable SYSCFG clock */ 310 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 311 | 312 | /* Disable fast mode plus driving capability for selected pin */ 313 | CLEAR_BIT(SYSCFG->CFGR1, (uint32_t)ConfigFastModePlus); 314 | } 315 | 316 | /** 317 | * @} 318 | */ 319 | 320 | /** 321 | * @} 322 | */ 323 | 324 | #endif /* HAL_I2C_MODULE_ENABLED */ 325 | /** 326 | * @} 327 | */ 328 | 329 | /** 330 | * @} 331 | */ 332 | 333 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 334 | -------------------------------------------------------------------------------- /mcu/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_flash.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_flash.h 4 | * @author MCD Application Team 5 | * @brief Header file of Flash HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F0xx_HAL_FLASH_H 22 | #define __STM32F0xx_HAL_FLASH_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup FLASH 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup FLASH_Private_Constants 40 | * @{ 41 | */ 42 | #define FLASH_TIMEOUT_VALUE (50000U) /* 50 s */ 43 | /** 44 | * @} 45 | */ 46 | 47 | /** @addtogroup FLASH_Private_Macros 48 | * @{ 49 | */ 50 | 51 | #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \ 52 | ((VALUE) == FLASH_TYPEPROGRAM_WORD) || \ 53 | ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD)) 54 | 55 | #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \ 56 | ((__LATENCY__) == FLASH_LATENCY_1)) 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /* Exported types ------------------------------------------------------------*/ 63 | /** @defgroup FLASH_Exported_Types FLASH Exported Types 64 | * @{ 65 | */ 66 | 67 | /** 68 | * @brief FLASH Procedure structure definition 69 | */ 70 | typedef enum 71 | { 72 | FLASH_PROC_NONE = 0U, 73 | FLASH_PROC_PAGEERASE = 1U, 74 | FLASH_PROC_MASSERASE = 2U, 75 | FLASH_PROC_PROGRAMHALFWORD = 3U, 76 | FLASH_PROC_PROGRAMWORD = 4U, 77 | FLASH_PROC_PROGRAMDOUBLEWORD = 5U 78 | } FLASH_ProcedureTypeDef; 79 | 80 | /** 81 | * @brief FLASH handle Structure definition 82 | */ 83 | typedef struct 84 | { 85 | __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */ 86 | 87 | __IO uint32_t DataRemaining; /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */ 88 | 89 | __IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */ 90 | 91 | __IO uint64_t Data; /*!< Internal variable to save data to be programmed */ 92 | 93 | HAL_LockTypeDef Lock; /*!< FLASH locking object */ 94 | 95 | __IO uint32_t ErrorCode; /*!< FLASH error code 96 | This parameter can be a value of @ref FLASH_Error_Codes */ 97 | } FLASH_ProcessTypeDef; 98 | 99 | /** 100 | * @} 101 | */ 102 | 103 | /* Exported constants --------------------------------------------------------*/ 104 | /** @defgroup FLASH_Exported_Constants FLASH Exported Constants 105 | * @{ 106 | */ 107 | 108 | /** @defgroup FLASH_Error_Codes FLASH Error Codes 109 | * @{ 110 | */ 111 | 112 | #define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */ 113 | #define HAL_FLASH_ERROR_PROG 0x01U /*!< Programming error */ 114 | #define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** @defgroup FLASH_Type_Program FLASH Type Program 121 | * @{ 122 | */ 123 | #define FLASH_TYPEPROGRAM_HALFWORD (0x01U) /*!ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__)) 186 | 187 | 188 | /** 189 | * @brief Get the FLASH Latency. 190 | * @retval FLASH Latency 191 | * The value of this parameter depend on device used within the same series 192 | */ 193 | #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)) 194 | 195 | /** 196 | * @} 197 | */ 198 | 199 | /** @defgroup FLASH_Prefetch FLASH Prefetch 200 | * @brief macros to handle FLASH Prefetch buffer 201 | * @{ 202 | */ 203 | /** 204 | * @brief Enable the FLASH prefetch buffer. 205 | * @retval None 206 | */ 207 | #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() (FLASH->ACR |= FLASH_ACR_PRFTBE) 208 | 209 | /** 210 | * @brief Disable the FLASH prefetch buffer. 211 | * @retval None 212 | */ 213 | #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() (FLASH->ACR &= (~FLASH_ACR_PRFTBE)) 214 | 215 | /** 216 | * @} 217 | */ 218 | 219 | /** @defgroup FLASH_Interrupt FLASH Interrupts 220 | * @brief macros to handle FLASH interrupts 221 | * @{ 222 | */ 223 | 224 | /** 225 | * @brief Enable the specified FLASH interrupt. 226 | * @param __INTERRUPT__ FLASH interrupt 227 | * This parameter can be any combination of the following values: 228 | * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 229 | * @arg @ref FLASH_IT_ERR Error Interrupt 230 | * @retval none 231 | */ 232 | #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->CR), (__INTERRUPT__)) 233 | 234 | /** 235 | * @brief Disable the specified FLASH interrupt. 236 | * @param __INTERRUPT__ FLASH interrupt 237 | * This parameter can be any combination of the following values: 238 | * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 239 | * @arg @ref FLASH_IT_ERR Error Interrupt 240 | * @retval none 241 | */ 242 | #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->CR), (uint32_t)(__INTERRUPT__)) 243 | 244 | /** 245 | * @brief Get the specified FLASH flag status. 246 | * @param __FLAG__ specifies the FLASH flag to check. 247 | * This parameter can be one of the following values: 248 | * @arg @ref FLASH_FLAG_BSY FLASH Busy flag 249 | * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 250 | * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 251 | * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag 252 | * @retval The new state of __FLAG__ (SET or RESET). 253 | */ 254 | #define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__)) 255 | 256 | /** 257 | * @brief Clear the specified FLASH flag. 258 | * @param __FLAG__ specifies the FLASH flags to clear. 259 | * This parameter can be any combination of the following values: 260 | * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 261 | * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 262 | * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag 263 | * @retval none 264 | */ 265 | #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__)) 266 | 267 | /** 268 | * @} 269 | */ 270 | 271 | /** 272 | * @} 273 | */ 274 | 275 | /* Include FLASH HAL Extended module */ 276 | #include "stm32f0xx_hal_flash_ex.h" 277 | 278 | /* Exported functions --------------------------------------------------------*/ 279 | /** @addtogroup FLASH_Exported_Functions 280 | * @{ 281 | */ 282 | 283 | /** @addtogroup FLASH_Exported_Functions_Group1 284 | * @{ 285 | */ 286 | /* IO operation functions *****************************************************/ 287 | HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 288 | HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data); 289 | 290 | /* FLASH IRQ handler function */ 291 | void HAL_FLASH_IRQHandler(void); 292 | /* Callbacks in non blocking modes */ 293 | void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); 294 | void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); 295 | 296 | /** 297 | * @} 298 | */ 299 | 300 | /** @addtogroup FLASH_Exported_Functions_Group2 301 | * @{ 302 | */ 303 | /* Peripheral Control functions ***********************************************/ 304 | HAL_StatusTypeDef HAL_FLASH_Unlock(void); 305 | HAL_StatusTypeDef HAL_FLASH_Lock(void); 306 | HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); 307 | HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); 308 | HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); 309 | 310 | /** 311 | * @} 312 | */ 313 | 314 | /** @addtogroup FLASH_Exported_Functions_Group3 315 | * @{ 316 | */ 317 | /* Peripheral State and Error functions ***************************************/ 318 | uint32_t HAL_FLASH_GetError(void); 319 | 320 | /** 321 | * @} 322 | */ 323 | 324 | /** 325 | * @} 326 | */ 327 | 328 | /* Private function -------------------------------------------------*/ 329 | /** @addtogroup FLASH_Private_Functions 330 | * @{ 331 | */ 332 | HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); 333 | 334 | /** 335 | * @} 336 | */ 337 | 338 | /** 339 | * @} 340 | */ 341 | 342 | /** 343 | * @} 344 | */ 345 | 346 | #ifdef __cplusplus 347 | } 348 | #endif 349 | 350 | #endif /* __STM32F0xx_HAL_FLASH_H */ 351 | 352 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 353 | 354 | -------------------------------------------------------------------------------- /mcu/Drivers/CMSIS/Include/mpu_armv8.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file mpu_armv8.h 3 | * @brief CMSIS MPU API for Armv8-M MPU 4 | * @version V5.0.4 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef ARM_MPU_ARMV8_H 32 | #define ARM_MPU_ARMV8_H 33 | 34 | /** \brief Attribute for device memory (outer only) */ 35 | #define ARM_MPU_ATTR_DEVICE ( 0U ) 36 | 37 | /** \brief Attribute for non-cacheable, normal memory */ 38 | #define ARM_MPU_ATTR_NON_CACHEABLE ( 4U ) 39 | 40 | /** \brief Attribute for normal memory (outer and inner) 41 | * \param NT Non-Transient: Set to 1 for non-transient data. 42 | * \param WB Write-Back: Set to 1 to use write-back update policy. 43 | * \param RA Read Allocation: Set to 1 to use cache allocation on read miss. 44 | * \param WA Write Allocation: Set to 1 to use cache allocation on write miss. 45 | */ 46 | #define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \ 47 | (((NT & 1U) << 3U) | ((WB & 1U) << 2U) | ((RA & 1U) << 1U) | (WA & 1U)) 48 | 49 | /** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */ 50 | #define ARM_MPU_ATTR_DEVICE_nGnRnE (0U) 51 | 52 | /** \brief Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement */ 53 | #define ARM_MPU_ATTR_DEVICE_nGnRE (1U) 54 | 55 | /** \brief Device memory type non Gathering, Re-ordering, Early Write Acknowledgement */ 56 | #define ARM_MPU_ATTR_DEVICE_nGRE (2U) 57 | 58 | /** \brief Device memory type Gathering, Re-ordering, Early Write Acknowledgement */ 59 | #define ARM_MPU_ATTR_DEVICE_GRE (3U) 60 | 61 | /** \brief Memory Attribute 62 | * \param O Outer memory attributes 63 | * \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes 64 | */ 65 | #define ARM_MPU_ATTR(O, I) (((O & 0xFU) << 4U) | (((O & 0xFU) != 0U) ? (I & 0xFU) : ((I & 0x3U) << 2U))) 66 | 67 | /** \brief Normal memory non-shareable */ 68 | #define ARM_MPU_SH_NON (0U) 69 | 70 | /** \brief Normal memory outer shareable */ 71 | #define ARM_MPU_SH_OUTER (2U) 72 | 73 | /** \brief Normal memory inner shareable */ 74 | #define ARM_MPU_SH_INNER (3U) 75 | 76 | /** \brief Memory access permissions 77 | * \param RO Read-Only: Set to 1 for read-only memory. 78 | * \param NP Non-Privileged: Set to 1 for non-privileged memory. 79 | */ 80 | #define ARM_MPU_AP_(RO, NP) (((RO & 1U) << 1U) | (NP & 1U)) 81 | 82 | /** \brief Region Base Address Register value 83 | * \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned. 84 | * \param SH Defines the Shareability domain for this memory region. 85 | * \param RO Read-Only: Set to 1 for a read-only memory region. 86 | * \param NP Non-Privileged: Set to 1 for a non-privileged memory region. 87 | * \oaram XN eXecute Never: Set to 1 for a non-executable memory region. 88 | */ 89 | #define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \ 90 | ((BASE & MPU_RBAR_BASE_Msk) | \ 91 | ((SH << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \ 92 | ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \ 93 | ((XN << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk)) 94 | 95 | /** \brief Region Limit Address Register value 96 | * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended. 97 | * \param IDX The attribute index to be associated with this memory region. 98 | */ 99 | #define ARM_MPU_RLAR(LIMIT, IDX) \ 100 | ((LIMIT & MPU_RLAR_LIMIT_Msk) | \ 101 | ((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ 102 | (MPU_RLAR_EN_Msk)) 103 | 104 | /** 105 | * Struct for a single MPU Region 106 | */ 107 | typedef struct { 108 | uint32_t RBAR; /*!< Region Base Address Register value */ 109 | uint32_t RLAR; /*!< Region Limit Address Register value */ 110 | } ARM_MPU_Region_t; 111 | 112 | /** Enable the MPU. 113 | * \param MPU_Control Default access permissions for unconfigured regions. 114 | */ 115 | __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) 116 | { 117 | __DSB(); 118 | __ISB(); 119 | MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; 120 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk 121 | SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; 122 | #endif 123 | } 124 | 125 | /** Disable the MPU. 126 | */ 127 | __STATIC_INLINE void ARM_MPU_Disable(void) 128 | { 129 | __DSB(); 130 | __ISB(); 131 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk 132 | SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; 133 | #endif 134 | MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; 135 | } 136 | 137 | #ifdef MPU_NS 138 | /** Enable the Non-secure MPU. 139 | * \param MPU_Control Default access permissions for unconfigured regions. 140 | */ 141 | __STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control) 142 | { 143 | __DSB(); 144 | __ISB(); 145 | MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; 146 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk 147 | SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; 148 | #endif 149 | } 150 | 151 | /** Disable the Non-secure MPU. 152 | */ 153 | __STATIC_INLINE void ARM_MPU_Disable_NS(void) 154 | { 155 | __DSB(); 156 | __ISB(); 157 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk 158 | SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; 159 | #endif 160 | MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk; 161 | } 162 | #endif 163 | 164 | /** Set the memory attribute encoding to the given MPU. 165 | * \param mpu Pointer to the MPU to be configured. 166 | * \param idx The attribute index to be set [0-7] 167 | * \param attr The attribute value to be set. 168 | */ 169 | __STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr) 170 | { 171 | const uint8_t reg = idx / 4U; 172 | const uint32_t pos = ((idx % 4U) * 8U); 173 | const uint32_t mask = 0xFFU << pos; 174 | 175 | if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) { 176 | return; // invalid index 177 | } 178 | 179 | mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask)); 180 | } 181 | 182 | /** Set the memory attribute encoding. 183 | * \param idx The attribute index to be set [0-7] 184 | * \param attr The attribute value to be set. 185 | */ 186 | __STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr) 187 | { 188 | ARM_MPU_SetMemAttrEx(MPU, idx, attr); 189 | } 190 | 191 | #ifdef MPU_NS 192 | /** Set the memory attribute encoding to the Non-secure MPU. 193 | * \param idx The attribute index to be set [0-7] 194 | * \param attr The attribute value to be set. 195 | */ 196 | __STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr) 197 | { 198 | ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr); 199 | } 200 | #endif 201 | 202 | /** Clear and disable the given MPU region of the given MPU. 203 | * \param mpu Pointer to MPU to be used. 204 | * \param rnr Region number to be cleared. 205 | */ 206 | __STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr) 207 | { 208 | mpu->RNR = rnr; 209 | mpu->RLAR = 0U; 210 | } 211 | 212 | /** Clear and disable the given MPU region. 213 | * \param rnr Region number to be cleared. 214 | */ 215 | __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) 216 | { 217 | ARM_MPU_ClrRegionEx(MPU, rnr); 218 | } 219 | 220 | #ifdef MPU_NS 221 | /** Clear and disable the given Non-secure MPU region. 222 | * \param rnr Region number to be cleared. 223 | */ 224 | __STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr) 225 | { 226 | ARM_MPU_ClrRegionEx(MPU_NS, rnr); 227 | } 228 | #endif 229 | 230 | /** Configure the given MPU region of the given MPU. 231 | * \param mpu Pointer to MPU to be used. 232 | * \param rnr Region number to be configured. 233 | * \param rbar Value for RBAR register. 234 | * \param rlar Value for RLAR register. 235 | */ 236 | __STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar) 237 | { 238 | mpu->RNR = rnr; 239 | mpu->RBAR = rbar; 240 | mpu->RLAR = rlar; 241 | } 242 | 243 | /** Configure the given MPU region. 244 | * \param rnr Region number to be configured. 245 | * \param rbar Value for RBAR register. 246 | * \param rlar Value for RLAR register. 247 | */ 248 | __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar) 249 | { 250 | ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar); 251 | } 252 | 253 | #ifdef MPU_NS 254 | /** Configure the given Non-secure MPU region. 255 | * \param rnr Region number to be configured. 256 | * \param rbar Value for RBAR register. 257 | * \param rlar Value for RLAR register. 258 | */ 259 | __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar) 260 | { 261 | ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar); 262 | } 263 | #endif 264 | 265 | /** Memcopy with strictly ordered memory access, e.g. for register targets. 266 | * \param dst Destination data is copied to. 267 | * \param src Source data is copied from. 268 | * \param len Amount of data words to be copied. 269 | */ 270 | __STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) 271 | { 272 | uint32_t i; 273 | for (i = 0U; i < len; ++i) 274 | { 275 | dst[i] = src[i]; 276 | } 277 | } 278 | 279 | /** Load the given number of MPU regions from a table to the given MPU. 280 | * \param mpu Pointer to the MPU registers to be used. 281 | * \param rnr First region number to be configured. 282 | * \param table Pointer to the MPU configuration table. 283 | * \param cnt Amount of regions to be configured. 284 | */ 285 | __STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) 286 | { 287 | const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; 288 | if (cnt == 1U) { 289 | mpu->RNR = rnr; 290 | orderedCpy(&(mpu->RBAR), &(table->RBAR), rowWordSize); 291 | } else { 292 | uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U); 293 | uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES; 294 | 295 | mpu->RNR = rnrBase; 296 | while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) { 297 | uint32_t c = MPU_TYPE_RALIASES - rnrOffset; 298 | orderedCpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize); 299 | table += c; 300 | cnt -= c; 301 | rnrOffset = 0U; 302 | rnrBase += MPU_TYPE_RALIASES; 303 | mpu->RNR = rnrBase; 304 | } 305 | 306 | orderedCpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize); 307 | } 308 | } 309 | 310 | /** Load the given number of MPU regions from a table. 311 | * \param rnr First region number to be configured. 312 | * \param table Pointer to the MPU configuration table. 313 | * \param cnt Amount of regions to be configured. 314 | */ 315 | __STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) 316 | { 317 | ARM_MPU_LoadEx(MPU, rnr, table, cnt); 318 | } 319 | 320 | #ifdef MPU_NS 321 | /** Load the given number of MPU regions from a table to the Non-secure MPU. 322 | * \param rnr First region number to be configured. 323 | * \param table Pointer to the MPU configuration table. 324 | * \param cnt Amount of regions to be configured. 325 | */ 326 | __STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) 327 | { 328 | ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt); 329 | } 330 | #endif 331 | 332 | #endif 333 | 334 | --------------------------------------------------------------------------------