├── .gitignore ├── LICENSE.txt ├── Libraries ├── CMSIS │ ├── Include │ │ ├── arm_common_tables.h │ │ ├── arm_math.h │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm3.h │ │ ├── core_cm4.h │ │ ├── core_cm4_simd.h │ │ ├── core_cmFunc.h │ │ ├── core_cmInstr.h │ │ ├── core_sc000.h │ │ └── core_sc300.h │ └── README.txt ├── STM32F10x_StdPeriph_Driver │ ├── Release_Notes.html │ ├── inc │ │ ├── misc.h │ │ ├── stm32f10x_adc.h │ │ ├── stm32f10x_bkp.h │ │ ├── stm32f10x_can.h │ │ ├── stm32f10x_cec.h │ │ ├── stm32f10x_crc.h │ │ ├── stm32f10x_dac.h │ │ ├── stm32f10x_dbgmcu.h │ │ ├── stm32f10x_dma.h │ │ ├── stm32f10x_exti.h │ │ ├── stm32f10x_flash.h │ │ ├── stm32f10x_fsmc.h │ │ ├── stm32f10x_gpio.h │ │ ├── stm32f10x_i2c.h │ │ ├── stm32f10x_iwdg.h │ │ ├── stm32f10x_pwr.h │ │ ├── stm32f10x_rcc.h │ │ ├── stm32f10x_rtc.h │ │ ├── stm32f10x_sdio.h │ │ ├── stm32f10x_spi.h │ │ ├── stm32f10x_tim.h │ │ ├── stm32f10x_usart.h │ │ └── stm32f10x_wwdg.h │ └── src │ │ ├── misc.c │ │ ├── stm32f10x_adc.c │ │ ├── stm32f10x_bkp.c │ │ ├── stm32f10x_can.c │ │ ├── stm32f10x_cec.c │ │ ├── stm32f10x_crc.c │ │ ├── stm32f10x_dac.c │ │ ├── stm32f10x_dbgmcu.c │ │ ├── stm32f10x_dma.c │ │ ├── stm32f10x_exti.c │ │ ├── stm32f10x_flash.c │ │ ├── stm32f10x_fsmc.c │ │ ├── stm32f10x_gpio.c │ │ ├── stm32f10x_i2c.c │ │ ├── stm32f10x_iwdg.c │ │ ├── stm32f10x_pwr.c │ │ ├── stm32f10x_rcc.c │ │ ├── stm32f10x_rtc.c │ │ ├── stm32f10x_sdio.c │ │ ├── stm32f10x_spi.c │ │ ├── stm32f10x_tim.c │ │ ├── stm32f10x_usart.c │ │ └── stm32f10x_wwdg.c └── STM32_USB-FS-Device_Driver │ ├── Release_Notes.html │ ├── inc │ ├── usb_core.h │ ├── usb_def.h │ ├── usb_init.h │ ├── usb_int.h │ ├── usb_lib.h │ ├── usb_mem.h │ ├── usb_regs.h │ ├── usb_sil.h │ └── usb_type.h │ └── src │ ├── usb_core.c │ ├── usb_init.c │ ├── usb_int.c │ ├── usb_mem.c │ ├── usb_regs.c │ └── usb_sil.c ├── README.md ├── System ├── startup_stm32f10x_md.s ├── stm32f10x.h ├── stm32f10x_conf.h ├── system_stm32f10x.c └── system_stm32f10x.h ├── USB_Device ├── usb_conf.h ├── usb_desc.c ├── usb_desc.h ├── usb_endp.c ├── usb_istr.c ├── usb_istr.h ├── usb_prop.c ├── usb_prop.h ├── usb_pwr.c └── usb_pwr.h ├── hw_config.c ├── hw_config.h ├── main.c ├── platform_config.h ├── retarget.c ├── stm32-ch340.uvoptx ├── stm32-ch340.uvprojx ├── stm32_it.c └── stm32_it.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | 35 | /DebugConfig 36 | /Listings 37 | /Objects 38 | /*.uvguix* 39 | /EventRecorder* 40 | 41 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Dmitry Lavygin (vdm.inbox@gmail.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | ------------------------------------------------------------------------------ 24 | 25 | This project contains following third-party open source software: 26 | 27 | 1) The Cortex Microcontroller Software Interface Standard (CMSIS) 28 | URL: https://github.com/ARM-software/CMSIS 29 | License: Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0) 30 | 31 | 2) STM32F10x Standard Peripherals Library Drivers 32 | URL: http://www.st.com/en/embedded-software/stsw-stm32054.html 33 | License: MCD-ST Liberty SW License Agreement V2 (http://www.st.com/software_license_agreement_liberty_v2) 34 | 35 | 3) STM32F10x, STM32L1xx and STM32F3xx USB-FS-Device Driver 36 | URL: http://www.st.com/en/embedded-software/stsw-stm32121.html 37 | License: MCD-ST Liberty SW License Agreement V2 (http://www.st.com/software_license_agreement_liberty_v2) 38 | -------------------------------------------------------------------------------- /Libraries/CMSIS/Include/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 11. November 2010 5 | * $Revision: V1.0.2 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Version 1.0.2 2010/11/11 15 | * Documentation updated. 16 | * 17 | * Version 1.0.1 2010/10/05 18 | * Production release and review comments incorporated. 19 | * 20 | * Version 1.0.0 2010/09/20 21 | * Production release and review comments incorporated. 22 | * -------------------------------------------------------------------- */ 23 | 24 | #ifndef _ARM_COMMON_TABLES_H 25 | #define _ARM_COMMON_TABLES_H 26 | 27 | #include "arm_math.h" 28 | 29 | extern const uint16_t armBitRevTable[1024]; 30 | extern const q15_t armRecipTableQ15[64]; 31 | extern const q31_t armRecipTableQ31[64]; 32 | extern const q31_t realCoefAQ31[1024]; 33 | extern const q31_t realCoefBQ31[1024]; 34 | extern const float32_t twiddleCoef[6144]; 35 | extern const q31_t twiddleCoefQ31[6144]; 36 | extern const q15_t twiddleCoefQ15[6144]; 37 | 38 | #endif /* ARM_COMMON_TABLES_H */ 39 | -------------------------------------------------------------------------------- /Libraries/CMSIS/README.txt: -------------------------------------------------------------------------------- 1 | * ------------------------------------------------------------------- 2 | * Copyright (C) 2011-2012 ARM Limited. All rights reserved. 3 | * 4 | * Date: 07 March 2012 5 | * Revision: V3.01 6 | * 7 | * Project: Cortex Microcontroller Software Interface Standard (CMSIS) 8 | * Title: Release Note for CMSIS 9 | * 10 | * ------------------------------------------------------------------- 11 | 12 | 13 | NOTE - Open the index.html file to access CMSIS documentation 14 | 15 | 16 | The Cortex Microcontroller Software Interface Standard (CMSIS) provides a single standard across all 17 | Cortex-Mx processor series vendors. It enables code re-use and code sharing across software projects 18 | and reduces time-to-market for new embedded applications. 19 | 20 | CMSIS is released under the terms of the end user license agreement ("CMSIS END USER LICENCE AGREEMENT.pdf"). 21 | Any user of the software package is bound to the terms and conditions of the end user license agreement. 22 | 23 | 24 | You will find the following sub-directories: 25 | 26 | Documentation - Contains CMSIS documentation. 27 | 28 | DSP_Lib - MDK project files, Examples and source files etc.. to build the 29 | CMSIS DSP Software Library for Cortex-M0, Cortex-M3, Cortex-M4 processors. 30 | 31 | Include - CMSIS Core Support and CMSIS DSP Include Files. 32 | 33 | Lib - CMSIS DSP Libraries. 34 | 35 | RTOS - CMSIS RTOS API template header file. 36 | 37 | SVD - CMSIS SVD Schema files and Conversion Utility. 38 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the miscellaneous 8 | * firmware library functions (add-on to CMSIS functions). 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __MISC_H 31 | #define __MISC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup MISC 45 | * @{ 46 | */ 47 | 48 | /** @defgroup MISC_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @brief NVIC Init Structure definition 54 | */ 55 | 56 | typedef struct 57 | { 58 | uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. 59 | This parameter can be a value of @ref IRQn_Type 60 | (For the complete STM32 Devices IRQ Channels list, please 61 | refer to stm32f10x.h file) */ 62 | 63 | uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel 64 | specified in NVIC_IRQChannel. This parameter can be a value 65 | between 0 and 15 as described in the table @ref NVIC_Priority_Table */ 66 | 67 | uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified 68 | in NVIC_IRQChannel. This parameter can be a value 69 | between 0 and 15 as described in the table @ref NVIC_Priority_Table */ 70 | 71 | FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel 72 | will be enabled or disabled. 73 | This parameter can be set either to ENABLE or DISABLE */ 74 | } NVIC_InitTypeDef; 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup NVIC_Priority_Table 81 | * @{ 82 | */ 83 | 84 | /** 85 | @code 86 | The table below gives the allowed values of the pre-emption priority and subpriority according 87 | to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function 88 | ============================================================================================================================ 89 | NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description 90 | ============================================================================================================================ 91 | NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption priority 92 | | | | 4 bits for subpriority 93 | ---------------------------------------------------------------------------------------------------------------------------- 94 | NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption priority 95 | | | | 3 bits for subpriority 96 | ---------------------------------------------------------------------------------------------------------------------------- 97 | NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption priority 98 | | | | 2 bits for subpriority 99 | ---------------------------------------------------------------------------------------------------------------------------- 100 | NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption priority 101 | | | | 1 bits for subpriority 102 | ---------------------------------------------------------------------------------------------------------------------------- 103 | NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption priority 104 | | | | 0 bits for subpriority 105 | ============================================================================================================================ 106 | @endcode 107 | */ 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** @defgroup MISC_Exported_Constants 114 | * @{ 115 | */ 116 | 117 | /** @defgroup Vector_Table_Base 118 | * @{ 119 | */ 120 | 121 | #define NVIC_VectTab_RAM ((uint32_t)0x20000000) 122 | #define NVIC_VectTab_FLASH ((uint32_t)0x08000000) 123 | #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \ 124 | ((VECTTAB) == NVIC_VectTab_FLASH)) 125 | /** 126 | * @} 127 | */ 128 | 129 | /** @defgroup System_Low_Power 130 | * @{ 131 | */ 132 | 133 | #define NVIC_LP_SEVONPEND ((uint8_t)0x10) 134 | #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04) 135 | #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02) 136 | #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \ 137 | ((LP) == NVIC_LP_SLEEPDEEP) || \ 138 | ((LP) == NVIC_LP_SLEEPONEXIT)) 139 | /** 140 | * @} 141 | */ 142 | 143 | /** @defgroup Preemption_Priority_Group 144 | * @{ 145 | */ 146 | 147 | #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority 148 | 4 bits for subpriority */ 149 | #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority 150 | 3 bits for subpriority */ 151 | #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority 152 | 2 bits for subpriority */ 153 | #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority 154 | 1 bits for subpriority */ 155 | #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority 156 | 0 bits for subpriority */ 157 | 158 | #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \ 159 | ((GROUP) == NVIC_PriorityGroup_1) || \ 160 | ((GROUP) == NVIC_PriorityGroup_2) || \ 161 | ((GROUP) == NVIC_PriorityGroup_3) || \ 162 | ((GROUP) == NVIC_PriorityGroup_4)) 163 | 164 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 165 | 166 | #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 167 | 168 | #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF) 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | /** @defgroup SysTick_clock_source 175 | * @{ 176 | */ 177 | 178 | #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB) 179 | #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004) 180 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \ 181 | ((SOURCE) == SysTick_CLKSource_HCLK_Div8)) 182 | /** 183 | * @} 184 | */ 185 | 186 | /** 187 | * @} 188 | */ 189 | 190 | /** @defgroup MISC_Exported_Macros 191 | * @{ 192 | */ 193 | 194 | /** 195 | * @} 196 | */ 197 | 198 | /** @defgroup MISC_Exported_Functions 199 | * @{ 200 | */ 201 | 202 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup); 203 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); 204 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset); 205 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState); 206 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); 207 | 208 | #ifdef __cplusplus 209 | } 210 | #endif 211 | 212 | #endif /* __MISC_H */ 213 | 214 | /** 215 | * @} 216 | */ 217 | 218 | /** 219 | * @} 220 | */ 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 227 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_bkp.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_bkp.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the BKP firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_BKP_H 31 | #define __STM32F10x_BKP_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup BKP 45 | * @{ 46 | */ 47 | 48 | /** @defgroup BKP_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup BKP_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup Tamper_Pin_active_level 61 | * @{ 62 | */ 63 | 64 | #define BKP_TamperPinLevel_High ((uint16_t)0x0000) 65 | #define BKP_TamperPinLevel_Low ((uint16_t)0x0001) 66 | #define IS_BKP_TAMPER_PIN_LEVEL(LEVEL) (((LEVEL) == BKP_TamperPinLevel_High) || \ 67 | ((LEVEL) == BKP_TamperPinLevel_Low)) 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup RTC_output_source_to_output_on_the_Tamper_pin 73 | * @{ 74 | */ 75 | 76 | #define BKP_RTCOutputSource_None ((uint16_t)0x0000) 77 | #define BKP_RTCOutputSource_CalibClock ((uint16_t)0x0080) 78 | #define BKP_RTCOutputSource_Alarm ((uint16_t)0x0100) 79 | #define BKP_RTCOutputSource_Second ((uint16_t)0x0300) 80 | #define IS_BKP_RTC_OUTPUT_SOURCE(SOURCE) (((SOURCE) == BKP_RTCOutputSource_None) || \ 81 | ((SOURCE) == BKP_RTCOutputSource_CalibClock) || \ 82 | ((SOURCE) == BKP_RTCOutputSource_Alarm) || \ 83 | ((SOURCE) == BKP_RTCOutputSource_Second)) 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup Data_Backup_Register 89 | * @{ 90 | */ 91 | 92 | #define BKP_DR1 ((uint16_t)0x0004) 93 | #define BKP_DR2 ((uint16_t)0x0008) 94 | #define BKP_DR3 ((uint16_t)0x000C) 95 | #define BKP_DR4 ((uint16_t)0x0010) 96 | #define BKP_DR5 ((uint16_t)0x0014) 97 | #define BKP_DR6 ((uint16_t)0x0018) 98 | #define BKP_DR7 ((uint16_t)0x001C) 99 | #define BKP_DR8 ((uint16_t)0x0020) 100 | #define BKP_DR9 ((uint16_t)0x0024) 101 | #define BKP_DR10 ((uint16_t)0x0028) 102 | #define BKP_DR11 ((uint16_t)0x0040) 103 | #define BKP_DR12 ((uint16_t)0x0044) 104 | #define BKP_DR13 ((uint16_t)0x0048) 105 | #define BKP_DR14 ((uint16_t)0x004C) 106 | #define BKP_DR15 ((uint16_t)0x0050) 107 | #define BKP_DR16 ((uint16_t)0x0054) 108 | #define BKP_DR17 ((uint16_t)0x0058) 109 | #define BKP_DR18 ((uint16_t)0x005C) 110 | #define BKP_DR19 ((uint16_t)0x0060) 111 | #define BKP_DR20 ((uint16_t)0x0064) 112 | #define BKP_DR21 ((uint16_t)0x0068) 113 | #define BKP_DR22 ((uint16_t)0x006C) 114 | #define BKP_DR23 ((uint16_t)0x0070) 115 | #define BKP_DR24 ((uint16_t)0x0074) 116 | #define BKP_DR25 ((uint16_t)0x0078) 117 | #define BKP_DR26 ((uint16_t)0x007C) 118 | #define BKP_DR27 ((uint16_t)0x0080) 119 | #define BKP_DR28 ((uint16_t)0x0084) 120 | #define BKP_DR29 ((uint16_t)0x0088) 121 | #define BKP_DR30 ((uint16_t)0x008C) 122 | #define BKP_DR31 ((uint16_t)0x0090) 123 | #define BKP_DR32 ((uint16_t)0x0094) 124 | #define BKP_DR33 ((uint16_t)0x0098) 125 | #define BKP_DR34 ((uint16_t)0x009C) 126 | #define BKP_DR35 ((uint16_t)0x00A0) 127 | #define BKP_DR36 ((uint16_t)0x00A4) 128 | #define BKP_DR37 ((uint16_t)0x00A8) 129 | #define BKP_DR38 ((uint16_t)0x00AC) 130 | #define BKP_DR39 ((uint16_t)0x00B0) 131 | #define BKP_DR40 ((uint16_t)0x00B4) 132 | #define BKP_DR41 ((uint16_t)0x00B8) 133 | #define BKP_DR42 ((uint16_t)0x00BC) 134 | 135 | #define IS_BKP_DR(DR) (((DR) == BKP_DR1) || ((DR) == BKP_DR2) || ((DR) == BKP_DR3) || \ 136 | ((DR) == BKP_DR4) || ((DR) == BKP_DR5) || ((DR) == BKP_DR6) || \ 137 | ((DR) == BKP_DR7) || ((DR) == BKP_DR8) || ((DR) == BKP_DR9) || \ 138 | ((DR) == BKP_DR10) || ((DR) == BKP_DR11) || ((DR) == BKP_DR12) || \ 139 | ((DR) == BKP_DR13) || ((DR) == BKP_DR14) || ((DR) == BKP_DR15) || \ 140 | ((DR) == BKP_DR16) || ((DR) == BKP_DR17) || ((DR) == BKP_DR18) || \ 141 | ((DR) == BKP_DR19) || ((DR) == BKP_DR20) || ((DR) == BKP_DR21) || \ 142 | ((DR) == BKP_DR22) || ((DR) == BKP_DR23) || ((DR) == BKP_DR24) || \ 143 | ((DR) == BKP_DR25) || ((DR) == BKP_DR26) || ((DR) == BKP_DR27) || \ 144 | ((DR) == BKP_DR28) || ((DR) == BKP_DR29) || ((DR) == BKP_DR30) || \ 145 | ((DR) == BKP_DR31) || ((DR) == BKP_DR32) || ((DR) == BKP_DR33) || \ 146 | ((DR) == BKP_DR34) || ((DR) == BKP_DR35) || ((DR) == BKP_DR36) || \ 147 | ((DR) == BKP_DR37) || ((DR) == BKP_DR38) || ((DR) == BKP_DR39) || \ 148 | ((DR) == BKP_DR40) || ((DR) == BKP_DR41) || ((DR) == BKP_DR42)) 149 | 150 | #define IS_BKP_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x7F) 151 | /** 152 | * @} 153 | */ 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /** @defgroup BKP_Exported_Macros 160 | * @{ 161 | */ 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | /** @defgroup BKP_Exported_Functions 168 | * @{ 169 | */ 170 | 171 | void BKP_DeInit(void); 172 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel); 173 | void BKP_TamperPinCmd(FunctionalState NewState); 174 | void BKP_ITConfig(FunctionalState NewState); 175 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource); 176 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue); 177 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data); 178 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR); 179 | FlagStatus BKP_GetFlagStatus(void); 180 | void BKP_ClearFlag(void); 181 | ITStatus BKP_GetITStatus(void); 182 | void BKP_ClearITPendingBit(void); 183 | 184 | #ifdef __cplusplus 185 | } 186 | #endif 187 | 188 | #endif /* __STM32F10x_BKP_H */ 189 | /** 190 | * @} 191 | */ 192 | 193 | /** 194 | * @} 195 | */ 196 | 197 | /** 198 | * @} 199 | */ 200 | 201 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 202 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_cec.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_cec.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the CEC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_CEC_H 31 | #define __STM32F10x_CEC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CEC 45 | * @{ 46 | */ 47 | 48 | 49 | /** @defgroup CEC_Exported_Types 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @brief CEC Init structure definition 55 | */ 56 | typedef struct 57 | { 58 | uint16_t CEC_BitTimingMode; /*!< Configures the CEC Bit Timing Error Mode. 59 | This parameter can be a value of @ref CEC_BitTiming_Mode */ 60 | uint16_t CEC_BitPeriodMode; /*!< Configures the CEC Bit Period Error Mode. 61 | This parameter can be a value of @ref CEC_BitPeriod_Mode */ 62 | }CEC_InitTypeDef; 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup CEC_Exported_Constants 69 | * @{ 70 | */ 71 | 72 | /** @defgroup CEC_BitTiming_Mode 73 | * @{ 74 | */ 75 | #define CEC_BitTimingStdMode ((uint16_t)0x00) /*!< Bit timing error Standard Mode */ 76 | #define CEC_BitTimingErrFreeMode CEC_CFGR_BTEM /*!< Bit timing error Free Mode */ 77 | 78 | #define IS_CEC_BIT_TIMING_ERROR_MODE(MODE) (((MODE) == CEC_BitTimingStdMode) || \ 79 | ((MODE) == CEC_BitTimingErrFreeMode)) 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup CEC_BitPeriod_Mode 85 | * @{ 86 | */ 87 | #define CEC_BitPeriodStdMode ((uint16_t)0x00) /*!< Bit period error Standard Mode */ 88 | #define CEC_BitPeriodFlexibleMode CEC_CFGR_BPEM /*!< Bit period error Flexible Mode */ 89 | 90 | #define IS_CEC_BIT_PERIOD_ERROR_MODE(MODE) (((MODE) == CEC_BitPeriodStdMode) || \ 91 | ((MODE) == CEC_BitPeriodFlexibleMode)) 92 | /** 93 | * @} 94 | */ 95 | 96 | 97 | /** @defgroup CEC_interrupts_definition 98 | * @{ 99 | */ 100 | #define CEC_IT_TERR CEC_CSR_TERR 101 | #define CEC_IT_TBTRF CEC_CSR_TBTRF 102 | #define CEC_IT_RERR CEC_CSR_RERR 103 | #define CEC_IT_RBTF CEC_CSR_RBTF 104 | #define IS_CEC_GET_IT(IT) (((IT) == CEC_IT_TERR) || ((IT) == CEC_IT_TBTRF) || \ 105 | ((IT) == CEC_IT_RERR) || ((IT) == CEC_IT_RBTF)) 106 | /** 107 | * @} 108 | */ 109 | 110 | 111 | /** @defgroup CEC_Own_Address 112 | * @{ 113 | */ 114 | #define IS_CEC_ADDRESS(ADDRESS) ((ADDRESS) < 0x10) 115 | /** 116 | * @} 117 | */ 118 | 119 | /** @defgroup CEC_Prescaler 120 | * @{ 121 | */ 122 | #define IS_CEC_PRESCALER(PRESCALER) ((PRESCALER) <= 0x3FFF) 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | /** @defgroup CEC_flags_definition 129 | * @{ 130 | */ 131 | 132 | /** 133 | * @brief ESR register flags 134 | */ 135 | #define CEC_FLAG_BTE ((uint32_t)0x10010000) 136 | #define CEC_FLAG_BPE ((uint32_t)0x10020000) 137 | #define CEC_FLAG_RBTFE ((uint32_t)0x10040000) 138 | #define CEC_FLAG_SBE ((uint32_t)0x10080000) 139 | #define CEC_FLAG_ACKE ((uint32_t)0x10100000) 140 | #define CEC_FLAG_LINE ((uint32_t)0x10200000) 141 | #define CEC_FLAG_TBTFE ((uint32_t)0x10400000) 142 | 143 | /** 144 | * @brief CSR register flags 145 | */ 146 | #define CEC_FLAG_TEOM ((uint32_t)0x00000002) 147 | #define CEC_FLAG_TERR ((uint32_t)0x00000004) 148 | #define CEC_FLAG_TBTRF ((uint32_t)0x00000008) 149 | #define CEC_FLAG_RSOM ((uint32_t)0x00000010) 150 | #define CEC_FLAG_REOM ((uint32_t)0x00000020) 151 | #define CEC_FLAG_RERR ((uint32_t)0x00000040) 152 | #define CEC_FLAG_RBTF ((uint32_t)0x00000080) 153 | 154 | #define IS_CEC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF03) == 0x00) && ((FLAG) != 0x00)) 155 | 156 | #define IS_CEC_GET_FLAG(FLAG) (((FLAG) == CEC_FLAG_BTE) || ((FLAG) == CEC_FLAG_BPE) || \ 157 | ((FLAG) == CEC_FLAG_RBTFE) || ((FLAG)== CEC_FLAG_SBE) || \ 158 | ((FLAG) == CEC_FLAG_ACKE) || ((FLAG) == CEC_FLAG_LINE) || \ 159 | ((FLAG) == CEC_FLAG_TBTFE) || ((FLAG) == CEC_FLAG_TEOM) || \ 160 | ((FLAG) == CEC_FLAG_TERR) || ((FLAG) == CEC_FLAG_TBTRF) || \ 161 | ((FLAG) == CEC_FLAG_RSOM) || ((FLAG) == CEC_FLAG_REOM) || \ 162 | ((FLAG) == CEC_FLAG_RERR) || ((FLAG) == CEC_FLAG_RBTF)) 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | /** @defgroup CEC_Exported_Macros 173 | * @{ 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /** @defgroup CEC_Exported_Functions 181 | * @{ 182 | */ 183 | void CEC_DeInit(void); 184 | void CEC_Init(CEC_InitTypeDef* CEC_InitStruct); 185 | void CEC_Cmd(FunctionalState NewState); 186 | void CEC_ITConfig(FunctionalState NewState); 187 | void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress); 188 | void CEC_SetPrescaler(uint16_t CEC_Prescaler); 189 | void CEC_SendDataByte(uint8_t Data); 190 | uint8_t CEC_ReceiveDataByte(void); 191 | void CEC_StartOfMessage(void); 192 | void CEC_EndOfMessageCmd(FunctionalState NewState); 193 | FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG); 194 | void CEC_ClearFlag(uint32_t CEC_FLAG); 195 | ITStatus CEC_GetITStatus(uint8_t CEC_IT); 196 | void CEC_ClearITPendingBit(uint16_t CEC_IT); 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif 201 | 202 | #endif /* __STM32F10x_CEC_H */ 203 | 204 | /** 205 | * @} 206 | */ 207 | 208 | /** 209 | * @} 210 | */ 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 217 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_CRC_H 31 | #define __STM32F10x_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /** @defgroup CRC_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup CRC_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup CRC_Exported_Macros 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup CRC_Exported_Functions 73 | * @{ 74 | */ 75 | 76 | void CRC_ResetDR(void); 77 | uint32_t CRC_CalcCRC(uint32_t Data); 78 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 79 | uint32_t CRC_GetCRC(void); 80 | void CRC_SetIDRegister(uint8_t IDValue); 81 | uint8_t CRC_GetIDRegister(void); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* __STM32F10x_CRC_H */ 88 | /** 89 | * @} 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 101 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_DBGMCU_H 31 | #define __STM32F10x_DBGMCU_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup DBGMCU 45 | * @{ 46 | */ 47 | 48 | /** @defgroup DBGMCU_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup DBGMCU_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 61 | #define DBGMCU_STOP ((uint32_t)0x00000002) 62 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 63 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 64 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 65 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 66 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 67 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 68 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 69 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 70 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 71 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 72 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 73 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 74 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 75 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 76 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 77 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 78 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 79 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 80 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 81 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 82 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 83 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 84 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 85 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 86 | 87 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup DBGMCU_Exported_Macros 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** @defgroup DBGMCU_Exported_Functions 101 | * @{ 102 | */ 103 | 104 | uint32_t DBGMCU_GetREVID(void); 105 | uint32_t DBGMCU_GetDEVID(void); 106 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* __STM32F10x_DBGMCU_H */ 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 126 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the EXTI firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_EXTI_H 31 | #define __STM32F10x_EXTI_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup EXTI 45 | * @{ 46 | */ 47 | 48 | /** @defgroup EXTI_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @brief EXTI mode enumeration 54 | */ 55 | 56 | typedef enum 57 | { 58 | EXTI_Mode_Interrupt = 0x00, 59 | EXTI_Mode_Event = 0x04 60 | }EXTIMode_TypeDef; 61 | 62 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) 63 | 64 | /** 65 | * @brief EXTI Trigger enumeration 66 | */ 67 | 68 | typedef enum 69 | { 70 | EXTI_Trigger_Rising = 0x08, 71 | EXTI_Trigger_Falling = 0x0C, 72 | EXTI_Trigger_Rising_Falling = 0x10 73 | }EXTITrigger_TypeDef; 74 | 75 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \ 76 | ((TRIGGER) == EXTI_Trigger_Falling) || \ 77 | ((TRIGGER) == EXTI_Trigger_Rising_Falling)) 78 | /** 79 | * @brief EXTI Init Structure definition 80 | */ 81 | 82 | typedef struct 83 | { 84 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. 85 | This parameter can be any combination of @ref EXTI_Lines */ 86 | 87 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. 88 | This parameter can be a value of @ref EXTIMode_TypeDef */ 89 | 90 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. 91 | This parameter can be a value of @ref EXTITrigger_TypeDef */ 92 | 93 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. 94 | This parameter can be set either to ENABLE or DISABLE */ 95 | }EXTI_InitTypeDef; 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup EXTI_Exported_Constants 102 | * @{ 103 | */ 104 | 105 | /** @defgroup EXTI_Lines 106 | * @{ 107 | */ 108 | 109 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */ 110 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */ 111 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */ 112 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */ 113 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */ 114 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */ 115 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */ 116 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */ 117 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */ 118 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */ 119 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */ 120 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */ 121 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */ 122 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */ 123 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */ 124 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */ 125 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */ 126 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 127 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB Device/USB OTG FS 128 | Wakeup from suspend event */ 129 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */ 130 | 131 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00)) 132 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \ 133 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \ 134 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \ 135 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \ 136 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \ 137 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \ 138 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \ 139 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \ 140 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \ 141 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19)) 142 | 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** @defgroup EXTI_Exported_Macros 153 | * @{ 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** @defgroup EXTI_Exported_Functions 161 | * @{ 162 | */ 163 | 164 | void EXTI_DeInit(void); 165 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); 166 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct); 167 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line); 168 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line); 169 | void EXTI_ClearFlag(uint32_t EXTI_Line); 170 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line); 171 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line); 172 | 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | #endif /* __STM32F10x_EXTI_H */ 178 | /** 179 | * @} 180 | */ 181 | 182 | /** 183 | * @} 184 | */ 185 | 186 | /** 187 | * @} 188 | */ 189 | 190 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 191 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_IWDG_H 31 | #define __STM32F10x_IWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup IWDG 45 | * @{ 46 | */ 47 | 48 | /** @defgroup IWDG_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup IWDG_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup IWDG_WriteAccess 61 | * @{ 62 | */ 63 | 64 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 65 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 66 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 67 | ((ACCESS) == IWDG_WriteAccess_Disable)) 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup IWDG_prescaler 73 | * @{ 74 | */ 75 | 76 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 77 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 78 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 79 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 80 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 81 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 82 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 83 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 84 | ((PRESCALER) == IWDG_Prescaler_8) || \ 85 | ((PRESCALER) == IWDG_Prescaler_16) || \ 86 | ((PRESCALER) == IWDG_Prescaler_32) || \ 87 | ((PRESCALER) == IWDG_Prescaler_64) || \ 88 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 89 | ((PRESCALER) == IWDG_Prescaler_256)) 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup IWDG_Flag 95 | * @{ 96 | */ 97 | 98 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 99 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 100 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 101 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 102 | /** 103 | * @} 104 | */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** @defgroup IWDG_Exported_Macros 111 | * @{ 112 | */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** @defgroup IWDG_Exported_Functions 119 | * @{ 120 | */ 121 | 122 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 123 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 124 | void IWDG_SetReload(uint16_t Reload); 125 | void IWDG_ReloadCounter(void); 126 | void IWDG_Enable(void); 127 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* __STM32F10x_IWDG_H */ 134 | /** 135 | * @} 136 | */ 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 147 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_PWR_H 31 | #define __STM32F10x_PWR_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup PWR 45 | * @{ 46 | */ 47 | 48 | /** @defgroup PWR_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup PWR_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup PVD_detection_level 61 | * @{ 62 | */ 63 | 64 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 65 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 66 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 67 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 68 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 69 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 70 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 71 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 72 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 73 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 74 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 75 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup Regulator_state_is_STOP_mode 81 | * @{ 82 | */ 83 | 84 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 85 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 86 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 87 | ((REGULATOR) == PWR_Regulator_LowPower)) 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup STOP_mode_entry 93 | * @{ 94 | */ 95 | 96 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 97 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 98 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** @defgroup PWR_Flag 105 | * @{ 106 | */ 107 | 108 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 109 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 110 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 111 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 112 | ((FLAG) == PWR_FLAG_PVDO)) 113 | 114 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | /** @defgroup PWR_Exported_Macros 124 | * @{ 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** @defgroup PWR_Exported_Functions 132 | * @{ 133 | */ 134 | 135 | void PWR_DeInit(void); 136 | void PWR_BackupAccessCmd(FunctionalState NewState); 137 | void PWR_PVDCmd(FunctionalState NewState); 138 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 139 | void PWR_WakeUpPinCmd(FunctionalState NewState); 140 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 141 | void PWR_EnterSTANDBYMode(void); 142 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 143 | void PWR_ClearFlag(uint32_t PWR_FLAG); 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif /* __STM32F10x_PWR_H */ 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 163 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_rtc.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the RTC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_RTC_H 31 | #define __STM32F10x_RTC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup RTC 45 | * @{ 46 | */ 47 | 48 | /** @defgroup RTC_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup RTC_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup RTC_interrupts_define 61 | * @{ 62 | */ 63 | 64 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */ 65 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */ 66 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */ 67 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 68 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 69 | ((IT) == RTC_IT_SEC)) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup RTC_interrupts_flags 75 | * @{ 76 | */ 77 | 78 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */ 79 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */ 80 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */ 81 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */ 82 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */ 83 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 84 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 85 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 86 | ((FLAG) == RTC_FLAG_SEC)) 87 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** @defgroup RTC_Exported_Macros 98 | * @{ 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** @defgroup RTC_Exported_Functions 106 | * @{ 107 | */ 108 | 109 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 110 | void RTC_EnterConfigMode(void); 111 | void RTC_ExitConfigMode(void); 112 | uint32_t RTC_GetCounter(void); 113 | void RTC_SetCounter(uint32_t CounterValue); 114 | void RTC_SetPrescaler(uint32_t PrescalerValue); 115 | void RTC_SetAlarm(uint32_t AlarmValue); 116 | uint32_t RTC_GetDivider(void); 117 | void RTC_WaitForLastTask(void); 118 | void RTC_WaitForSynchro(void); 119 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 120 | void RTC_ClearFlag(uint16_t RTC_FLAG); 121 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 122 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif /* __STM32F10x_RTC_H */ 129 | /** 130 | * @} 131 | */ 132 | 133 | /** 134 | * @} 135 | */ 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 142 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_WWDG_H 31 | #define __STM32F10x_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /** @defgroup WWDG_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup WWDG_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup WWDG_Prescaler 61 | * @{ 62 | */ 63 | 64 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 65 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 66 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 67 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 68 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 69 | ((PRESCALER) == WWDG_Prescaler_2) || \ 70 | ((PRESCALER) == WWDG_Prescaler_4) || \ 71 | ((PRESCALER) == WWDG_Prescaler_8)) 72 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 73 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup WWDG_Exported_Macros 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** @defgroup WWDG_Exported_Functions 91 | * @{ 92 | */ 93 | 94 | void WWDG_DeInit(void); 95 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 96 | void WWDG_SetWindowValue(uint8_t WindowValue); 97 | void WWDG_EnableIT(void); 98 | void WWDG_SetCounter(uint8_t Counter); 99 | void WWDG_Enable(uint8_t Counter); 100 | FlagStatus WWDG_GetFlagStatus(void); 101 | void WWDG_ClearFlag(void); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* __STM32F10x_WWDG_H */ 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 122 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/misc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the miscellaneous firmware functions (add-on 8 | * to CMSIS functions). 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "misc.h" 31 | 32 | /** @addtogroup STM32F10x_StdPeriph_Driver 33 | * @{ 34 | */ 35 | 36 | /** @defgroup MISC 37 | * @brief MISC driver modules 38 | * @{ 39 | */ 40 | 41 | /** @defgroup MISC_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | /** @defgroup MISC_Private_Defines 50 | * @{ 51 | */ 52 | 53 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup MISC_Private_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup MISC_Private_Variables 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup MISC_Private_FunctionPrototypes 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup MISC_Private_Functions 83 | * @{ 84 | */ 85 | 86 | /** 87 | * @brief Configures the priority grouping: pre-emption priority and subpriority. 88 | * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 89 | * This parameter can be one of the following values: 90 | * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority 91 | * 4 bits for subpriority 92 | * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority 93 | * 3 bits for subpriority 94 | * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority 95 | * 2 bits for subpriority 96 | * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority 97 | * 1 bits for subpriority 98 | * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority 99 | * 0 bits for subpriority 100 | * @retval None 101 | */ 102 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) 103 | { 104 | /* Check the parameters */ 105 | assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); 106 | 107 | /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 108 | SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 109 | } 110 | 111 | /** 112 | * @brief Initializes the NVIC peripheral according to the specified 113 | * parameters in the NVIC_InitStruct. 114 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 115 | * the configuration information for the specified NVIC peripheral. 116 | * @retval None 117 | */ 118 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 119 | { 120 | uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 121 | 122 | /* Check the parameters */ 123 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 124 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 125 | assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 126 | 127 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 128 | { 129 | /* Compute the Corresponding IRQ Priority --------------------------------*/ 130 | tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 131 | tmppre = (0x4 - tmppriority); 132 | tmpsub = tmpsub >> tmppriority; 133 | 134 | tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 135 | tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 136 | tmppriority = tmppriority << 0x04; 137 | 138 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 139 | 140 | /* Enable the Selected IRQ Channels --------------------------------------*/ 141 | NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 142 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 143 | } 144 | else 145 | { 146 | /* Disable the Selected IRQ Channels -------------------------------------*/ 147 | NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 148 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 149 | } 150 | } 151 | 152 | /** 153 | * @brief Sets the vector table location and Offset. 154 | * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. 155 | * This parameter can be one of the following values: 156 | * @arg NVIC_VectTab_RAM 157 | * @arg NVIC_VectTab_FLASH 158 | * @param Offset: Vector Table base offset field. This value must be a multiple 159 | * of 0x200. 160 | * @retval None 161 | */ 162 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) 163 | { 164 | /* Check the parameters */ 165 | assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); 166 | assert_param(IS_NVIC_OFFSET(Offset)); 167 | 168 | SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 169 | } 170 | 171 | /** 172 | * @brief Selects the condition for the system to enter low power mode. 173 | * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 174 | * This parameter can be one of the following values: 175 | * @arg NVIC_LP_SEVONPEND 176 | * @arg NVIC_LP_SLEEPDEEP 177 | * @arg NVIC_LP_SLEEPONEXIT 178 | * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. 179 | * @retval None 180 | */ 181 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 182 | { 183 | /* Check the parameters */ 184 | assert_param(IS_NVIC_LP(LowPowerMode)); 185 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 186 | 187 | if (NewState != DISABLE) 188 | { 189 | SCB->SCR |= LowPowerMode; 190 | } 191 | else 192 | { 193 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 194 | } 195 | } 196 | 197 | /** 198 | * @brief Configures the SysTick clock source. 199 | * @param SysTick_CLKSource: specifies the SysTick clock source. 200 | * This parameter can be one of the following values: 201 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 202 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 203 | * @retval None 204 | */ 205 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 206 | { 207 | /* Check the parameters */ 208 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 209 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 210 | { 211 | SysTick->CTRL |= SysTick_CLKSource_HCLK; 212 | } 213 | else 214 | { 215 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 216 | } 217 | } 218 | 219 | /** 220 | * @} 221 | */ 222 | 223 | /** 224 | * @} 225 | */ 226 | 227 | /** 228 | * @} 229 | */ 230 | 231 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 232 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_bkp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_bkp.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the BKP firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_bkp.h" 30 | #include "stm32f10x_rcc.h" 31 | 32 | /** @addtogroup STM32F10x_StdPeriph_Driver 33 | * @{ 34 | */ 35 | 36 | /** @defgroup BKP 37 | * @brief BKP driver modules 38 | * @{ 39 | */ 40 | 41 | /** @defgroup BKP_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | /** @defgroup BKP_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /* ------------ BKP registers bit address in the alias region --------------- */ 54 | #define BKP_OFFSET (BKP_BASE - PERIPH_BASE) 55 | 56 | /* --- CR Register ----*/ 57 | 58 | /* Alias word address of TPAL bit */ 59 | #define CR_OFFSET (BKP_OFFSET + 0x30) 60 | #define TPAL_BitNumber 0x01 61 | #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4)) 62 | 63 | /* Alias word address of TPE bit */ 64 | #define TPE_BitNumber 0x00 65 | #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4)) 66 | 67 | /* --- CSR Register ---*/ 68 | 69 | /* Alias word address of TPIE bit */ 70 | #define CSR_OFFSET (BKP_OFFSET + 0x34) 71 | #define TPIE_BitNumber 0x02 72 | #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4)) 73 | 74 | /* Alias word address of TIF bit */ 75 | #define TIF_BitNumber 0x09 76 | #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4)) 77 | 78 | /* Alias word address of TEF bit */ 79 | #define TEF_BitNumber 0x08 80 | #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4)) 81 | 82 | /* ---------------------- BKP registers bit mask ------------------------ */ 83 | 84 | /* RTCCR register bit mask */ 85 | #define RTCCR_CAL_MASK ((uint16_t)0xFF80) 86 | #define RTCCR_MASK ((uint16_t)0xFC7F) 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | 93 | /** @defgroup BKP_Private_Macros 94 | * @{ 95 | */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup BKP_Private_Variables 102 | * @{ 103 | */ 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /** @defgroup BKP_Private_FunctionPrototypes 110 | * @{ 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup BKP_Private_Functions 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @brief Deinitializes the BKP peripheral registers to their default reset values. 123 | * @param None 124 | * @retval None 125 | */ 126 | void BKP_DeInit(void) 127 | { 128 | RCC_BackupResetCmd(ENABLE); 129 | RCC_BackupResetCmd(DISABLE); 130 | } 131 | 132 | /** 133 | * @brief Configures the Tamper Pin active level. 134 | * @param BKP_TamperPinLevel: specifies the Tamper Pin active level. 135 | * This parameter can be one of the following values: 136 | * @arg BKP_TamperPinLevel_High: Tamper pin active on high level 137 | * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level 138 | * @retval None 139 | */ 140 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel) 141 | { 142 | /* Check the parameters */ 143 | assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel)); 144 | *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel; 145 | } 146 | 147 | /** 148 | * @brief Enables or disables the Tamper Pin activation. 149 | * @param NewState: new state of the Tamper Pin activation. 150 | * This parameter can be: ENABLE or DISABLE. 151 | * @retval None 152 | */ 153 | void BKP_TamperPinCmd(FunctionalState NewState) 154 | { 155 | /* Check the parameters */ 156 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 157 | *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState; 158 | } 159 | 160 | /** 161 | * @brief Enables or disables the Tamper Pin Interrupt. 162 | * @param NewState: new state of the Tamper Pin Interrupt. 163 | * This parameter can be: ENABLE or DISABLE. 164 | * @retval None 165 | */ 166 | void BKP_ITConfig(FunctionalState NewState) 167 | { 168 | /* Check the parameters */ 169 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 170 | *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState; 171 | } 172 | 173 | /** 174 | * @brief Select the RTC output source to output on the Tamper pin. 175 | * @param BKP_RTCOutputSource: specifies the RTC output source. 176 | * This parameter can be one of the following values: 177 | * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin. 178 | * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency 179 | * divided by 64 on the Tamper pin. 180 | * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on 181 | * the Tamper pin. 182 | * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on 183 | * the Tamper pin. 184 | * @retval None 185 | */ 186 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource) 187 | { 188 | uint16_t tmpreg = 0; 189 | /* Check the parameters */ 190 | assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource)); 191 | tmpreg = BKP->RTCCR; 192 | /* Clear CCO, ASOE and ASOS bits */ 193 | tmpreg &= RTCCR_MASK; 194 | 195 | /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */ 196 | tmpreg |= BKP_RTCOutputSource; 197 | /* Store the new value */ 198 | BKP->RTCCR = tmpreg; 199 | } 200 | 201 | /** 202 | * @brief Sets RTC Clock Calibration value. 203 | * @param CalibrationValue: specifies the RTC Clock Calibration value. 204 | * This parameter must be a number between 0 and 0x7F. 205 | * @retval None 206 | */ 207 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue) 208 | { 209 | uint16_t tmpreg = 0; 210 | /* Check the parameters */ 211 | assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue)); 212 | tmpreg = BKP->RTCCR; 213 | /* Clear CAL[6:0] bits */ 214 | tmpreg &= RTCCR_CAL_MASK; 215 | /* Set CAL[6:0] bits according to CalibrationValue value */ 216 | tmpreg |= CalibrationValue; 217 | /* Store the new value */ 218 | BKP->RTCCR = tmpreg; 219 | } 220 | 221 | /** 222 | * @brief Writes user data to the specified Data Backup Register. 223 | * @param BKP_DR: specifies the Data Backup Register. 224 | * This parameter can be BKP_DRx where x:[1, 42] 225 | * @param Data: data to write 226 | * @retval None 227 | */ 228 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data) 229 | { 230 | __IO uint32_t tmp = 0; 231 | 232 | /* Check the parameters */ 233 | assert_param(IS_BKP_DR(BKP_DR)); 234 | 235 | tmp = (uint32_t)BKP_BASE; 236 | tmp += BKP_DR; 237 | 238 | *(__IO uint32_t *) tmp = Data; 239 | } 240 | 241 | /** 242 | * @brief Reads data from the specified Data Backup Register. 243 | * @param BKP_DR: specifies the Data Backup Register. 244 | * This parameter can be BKP_DRx where x:[1, 42] 245 | * @retval The content of the specified Data Backup Register 246 | */ 247 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR) 248 | { 249 | __IO uint32_t tmp = 0; 250 | 251 | /* Check the parameters */ 252 | assert_param(IS_BKP_DR(BKP_DR)); 253 | 254 | tmp = (uint32_t)BKP_BASE; 255 | tmp += BKP_DR; 256 | 257 | return (*(__IO uint16_t *) tmp); 258 | } 259 | 260 | /** 261 | * @brief Checks whether the Tamper Pin Event flag is set or not. 262 | * @param None 263 | * @retval The new state of the Tamper Pin Event flag (SET or RESET). 264 | */ 265 | FlagStatus BKP_GetFlagStatus(void) 266 | { 267 | return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB); 268 | } 269 | 270 | /** 271 | * @brief Clears Tamper Pin Event pending flag. 272 | * @param None 273 | * @retval None 274 | */ 275 | void BKP_ClearFlag(void) 276 | { 277 | /* Set CTE bit to clear Tamper Pin Event flag */ 278 | BKP->CSR |= BKP_CSR_CTE; 279 | } 280 | 281 | /** 282 | * @brief Checks whether the Tamper Pin Interrupt has occurred or not. 283 | * @param None 284 | * @retval The new state of the Tamper Pin Interrupt (SET or RESET). 285 | */ 286 | ITStatus BKP_GetITStatus(void) 287 | { 288 | return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB); 289 | } 290 | 291 | /** 292 | * @brief Clears Tamper Pin Interrupt pending bit. 293 | * @param None 294 | * @retval None 295 | */ 296 | void BKP_ClearITPendingBit(void) 297 | { 298 | /* Set CTI bit to clear Tamper Pin Interrupt pending bit */ 299 | BKP->CSR |= BKP_CSR_CTI; 300 | } 301 | 302 | /** 303 | * @} 304 | */ 305 | 306 | /** 307 | * @} 308 | */ 309 | 310 | /** 311 | * @} 312 | */ 313 | 314 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 315 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_crc.h" 30 | 31 | /** @addtogroup STM32F10x_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup CRC 36 | * @brief CRC driver modules 37 | * @{ 38 | */ 39 | 40 | /** @defgroup CRC_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | /** @defgroup CRC_Private_Defines 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup CRC_Private_Macros 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup CRC_Private_Variables 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup CRC_Private_FunctionPrototypes 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup CRC_Private_Functions 81 | * @{ 82 | */ 83 | 84 | /** 85 | * @brief Resets the CRC Data register (DR). 86 | * @param None 87 | * @retval None 88 | */ 89 | void CRC_ResetDR(void) 90 | { 91 | /* Reset CRC generator */ 92 | CRC->CR = CRC_CR_RESET; 93 | } 94 | 95 | /** 96 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 97 | * @param Data: data word(32-bit) to compute its CRC 98 | * @retval 32-bit CRC 99 | */ 100 | uint32_t CRC_CalcCRC(uint32_t Data) 101 | { 102 | CRC->DR = Data; 103 | 104 | return (CRC->DR); 105 | } 106 | 107 | /** 108 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 109 | * @param pBuffer: pointer to the buffer containing the data to be computed 110 | * @param BufferLength: length of the buffer to be computed 111 | * @retval 32-bit CRC 112 | */ 113 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 114 | { 115 | uint32_t index = 0; 116 | 117 | for(index = 0; index < BufferLength; index++) 118 | { 119 | CRC->DR = pBuffer[index]; 120 | } 121 | return (CRC->DR); 122 | } 123 | 124 | /** 125 | * @brief Returns the current CRC value. 126 | * @param None 127 | * @retval 32-bit CRC 128 | */ 129 | uint32_t CRC_GetCRC(void) 130 | { 131 | return (CRC->DR); 132 | } 133 | 134 | /** 135 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 136 | * @param IDValue: 8-bit value to be stored in the ID register 137 | * @retval None 138 | */ 139 | void CRC_SetIDRegister(uint8_t IDValue) 140 | { 141 | CRC->IDR = IDValue; 142 | } 143 | 144 | /** 145 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 146 | * @param None 147 | * @retval 8-bit value of the ID register 148 | */ 149 | uint8_t CRC_GetIDRegister(void) 150 | { 151 | return (CRC->IDR); 152 | } 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 167 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the DBGMCU firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_dbgmcu.h" 30 | 31 | /** @addtogroup STM32F10x_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup DBGMCU 36 | * @brief DBGMCU driver modules 37 | * @{ 38 | */ 39 | 40 | /** @defgroup DBGMCU_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | /** @defgroup DBGMCU_Private_Defines 49 | * @{ 50 | */ 51 | 52 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 53 | /** 54 | * @} 55 | */ 56 | 57 | /** @defgroup DBGMCU_Private_Macros 58 | * @{ 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup DBGMCU_Private_Variables 66 | * @{ 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup DBGMCU_Private_FunctionPrototypes 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @defgroup DBGMCU_Private_Functions 82 | * @{ 83 | */ 84 | 85 | /** 86 | * @brief Returns the device revision identifier. 87 | * @param None 88 | * @retval Device revision identifier 89 | */ 90 | uint32_t DBGMCU_GetREVID(void) 91 | { 92 | return(DBGMCU->IDCODE >> 16); 93 | } 94 | 95 | /** 96 | * @brief Returns the device identifier. 97 | * @param None 98 | * @retval Device identifier 99 | */ 100 | uint32_t DBGMCU_GetDEVID(void) 101 | { 102 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 103 | } 104 | 105 | /** 106 | * @brief Configures the specified peripheral and low power mode behavior 107 | * when the MCU under Debug mode. 108 | * @param DBGMCU_Periph: specifies the peripheral and low power mode. 109 | * This parameter can be any combination of the following values: 110 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 111 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 112 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 113 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 114 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 115 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 116 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 117 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 118 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 119 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 120 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 121 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 122 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 123 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 124 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 125 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 126 | * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted 127 | * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted 128 | * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted 129 | * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted 130 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 131 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 132 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 133 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 134 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 135 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 136 | * @param NewState: new state of the specified peripheral in Debug mode. 137 | * This parameter can be: ENABLE or DISABLE. 138 | * @retval None 139 | */ 140 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 141 | { 142 | /* Check the parameters */ 143 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 144 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 145 | 146 | if (NewState != DISABLE) 147 | { 148 | DBGMCU->CR |= DBGMCU_Periph; 149 | } 150 | else 151 | { 152 | DBGMCU->CR &= ~DBGMCU_Periph; 153 | } 154 | } 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 169 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_exti.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the EXTI firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_exti.h" 30 | 31 | /** @addtogroup STM32F10x_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup EXTI 36 | * @brief EXTI driver modules 37 | * @{ 38 | */ 39 | 40 | /** @defgroup EXTI_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | /** @defgroup EXTI_Private_Defines 49 | * @{ 50 | */ 51 | 52 | #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup EXTI_Private_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup EXTI_Private_Variables 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup EXTI_Private_FunctionPrototypes 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup EXTI_Private_Functions 83 | * @{ 84 | */ 85 | 86 | /** 87 | * @brief Deinitializes the EXTI peripheral registers to their default reset values. 88 | * @param None 89 | * @retval None 90 | */ 91 | void EXTI_DeInit(void) 92 | { 93 | EXTI->IMR = 0x00000000; 94 | EXTI->EMR = 0x00000000; 95 | EXTI->RTSR = 0x00000000; 96 | EXTI->FTSR = 0x00000000; 97 | EXTI->PR = 0x000FFFFF; 98 | } 99 | 100 | /** 101 | * @brief Initializes the EXTI peripheral according to the specified 102 | * parameters in the EXTI_InitStruct. 103 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 104 | * that contains the configuration information for the EXTI peripheral. 105 | * @retval None 106 | */ 107 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct) 108 | { 109 | uint32_t tmp = 0; 110 | 111 | /* Check the parameters */ 112 | assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); 113 | assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); 114 | assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); 115 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); 116 | 117 | tmp = (uint32_t)EXTI_BASE; 118 | 119 | if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) 120 | { 121 | /* Clear EXTI line configuration */ 122 | EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; 123 | EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; 124 | 125 | tmp += EXTI_InitStruct->EXTI_Mode; 126 | 127 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 128 | 129 | /* Clear Rising Falling edge configuration */ 130 | EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; 131 | EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; 132 | 133 | /* Select the trigger for the selected external interrupts */ 134 | if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) 135 | { 136 | /* Rising Falling edge */ 137 | EXTI->RTSR |= EXTI_InitStruct->EXTI_Line; 138 | EXTI->FTSR |= EXTI_InitStruct->EXTI_Line; 139 | } 140 | else 141 | { 142 | tmp = (uint32_t)EXTI_BASE; 143 | tmp += EXTI_InitStruct->EXTI_Trigger; 144 | 145 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 146 | } 147 | } 148 | else 149 | { 150 | tmp += EXTI_InitStruct->EXTI_Mode; 151 | 152 | /* Disable the selected external lines */ 153 | *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; 154 | } 155 | } 156 | 157 | /** 158 | * @brief Fills each EXTI_InitStruct member with its reset value. 159 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will 160 | * be initialized. 161 | * @retval None 162 | */ 163 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct) 164 | { 165 | EXTI_InitStruct->EXTI_Line = EXTI_LINENONE; 166 | EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; 167 | EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; 168 | EXTI_InitStruct->EXTI_LineCmd = DISABLE; 169 | } 170 | 171 | /** 172 | * @brief Generates a Software interrupt. 173 | * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled. 174 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 175 | * @retval None 176 | */ 177 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line) 178 | { 179 | /* Check the parameters */ 180 | assert_param(IS_EXTI_LINE(EXTI_Line)); 181 | 182 | EXTI->SWIER |= EXTI_Line; 183 | } 184 | 185 | /** 186 | * @brief Checks whether the specified EXTI line flag is set or not. 187 | * @param EXTI_Line: specifies the EXTI line flag to check. 188 | * This parameter can be: 189 | * @arg EXTI_Linex: External interrupt line x where x(0..19) 190 | * @retval The new state of EXTI_Line (SET or RESET). 191 | */ 192 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line) 193 | { 194 | FlagStatus bitstatus = RESET; 195 | /* Check the parameters */ 196 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 197 | 198 | if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 199 | { 200 | bitstatus = SET; 201 | } 202 | else 203 | { 204 | bitstatus = RESET; 205 | } 206 | return bitstatus; 207 | } 208 | 209 | /** 210 | * @brief Clears the EXTI's line pending flags. 211 | * @param EXTI_Line: specifies the EXTI lines flags to clear. 212 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 213 | * @retval None 214 | */ 215 | void EXTI_ClearFlag(uint32_t EXTI_Line) 216 | { 217 | /* Check the parameters */ 218 | assert_param(IS_EXTI_LINE(EXTI_Line)); 219 | 220 | EXTI->PR = EXTI_Line; 221 | } 222 | 223 | /** 224 | * @brief Checks whether the specified EXTI line is asserted or not. 225 | * @param EXTI_Line: specifies the EXTI line to check. 226 | * This parameter can be: 227 | * @arg EXTI_Linex: External interrupt line x where x(0..19) 228 | * @retval The new state of EXTI_Line (SET or RESET). 229 | */ 230 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line) 231 | { 232 | ITStatus bitstatus = RESET; 233 | uint32_t enablestatus = 0; 234 | /* Check the parameters */ 235 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 236 | 237 | enablestatus = EXTI->IMR & EXTI_Line; 238 | if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 239 | { 240 | bitstatus = SET; 241 | } 242 | else 243 | { 244 | bitstatus = RESET; 245 | } 246 | return bitstatus; 247 | } 248 | 249 | /** 250 | * @brief Clears the EXTI's line pending bits. 251 | * @param EXTI_Line: specifies the EXTI lines to clear. 252 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 253 | * @retval None 254 | */ 255 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line) 256 | { 257 | /* Check the parameters */ 258 | assert_param(IS_EXTI_LINE(EXTI_Line)); 259 | 260 | EXTI->PR = EXTI_Line; 261 | } 262 | 263 | /** 264 | * @} 265 | */ 266 | 267 | /** 268 | * @} 269 | */ 270 | 271 | /** 272 | * @} 273 | */ 274 | 275 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 276 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vdm-dev/stm32-ch340/50b50a5fb211a439dcc4fd32943b5d73395a037a/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vdm-dev/stm32-ch340/50b50a5fb211a439dcc4fd32943b5d73395a037a/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the IWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_iwdg.h" 30 | 31 | /** @addtogroup STM32F10x_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup IWDG 36 | * @brief IWDG driver modules 37 | * @{ 38 | */ 39 | 40 | /** @defgroup IWDG_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | /** @defgroup IWDG_Private_Defines 49 | * @{ 50 | */ 51 | 52 | /* ---------------------- IWDG registers bit mask ----------------------------*/ 53 | 54 | /* KR register bit mask */ 55 | #define KR_KEY_Reload ((uint16_t)0xAAAA) 56 | #define KR_KEY_Enable ((uint16_t)0xCCCC) 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup IWDG_Private_Macros 63 | * @{ 64 | */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** @defgroup IWDG_Private_Variables 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @defgroup IWDG_Private_FunctionPrototypes 79 | * @{ 80 | */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup IWDG_Private_Functions 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers. 92 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers. 93 | * This parameter can be one of the following values: 94 | * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers 95 | * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers 96 | * @retval None 97 | */ 98 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess) 99 | { 100 | /* Check the parameters */ 101 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess)); 102 | IWDG->KR = IWDG_WriteAccess; 103 | } 104 | 105 | /** 106 | * @brief Sets IWDG Prescaler value. 107 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value. 108 | * This parameter can be one of the following values: 109 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4 110 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8 111 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16 112 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32 113 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64 114 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128 115 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256 116 | * @retval None 117 | */ 118 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler) 119 | { 120 | /* Check the parameters */ 121 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler)); 122 | IWDG->PR = IWDG_Prescaler; 123 | } 124 | 125 | /** 126 | * @brief Sets IWDG Reload value. 127 | * @param Reload: specifies the IWDG Reload value. 128 | * This parameter must be a number between 0 and 0x0FFF. 129 | * @retval None 130 | */ 131 | void IWDG_SetReload(uint16_t Reload) 132 | { 133 | /* Check the parameters */ 134 | assert_param(IS_IWDG_RELOAD(Reload)); 135 | IWDG->RLR = Reload; 136 | } 137 | 138 | /** 139 | * @brief Reloads IWDG counter with value defined in the reload register 140 | * (write access to IWDG_PR and IWDG_RLR registers disabled). 141 | * @param None 142 | * @retval None 143 | */ 144 | void IWDG_ReloadCounter(void) 145 | { 146 | IWDG->KR = KR_KEY_Reload; 147 | } 148 | 149 | /** 150 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled). 151 | * @param None 152 | * @retval None 153 | */ 154 | void IWDG_Enable(void) 155 | { 156 | IWDG->KR = KR_KEY_Enable; 157 | } 158 | 159 | /** 160 | * @brief Checks whether the specified IWDG flag is set or not. 161 | * @param IWDG_FLAG: specifies the flag to check. 162 | * This parameter can be one of the following values: 163 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going 164 | * @arg IWDG_FLAG_RVU: Reload Value Update on going 165 | * @retval The new state of IWDG_FLAG (SET or RESET). 166 | */ 167 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG) 168 | { 169 | FlagStatus bitstatus = RESET; 170 | /* Check the parameters */ 171 | assert_param(IS_IWDG_FLAG(IWDG_FLAG)); 172 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET) 173 | { 174 | bitstatus = SET; 175 | } 176 | else 177 | { 178 | bitstatus = RESET; 179 | } 180 | /* Return the flag status */ 181 | return bitstatus; 182 | } 183 | 184 | /** 185 | * @} 186 | */ 187 | 188 | /** 189 | * @} 190 | */ 191 | 192 | /** 193 | * @} 194 | */ 195 | 196 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 197 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vdm-dev/stm32-ch340/50b50a5fb211a439dcc4fd32943b5d73395a037a/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the WWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_wwdg.h" 30 | #include "stm32f10x_rcc.h" 31 | 32 | /** @addtogroup STM32F10x_StdPeriph_Driver 33 | * @{ 34 | */ 35 | 36 | /** @defgroup WWDG 37 | * @brief WWDG driver modules 38 | * @{ 39 | */ 40 | 41 | /** @defgroup WWDG_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | /** @defgroup WWDG_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /* ----------- WWDG registers bit address in the alias region ----------- */ 54 | #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE) 55 | 56 | /* Alias word address of EWI bit */ 57 | #define CFR_OFFSET (WWDG_OFFSET + 0x04) 58 | #define EWI_BitNumber 0x09 59 | #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4)) 60 | 61 | /* --------------------- WWDG registers bit mask ------------------------ */ 62 | 63 | /* CR register bit mask */ 64 | #define CR_WDGA_Set ((uint32_t)0x00000080) 65 | 66 | /* CFR register bit mask */ 67 | #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F) 68 | #define CFR_W_Mask ((uint32_t)0xFFFFFF80) 69 | #define BIT_Mask ((uint8_t)0x7F) 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup WWDG_Private_Macros 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup WWDG_Private_Variables 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @defgroup WWDG_Private_FunctionPrototypes 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @defgroup WWDG_Private_Functions 100 | * @{ 101 | */ 102 | 103 | /** 104 | * @brief Deinitializes the WWDG peripheral registers to their default reset values. 105 | * @param None 106 | * @retval None 107 | */ 108 | void WWDG_DeInit(void) 109 | { 110 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE); 111 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE); 112 | } 113 | 114 | /** 115 | * @brief Sets the WWDG Prescaler. 116 | * @param WWDG_Prescaler: specifies the WWDG Prescaler. 117 | * This parameter can be one of the following values: 118 | * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1 119 | * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2 120 | * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4 121 | * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8 122 | * @retval None 123 | */ 124 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler) 125 | { 126 | uint32_t tmpreg = 0; 127 | /* Check the parameters */ 128 | assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler)); 129 | /* Clear WDGTB[1:0] bits */ 130 | tmpreg = WWDG->CFR & CFR_WDGTB_Mask; 131 | /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */ 132 | tmpreg |= WWDG_Prescaler; 133 | /* Store the new value */ 134 | WWDG->CFR = tmpreg; 135 | } 136 | 137 | /** 138 | * @brief Sets the WWDG window value. 139 | * @param WindowValue: specifies the window value to be compared to the downcounter. 140 | * This parameter value must be lower than 0x80. 141 | * @retval None 142 | */ 143 | void WWDG_SetWindowValue(uint8_t WindowValue) 144 | { 145 | __IO uint32_t tmpreg = 0; 146 | 147 | /* Check the parameters */ 148 | assert_param(IS_WWDG_WINDOW_VALUE(WindowValue)); 149 | /* Clear W[6:0] bits */ 150 | 151 | tmpreg = WWDG->CFR & CFR_W_Mask; 152 | 153 | /* Set W[6:0] bits according to WindowValue value */ 154 | tmpreg |= WindowValue & (uint32_t) BIT_Mask; 155 | 156 | /* Store the new value */ 157 | WWDG->CFR = tmpreg; 158 | } 159 | 160 | /** 161 | * @brief Enables the WWDG Early Wakeup interrupt(EWI). 162 | * @param None 163 | * @retval None 164 | */ 165 | void WWDG_EnableIT(void) 166 | { 167 | *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE; 168 | } 169 | 170 | /** 171 | * @brief Sets the WWDG counter value. 172 | * @param Counter: specifies the watchdog counter value. 173 | * This parameter must be a number between 0x40 and 0x7F. 174 | * @retval None 175 | */ 176 | void WWDG_SetCounter(uint8_t Counter) 177 | { 178 | /* Check the parameters */ 179 | assert_param(IS_WWDG_COUNTER(Counter)); 180 | /* Write to T[6:0] bits to configure the counter value, no need to do 181 | a read-modify-write; writing a 0 to WDGA bit does nothing */ 182 | WWDG->CR = Counter & BIT_Mask; 183 | } 184 | 185 | /** 186 | * @brief Enables WWDG and load the counter value. 187 | * @param Counter: specifies the watchdog counter value. 188 | * This parameter must be a number between 0x40 and 0x7F. 189 | * @retval None 190 | */ 191 | void WWDG_Enable(uint8_t Counter) 192 | { 193 | /* Check the parameters */ 194 | assert_param(IS_WWDG_COUNTER(Counter)); 195 | WWDG->CR = CR_WDGA_Set | Counter; 196 | } 197 | 198 | /** 199 | * @brief Checks whether the Early Wakeup interrupt flag is set or not. 200 | * @param None 201 | * @retval The new state of the Early Wakeup interrupt flag (SET or RESET) 202 | */ 203 | FlagStatus WWDG_GetFlagStatus(void) 204 | { 205 | return (FlagStatus)(WWDG->SR); 206 | } 207 | 208 | /** 209 | * @brief Clears Early Wakeup interrupt flag. 210 | * @param None 211 | * @retval None 212 | */ 213 | void WWDG_ClearFlag(void) 214 | { 215 | WWDG->SR = (uint32_t)RESET; 216 | } 217 | 218 | /** 219 | * @} 220 | */ 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | /** 227 | * @} 228 | */ 229 | 230 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 231 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_def.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Definitions related to USB Core 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_DEF_H 30 | #define __USB_DEF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported types ------------------------------------------------------------*/ 34 | typedef enum _RECIPIENT_TYPE 35 | { 36 | DEVICE_RECIPIENT, /* Recipient device */ 37 | INTERFACE_RECIPIENT, /* Recipient interface */ 38 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 39 | OTHER_RECIPIENT 40 | } RECIPIENT_TYPE; 41 | 42 | 43 | typedef enum _STANDARD_REQUESTS 44 | { 45 | GET_STATUS = 0, 46 | CLEAR_FEATURE, 47 | RESERVED1, 48 | SET_FEATURE, 49 | RESERVED2, 50 | SET_ADDRESS, 51 | GET_DESCRIPTOR, 52 | SET_DESCRIPTOR, 53 | GET_CONFIGURATION, 54 | SET_CONFIGURATION, 55 | GET_INTERFACE, 56 | SET_INTERFACE, 57 | TOTAL_sREQUEST, /* Total number of Standard request */ 58 | SYNCH_FRAME = 12 59 | } STANDARD_REQUESTS; 60 | 61 | /* Definition of "USBwValue" */ 62 | typedef enum _DESCRIPTOR_TYPE 63 | { 64 | DEVICE_DESCRIPTOR = 1, 65 | CONFIG_DESCRIPTOR, 66 | STRING_DESCRIPTOR, 67 | INTERFACE_DESCRIPTOR, 68 | ENDPOINT_DESCRIPTOR 69 | } DESCRIPTOR_TYPE; 70 | 71 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 72 | typedef enum _FEATURE_SELECTOR 73 | { 74 | ENDPOINT_STALL, 75 | DEVICE_REMOTE_WAKEUP 76 | } FEATURE_SELECTOR; 77 | 78 | /* Exported constants --------------------------------------------------------*/ 79 | /* Definition of "USBbmRequestType" */ 80 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 81 | #define STANDARD_REQUEST 0x00 /* Standard request */ 82 | #define CLASS_REQUEST 0x20 /* Class request */ 83 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 84 | 85 | #define RECIPIENT 0x1F /* Mask to get recipient */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions ------------------------------------------------------- */ 89 | 90 | #endif /* __USB_DEF_H */ 91 | 92 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 93 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INIT_H 31 | #define __USB_INIT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void USB_Init(void); 39 | 40 | /* External variables --------------------------------------------------------*/ 41 | /* The number of current endpoint, it will be used to specify an endpoint */ 42 | extern uint8_t EPindex; 43 | /* The number of current device, it is an index to the Device_Table */ 44 | /*extern uint8_t Device_no; */ 45 | /* Points to the DEVICE_INFO structure of current device */ 46 | /* The purpose of this register is to speed up the execution */ 47 | extern DEVICE_INFO* pInformation; 48 | /* Points to the DEVICE_PROP structure of current device */ 49 | /* The purpose of this register is to speed up the execution */ 50 | extern DEVICE_PROP* pProperty; 51 | /* Temporary save the state of Rx & Tx status. */ 52 | /* Whenever the Rx or Tx state is changed, its value is saved */ 53 | /* in this variable first and will be set to the EPRB or EPRA */ 54 | /* at the end of interrupt process */ 55 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 56 | 57 | extern uint16_t SaveState ; 58 | extern uint16_t wInterrupt_Mask; 59 | 60 | #endif /* __USB_INIT_H */ 61 | 62 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 63 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines prototypes 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INT_H 31 | #define __USB_INT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void CTR_LP(void); 39 | void CTR_HP(void); 40 | 41 | /* External variables --------------------------------------------------------*/ 42 | 43 | #endif /* __USB_INT_H */ 44 | 45 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_lib.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief USB library include files 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_LIB_H 31 | #define __USB_LIB_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "hw_config.h" 35 | #include "usb_type.h" 36 | #include "usb_regs.h" 37 | #include "usb_def.h" 38 | #include "usb_core.h" 39 | #include "usb_init.h" 40 | #include "usb_sil.h" 41 | #include "usb_mem.h" 42 | #include "usb_int.h" 43 | 44 | /* Exported types ------------------------------------------------------------*/ 45 | /* Exported constants --------------------------------------------------------*/ 46 | /* Exported macro ------------------------------------------------------------*/ 47 | /* Exported functions ------------------------------------------------------- */ 48 | /* External variables --------------------------------------------------------*/ 49 | 50 | #endif /* __USB_LIB_H */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility prototypes functions for memory/PMA transfers 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_MEM_H 31 | #define __USB_MEM_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 39 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 40 | 41 | /* External variables --------------------------------------------------------*/ 42 | 43 | #endif /*__USB_MEM_H*/ 44 | 45 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_sil.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer function prototypes. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_SIL_H 31 | #define __USB_SIL_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | 39 | uint32_t USB_SIL_Init(void); 40 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize); 41 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer); 42 | 43 | /* External variables --------------------------------------------------------*/ 44 | 45 | #endif /* __USB_SIL_H */ 46 | 47 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 48 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_type.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Type definitions used by the USB Library 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_TYPE_H 31 | #define __USB_TYPE_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usb_conf.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | #ifndef NULL 39 | #define NULL ((void *)0) 40 | #endif 41 | 42 | typedef enum 43 | { 44 | FALSE = 0, TRUE = !FALSE 45 | } 46 | bool; 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* Exported functions ------------------------------------------------------- */ 50 | /* External variables --------------------------------------------------------*/ 51 | 52 | #endif /* __USB_TYPE_H */ 53 | 54 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/src/usb_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* Private define ------------------------------------------------------------*/ 34 | /* Private macro -------------------------------------------------------------*/ 35 | /* Private variables ---------------------------------------------------------*/ 36 | /* The number of current endpoint, it will be used to specify an endpoint */ 37 | uint8_t EPindex; 38 | /* The number of current device, it is an index to the Device_Table */ 39 | /* uint8_t Device_no; */ 40 | /* Points to the DEVICE_INFO structure of current device */ 41 | /* The purpose of this register is to speed up the execution */ 42 | DEVICE_INFO *pInformation; 43 | /* Points to the DEVICE_PROP structure of current device */ 44 | /* The purpose of this register is to speed up the execution */ 45 | DEVICE_PROP *pProperty; 46 | /* Temporary save the state of Rx & Tx status. */ 47 | /* Whenever the Rx or Tx state is changed, its value is saved */ 48 | /* in this variable first and will be set to the EPRB or EPRA */ 49 | /* at the end of interrupt process */ 50 | uint16_t SaveState ; 51 | uint16_t wInterrupt_Mask; 52 | DEVICE_INFO Device_Info; 53 | USER_STANDARD_REQUESTS *pUser_Standard_Requests; 54 | 55 | /* Extern variables ----------------------------------------------------------*/ 56 | /* Private function prototypes -----------------------------------------------*/ 57 | /* Private functions ---------------------------------------------------------*/ 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_Init 61 | * Description : USB system initialization 62 | * Input : None. 63 | * Output : None. 64 | * Return : None. 65 | *******************************************************************************/ 66 | void USB_Init(void) 67 | { 68 | pInformation = &Device_Info; 69 | pInformation->ControlState = 2; 70 | pProperty = &Device_Property; 71 | pUser_Standard_Requests = &User_Standard_Requests; 72 | /* Initialize devices one by one */ 73 | pProperty->Init(); 74 | } 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/src/usb_int.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usb_lib.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | __IO uint16_t SaveRState; 36 | __IO uint16_t SaveTState; 37 | 38 | /* Extern variables ----------------------------------------------------------*/ 39 | extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */ 40 | extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */ 41 | 42 | /* Private function prototypes -----------------------------------------------*/ 43 | /* Private functions ---------------------------------------------------------*/ 44 | 45 | /******************************************************************************* 46 | * Function Name : CTR_LP. 47 | * Description : Low priority Endpoint Correct Transfer interrupt's service 48 | * routine. 49 | * Input : None. 50 | * Output : None. 51 | * Return : None. 52 | *******************************************************************************/ 53 | void CTR_LP(void) 54 | { 55 | __IO uint16_t wEPVal = 0; 56 | /* stay in loop while pending interrupts */ 57 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0) 58 | { 59 | /* extract highest priority endpoint number */ 60 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID); 61 | if (EPindex == 0) 62 | { 63 | /* Decode and service control endpoint interrupt */ 64 | /* calling related service routine */ 65 | /* (Setup0_Process, In0_Process, Out0_Process) */ 66 | 67 | /* save RX & TX status */ 68 | /* and set both to NAK */ 69 | 70 | SaveRState = _GetENDPOINT(ENDP0); 71 | SaveTState = SaveRState & EPTX_STAT; 72 | SaveRState &= EPRX_STAT; 73 | 74 | _SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK); 75 | 76 | /* DIR bit = origin of the interrupt */ 77 | 78 | if ((wIstr & ISTR_DIR) == 0) 79 | { 80 | /* DIR = 0 */ 81 | 82 | /* DIR = 0 => IN int */ 83 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ 84 | 85 | _ClearEP_CTR_TX(ENDP0); 86 | In0_Process(); 87 | 88 | /* before terminate set Tx & Rx status */ 89 | 90 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 91 | return; 92 | } 93 | else 94 | { 95 | /* DIR = 1 */ 96 | 97 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ 98 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ 99 | 100 | wEPVal = _GetENDPOINT(ENDP0); 101 | 102 | if ((wEPVal &EP_SETUP) != 0) 103 | { 104 | _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */ 105 | Setup0_Process(); 106 | /* before terminate set Tx & Rx status */ 107 | 108 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 109 | return; 110 | } 111 | 112 | else if ((wEPVal & EP_CTR_RX) != 0) 113 | { 114 | _ClearEP_CTR_RX(ENDP0); 115 | Out0_Process(); 116 | /* before terminate set Tx & Rx status */ 117 | 118 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 119 | return; 120 | } 121 | } 122 | }/* if(EPindex == 0) */ 123 | else 124 | { 125 | /* Decode and service non control endpoints interrupt */ 126 | 127 | /* process related endpoint register */ 128 | wEPVal = _GetENDPOINT(EPindex); 129 | if ((wEPVal & EP_CTR_RX) != 0) 130 | { 131 | /* clear int flag */ 132 | _ClearEP_CTR_RX(EPindex); 133 | 134 | /* call OUT service function */ 135 | (*pEpInt_OUT[EPindex-1])(); 136 | 137 | } /* if((wEPVal & EP_CTR_RX) */ 138 | 139 | if ((wEPVal & EP_CTR_TX) != 0) 140 | { 141 | /* clear int flag */ 142 | _ClearEP_CTR_TX(EPindex); 143 | 144 | /* call IN service function */ 145 | (*pEpInt_IN[EPindex-1])(); 146 | } /* if((wEPVal & EP_CTR_TX) != 0) */ 147 | 148 | }/* if(EPindex == 0) else */ 149 | 150 | }/* while(...) */ 151 | } 152 | 153 | /******************************************************************************* 154 | * Function Name : CTR_HP. 155 | * Description : High Priority Endpoint Correct Transfer interrupt's service 156 | * routine. 157 | * Input : None. 158 | * Output : None. 159 | * Return : None. 160 | *******************************************************************************/ 161 | void CTR_HP(void) 162 | { 163 | uint32_t wEPVal = 0; 164 | 165 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0) 166 | { 167 | _SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */ 168 | /* extract highest priority endpoint number */ 169 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID); 170 | /* process related endpoint register */ 171 | wEPVal = _GetENDPOINT(EPindex); 172 | if ((wEPVal & EP_CTR_RX) != 0) 173 | { 174 | /* clear int flag */ 175 | _ClearEP_CTR_RX(EPindex); 176 | 177 | /* call OUT service function */ 178 | (*pEpInt_OUT[EPindex-1])(); 179 | 180 | } /* if((wEPVal & EP_CTR_RX) */ 181 | else if ((wEPVal & EP_CTR_TX) != 0) 182 | { 183 | /* clear int flag */ 184 | _ClearEP_CTR_TX(EPindex); 185 | 186 | /* call IN service function */ 187 | (*pEpInt_IN[EPindex-1])(); 188 | 189 | 190 | } /* if((wEPVal & EP_CTR_TX) != 0) */ 191 | 192 | }/* while(...) */ 193 | } 194 | 195 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 196 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/src/usb_mem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility functions for memory transfers to/from PMA 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usb_lib.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | /* Extern variables ----------------------------------------------------------*/ 36 | /* Private function prototypes -----------------------------------------------*/ 37 | /* Private functions ---------------------------------------------------------*/ 38 | 39 | /******************************************************************************* 40 | * Function Name : UserToPMABufferCopy 41 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 42 | * Input : - pbUsrBuf: pointer to user memory area. 43 | * - wPMABufAddr: address into PMA. 44 | * - wNBytes: no. of bytes to be copied. 45 | * Output : None. 46 | * Return : None . 47 | *******************************************************************************/ 48 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 49 | { 50 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 51 | uint32_t i, temp1, temp2; 52 | uint16_t *pdwVal; 53 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); 54 | for (i = n; i != 0; i--) 55 | { 56 | temp1 = (uint16_t) * pbUsrBuf; 57 | pbUsrBuf++; 58 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; 59 | *pdwVal++ = temp2; 60 | pdwVal++; 61 | pbUsrBuf++; 62 | } 63 | } 64 | 65 | /******************************************************************************* 66 | * Function Name : PMAToUserBufferCopy 67 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 68 | * Input : - pbUsrBuf = pointer to user memory area. 69 | * - wPMABufAddr = address into PMA. 70 | * - wNBytes = no. of bytes to be copied. 71 | * Output : None. 72 | * Return : None. 73 | *******************************************************************************/ 74 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 75 | { 76 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ 77 | uint32_t i; 78 | uint32_t *pdwVal; 79 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); 80 | for (i = n; i != 0; i--) 81 | { 82 | *(uint16_t*)pbUsrBuf++ = *pdwVal++; 83 | pbUsrBuf++; 84 | } 85 | } 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/src/usb_sil.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer for Global Initialization and Endpoint 8 | * Rea/Write operations. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usb_lib.h" 32 | 33 | /* Private typedef -----------------------------------------------------------*/ 34 | /* Private define ------------------------------------------------------------*/ 35 | /* Private macro -------------------------------------------------------------*/ 36 | /* Private variables ---------------------------------------------------------*/ 37 | /* Extern variables ----------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /******************************************************************************* 42 | * Function Name : USB_SIL_Init 43 | * Description : Initialize the USB Device IP and the Endpoint 0. 44 | * Input : None. 45 | * Output : None. 46 | * Return : Status. 47 | *******************************************************************************/ 48 | uint32_t USB_SIL_Init(void) 49 | { 50 | /* USB interrupts initialization */ 51 | /* clear pending interrupts */ 52 | _SetISTR(0); 53 | wInterrupt_Mask = IMR_MSK; 54 | /* set interrupts mask */ 55 | _SetCNTR(wInterrupt_Mask); 56 | return 0; 57 | } 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_SIL_Write 61 | * Description : Write a buffer of data to a selected endpoint. 62 | * Input : - bEpAddr: The address of the non control endpoint. 63 | * - pBufferPointer: The pointer to the buffer of data to be written 64 | * to the endpoint. 65 | * - wBufferSize: Number of data to be written (in bytes). 66 | * Output : None. 67 | * Return : Status. 68 | *******************************************************************************/ 69 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize) 70 | { 71 | /* Use the memory interface function to write to the selected endpoint */ 72 | UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize); 73 | 74 | /* Update the data length in the control register */ 75 | SetEPTxCount((bEpAddr & 0x7F), wBufferSize); 76 | 77 | return 0; 78 | } 79 | 80 | /******************************************************************************* 81 | * Function Name : USB_SIL_Read 82 | * Description : Write a buffer of data to a selected endpoint. 83 | * Input : - bEpAddr: The address of the non control endpoint. 84 | * - pBufferPointer: The pointer to which will be saved the 85 | * received data buffer. 86 | * Output : None. 87 | * Return : Number of received data (in Bytes). 88 | *******************************************************************************/ 89 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer) 90 | { 91 | uint32_t DataLength = 0; 92 | 93 | /* Get the number of received data on the selected Endpoint */ 94 | DataLength = GetEPRxCount(bEpAddr & 0x7F); 95 | 96 | /* Use the memory interface function to write to the selected endpoint */ 97 | PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); 98 | 99 | /* Return the number of received data */ 100 | return DataLength; 101 | } 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM32 CH340 Imitation Firmware 2 | The firmware for STM32F103 microcontrollers that emulates CH340 IC (USB to UART interface) 3 | -------------------------------------------------------------------------------- /System/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vdm-dev/stm32-ch340/50b50a5fb211a439dcc4fd32943b5d73395a037a/System/stm32f10x.h -------------------------------------------------------------------------------- /System/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_CONF_H 31 | #define __STM32F10x_CONF_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Uncomment the line below to enable peripheral header file inclusion */ 35 | #include "stm32f10x_adc.h" 36 | #include "stm32f10x_bkp.h" 37 | #include "stm32f10x_can.h" 38 | #include "stm32f10x_crc.h" 39 | #include "stm32f10x_dac.h" 40 | #include "stm32f10x_dbgmcu.h" 41 | #include "stm32f10x_dma.h" 42 | #include "stm32f10x_exti.h" 43 | #include "stm32f10x_flash.h" 44 | #include "stm32f10x_fsmc.h" 45 | #include "stm32f10x_gpio.h" 46 | #include "stm32f10x_i2c.h" 47 | #include "stm32f10x_iwdg.h" 48 | #include "stm32f10x_pwr.h" 49 | #include "stm32f10x_rcc.h" 50 | #include "stm32f10x_rtc.h" 51 | #include "stm32f10x_sdio.h" 52 | #include "stm32f10x_spi.h" 53 | #include "stm32f10x_tim.h" 54 | #include "stm32f10x_usart.h" 55 | #include "stm32f10x_wwdg.h" 56 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 57 | 58 | /* Exported types ------------------------------------------------------------*/ 59 | /* Exported constants --------------------------------------------------------*/ 60 | /* Uncomment the line below to expanse the "assert_param" macro in the 61 | Standard Peripheral Library drivers code */ 62 | /* #define USE_FULL_ASSERT 1 */ 63 | 64 | /* Exported macro ------------------------------------------------------------*/ 65 | #ifdef USE_FULL_ASSERT 66 | 67 | /******************************************************************************* 68 | * Macro Name : assert_param 69 | * Description : The assert_param macro is used for function's parameters check. 70 | * Input : - expr: If expr is false, it calls assert_failed function 71 | * which reports the name of the source file and the source 72 | * line number of the call that failed. 73 | * If expr is true, it returns no value. 74 | * Return : None 75 | *******************************************************************************/ 76 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 77 | /* Exported functions ------------------------------------------------------- */ 78 | void assert_failed(uint8_t* file, uint32_t line); 79 | #else 80 | #define assert_param(expr) ((void)0) 81 | #endif /* USE_FULL_ASSERT */ 82 | 83 | #endif /* __STM32F10x_CONF_H */ 84 | 85 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 86 | -------------------------------------------------------------------------------- /System/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 09-March-2012 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f10x_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F10X_H 40 | #define __SYSTEM_STM32F10X_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F10x_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F10x_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @addtogroup STM32F10x_System_Exported_Constants 66 | * @{ 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @addtogroup STM32F10x_System_Exported_Macros 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @addtogroup STM32F10x_System_Exported_Functions 82 | * @{ 83 | */ 84 | 85 | extern void SystemInit(void); 86 | extern void SystemCoreClockUpdate(void); 87 | /** 88 | * @} 89 | */ 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /*__SYSTEM_STM32F10X_H */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /USB_Device/usb_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_conf.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Virtual COM Port Demo configuration header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_CONF_H 31 | #define __USB_CONF_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | /* External variables --------------------------------------------------------*/ 39 | 40 | /*-------------------------------------------------------------*/ 41 | /* EP_NUM */ 42 | /* defines how many endpoints are used by the device */ 43 | /*-------------------------------------------------------------*/ 44 | 45 | #define EP_NUM (4) 46 | 47 | /*-------------------------------------------------------------*/ 48 | /* -------------- Buffer Description Table -----------------*/ 49 | /*-------------------------------------------------------------*/ 50 | /* buffer table base address */ 51 | /* buffer table base address */ 52 | #define BTABLE_ADDRESS (0x00) 53 | 54 | /* EP0 */ 55 | /* rx/tx buffer base address */ 56 | #define ENDP0_RXADDR (0x40) 57 | #define ENDP0_TXADDR (0x80) 58 | 59 | /* EP1 */ 60 | /* tx buffer base address */ 61 | #define ENDP2_TXADDR (0xC0) 62 | #define ENDP2_RXADDR (0x100) 63 | #define ENDP1_TXADDR (0x110) 64 | 65 | 66 | /*-------------------------------------------------------------*/ 67 | /* ------------------- ISTR events -------------------------*/ 68 | /*-------------------------------------------------------------*/ 69 | /* IMR_MSK */ 70 | /* mask defining which events has to be handled */ 71 | /* by the device application software */ 72 | #define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \ 73 | | CNTR_ESOFM | CNTR_RESETM ) 74 | 75 | /*#define CTR_CALLBACK*/ 76 | /*#define DOVR_CALLBACK*/ 77 | /*#define ERR_CALLBACK*/ 78 | /*#define WKUP_CALLBACK*/ 79 | /*#define SUSP_CALLBACK*/ 80 | /*#define RESET_CALLBACK*/ 81 | #define SOF_CALLBACK 82 | /*#define ESOF_CALLBACK*/ 83 | /* CTR service routines */ 84 | /* associated to defined endpoints */ 85 | //#define EP1_IN_Callback NOP_Process 86 | //#define EP2_IN_Callback NOP_Process 87 | #define EP3_IN_Callback NOP_Process 88 | #define EP4_IN_Callback NOP_Process 89 | #define EP5_IN_Callback NOP_Process 90 | #define EP6_IN_Callback NOP_Process 91 | #define EP7_IN_Callback NOP_Process 92 | 93 | #define EP1_OUT_Callback NOP_Process 94 | //#define EP2_OUT_Callback NOP_Process 95 | #define EP3_OUT_Callback NOP_Process 96 | #define EP4_OUT_Callback NOP_Process 97 | #define EP5_OUT_Callback NOP_Process 98 | #define EP6_OUT_Callback NOP_Process 99 | #define EP7_OUT_Callback NOP_Process 100 | 101 | #endif /* __USB_CONF_H */ 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /USB_Device/usb_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Descriptors for Virtual Com Port Demo 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_desc.h" 32 | 33 | /* USB Standard Device Descriptor */ 34 | const uint8_t Virtual_Com_Port_DeviceDescriptor[] = 35 | { 36 | 0x12, /* bLength */ 37 | USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ 38 | 0x10, 39 | 0x01, /* bcdUSB = 1.1 */ 40 | 0xFF, /* bDeviceClass: Vendor */ 41 | 0x00, /* bDeviceSubClass */ 42 | 0x00, /* bDeviceProtocol */ 43 | 0x08, /* bMaxPacketSize0 = 8 */ 44 | 0x86, 45 | 0x1A, /* idVendor = 0x1A86 */ 46 | 0x23, 47 | 0x75, /* idProduct = 0x7523 */ 48 | 0x54, 49 | 0x02, /* bcdDevice = 2.54 */ 50 | 1, /* Index of string descriptor describing manufacturer */ 51 | 2, /* Index of string descriptor describing product */ 52 | 3, /* Index of string descriptor describing the device's serial number */ 53 | 0x01 /* bNumConfigurations */ 54 | }; 55 | 56 | const uint8_t Virtual_Com_Port_ConfigDescriptor[] = 57 | { 58 | /*Configuration Descriptor*/ 59 | 0x09, /* bLength: Configuration Descriptor size */ 60 | USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ 61 | VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, /* wTotalLength:no of returned bytes */ 62 | 0x00, 63 | 0x01, /* bNumInterfaces: 1 interface */ 64 | 0x01, /* bConfigurationValue: Configuration value */ 65 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 66 | 0x80, /* bmAttributes: self powered */ 67 | 0x32, /* MaxPower 100 mA */ 68 | /*Interface Descriptor*/ 69 | 0x09, /* bLength: Interface Descriptor size */ 70 | USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ 71 | /* Interface descriptor type */ 72 | 0x00, /* bInterfaceNumber: Number of Interface */ 73 | 0x00, /* bAlternateSetting: Alternate setting */ 74 | 0x03, /* bNumEndpoints: 3 endpoints used */ 75 | 0xFF, /* bInterfaceClass: Vendor Interface Class */ 76 | 0x01, /* bInterfaceSubClass */ 77 | 0x02, /* bInterfaceProtocol */ 78 | 0x00, /* iInterface: */ 79 | /* Endpoint 2 IN Descriptor*/ 80 | 0x07, /* bLength: Endpoint Descriptor size */ 81 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 82 | 0x82, /* bEndpointAddress: (IN2) */ 83 | 0x02, /* bmAttributes: Bulk */ 84 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 85 | 0x00, 86 | 0x00, /* bInterval: */ 87 | /* Endpoint 2 OUT Descriptor*/ 88 | 0x07, /* bLength: Endpoint Descriptor size */ 89 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 90 | 0x02, /* bEndpointAddress: (OUT2) */ 91 | 0x02, /* bmAttributes: Bulk */ 92 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 93 | 0x00, 94 | 0x00, /* bInterval: ignore for Bulk transfer */ 95 | /* Endpoint 1 IN Descriptor*/ 96 | 0x07, /* bLength: Endpoint Descriptor size */ 97 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 98 | 0x81, /* bEndpointAddress: (IN1) */ 99 | 0x03, /* bmAttributes: Interrupt */ 100 | VIRTUAL_COM_PORT_INT_SIZE, /* wMaxPacketSize: */ 101 | 0x00, 102 | 0x01 /* bInterval */ 103 | }; 104 | 105 | /* USB String Descriptors */ 106 | const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID] = 107 | { 108 | VIRTUAL_COM_PORT_SIZ_STRING_LANGID, 109 | USB_STRING_DESCRIPTOR_TYPE, 110 | 0x09, 111 | 0x04 /* LangID = 0x0409: U.S. English */ 112 | }; 113 | 114 | const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR] = 115 | { 116 | VIRTUAL_COM_PORT_SIZ_STRING_VENDOR, /* Size of Vendor string */ 117 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/ 118 | /* Manufacturer: "STMicroelectronics" */ 119 | 'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0, 120 | 'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0, 121 | 'c', 0, 's', 0 122 | }; 123 | 124 | const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT] = 125 | { 126 | VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT, /* bLength */ 127 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 128 | /* Product name: "STM32 Virtual COM Port" */ 129 | 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, ' ', 0, 'V', 0, 'i', 0, 130 | 'r', 0, 't', 0, 'u', 0, 'a', 0, 'l', 0, ' ', 0, 'C', 0, 'O', 0, 131 | 'M', 0, ' ', 0, 'P', 0, 'o', 0, 'r', 0, 't', 0, ' ', 0, ' ', 0 132 | }; 133 | 134 | uint8_t vcpStringSerial[VCP_STRING_SERIAL_SIZE] = 135 | { 136 | VCP_STRING_SERIAL_SIZE, // bLength 137 | USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType 138 | 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0 139 | }; 140 | -------------------------------------------------------------------------------- /USB_Device/usb_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Descriptor Header for Virtual COM Port Device 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_DESC_H 31 | #define __USB_DESC_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported define -----------------------------------------------------------*/ 38 | #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 39 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 40 | #define USB_STRING_DESCRIPTOR_TYPE 0x03 41 | #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 42 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 43 | 44 | #define VIRTUAL_COM_PORT_DATA_SIZE 32 45 | #define VIRTUAL_COM_PORT_INT_SIZE 8 46 | 47 | #define VIRTUAL_COM_PORT_SIZ_DEVICE_DESC 18 48 | #define VIRTUAL_COM_PORT_SIZ_CONFIG_DESC 39 49 | #define VIRTUAL_COM_PORT_SIZ_STRING_LANGID 4 50 | #define VIRTUAL_COM_PORT_SIZ_STRING_VENDOR 38 51 | #define VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT 50 52 | #define VCP_STRING_SERIAL_SIZE 26 53 | 54 | #define STANDARD_ENDPOINT_DESC_SIZE 0x09 55 | 56 | /* Exported functions ------------------------------------------------------- */ 57 | extern const uint8_t Virtual_Com_Port_DeviceDescriptor[VIRTUAL_COM_PORT_SIZ_DEVICE_DESC]; 58 | extern const uint8_t Virtual_Com_Port_ConfigDescriptor[VIRTUAL_COM_PORT_SIZ_CONFIG_DESC]; 59 | 60 | extern const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID]; 61 | extern const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR]; 62 | extern const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT]; 63 | extern uint8_t vcpStringSerial[VCP_STRING_SERIAL_SIZE]; 64 | 65 | #endif /* __USB_DESC_H */ 66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 67 | -------------------------------------------------------------------------------- /USB_Device/usb_endp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_endp.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Endpoint routines 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_desc.h" 32 | #include "usb_mem.h" 33 | #include "hw_config.h" 34 | #include "usb_istr.h" 35 | #include "usb_pwr.h" 36 | 37 | #include "stdio.h" 38 | 39 | /* Private typedef -----------------------------------------------------------*/ 40 | /* Private define ------------------------------------------------------------*/ 41 | 42 | /* Interval between sending IN packets in frame number (1 frame = 1ms) */ 43 | #define VCOMPORT_IN_FRAME_INTERVAL 5 44 | 45 | /* Private macro -------------------------------------------------------------*/ 46 | /* Private variables ---------------------------------------------------------*/ 47 | uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE]; 48 | extern uint8_t USART_Rx_Buffer[]; 49 | extern uint32_t USART_Rx_ptr_out; 50 | extern uint32_t USART_Rx_length; 51 | extern uint8_t USB_Tx_State; 52 | 53 | /* Private function prototypes -----------------------------------------------*/ 54 | /* Private functions ---------------------------------------------------------*/ 55 | 56 | /******************************************************************************* 57 | * Function Name : EP1_IN_Callback 58 | * Description : 59 | * Input : None. 60 | * Output : None. 61 | * Return : None. 62 | *******************************************************************************/ 63 | void EP2_IN_Callback (void) 64 | { 65 | uint16_t USB_Tx_ptr; 66 | uint16_t USB_Tx_length; 67 | 68 | // Do Callback 69 | printf("EP2_IN_Callback\r\n"); 70 | 71 | if (USB_Tx_State == 1) 72 | { 73 | if (USART_Rx_length == 0) 74 | { 75 | USB_Tx_State = 0; 76 | } 77 | else 78 | { 79 | if (USART_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE){ 80 | USB_Tx_ptr = USART_Rx_ptr_out; 81 | USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE; 82 | 83 | USART_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE; 84 | USART_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE; 85 | } 86 | else 87 | { 88 | USB_Tx_ptr = USART_Rx_ptr_out; 89 | USB_Tx_length = USART_Rx_length; 90 | 91 | USART_Rx_ptr_out += USART_Rx_length; 92 | USART_Rx_length = 0; 93 | } 94 | UserToPMABufferCopy(&USART_Rx_Buffer[USB_Tx_ptr], ENDP2_TXADDR, USB_Tx_length); 95 | SetEPTxCount(ENDP2, USB_Tx_length); 96 | SetEPTxValid(ENDP2); 97 | } 98 | } 99 | } 100 | 101 | /******************************************************************************* 102 | * Function Name : EP3_OUT_Callback 103 | * Description : 104 | * Input : None. 105 | * Output : None. 106 | * Return : None. 107 | *******************************************************************************/ 108 | void EP2_OUT_Callback(void) 109 | { 110 | uint16_t USB_Rx_Cnt; 111 | 112 | /* Get the received data buffer and update the counter */ 113 | USB_Rx_Cnt = USB_SIL_Read(EP2_OUT, USB_Rx_Buffer); 114 | 115 | printf("EP2_OUT_Callback, count: %u\r\n", USB_Rx_Cnt); 116 | 117 | 118 | /* USB data will be immediately processed, this allow next USB traffic being 119 | NAKed till the end of the USART Xfer */ 120 | 121 | USB_To_USART_Send_Data(USB_Rx_Buffer, USB_Rx_Cnt); 122 | 123 | /* Enable the receive of data on EP3 */ 124 | SetEPRxValid(ENDP2); 125 | } 126 | 127 | void EP1_IN_Callback(void) 128 | { 129 | printf("EP1_IN_Callback\r\n"); 130 | } 131 | 132 | 133 | /******************************************************************************* 134 | * Function Name : SOF_Callback / INTR_SOFINTR_Callback 135 | * Description : 136 | * Input : None. 137 | * Output : None. 138 | * Return : None. 139 | *******************************************************************************/ 140 | void SOF_Callback(void) 141 | { 142 | static uint32_t FrameCount = 0; 143 | 144 | if(bDeviceState == CONFIGURED) 145 | { 146 | if (FrameCount++ == VCOMPORT_IN_FRAME_INTERVAL) 147 | { 148 | /* Reset the frame counter */ 149 | FrameCount = 0; 150 | 151 | /* Check the data to be sent through IN pipe */ 152 | Handle_USBAsynchXfer(); 153 | } 154 | } 155 | } 156 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 157 | 158 | -------------------------------------------------------------------------------- /USB_Device/usb_istr.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief ISTR events interrupt service routines 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_prop.h" 32 | #include "usb_pwr.h" 33 | #include "usb_istr.h" 34 | 35 | /* Private typedef -----------------------------------------------------------*/ 36 | /* Private define ------------------------------------------------------------*/ 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* Private variables ---------------------------------------------------------*/ 39 | __IO uint16_t wIstr; /* ISTR register last read value */ 40 | __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */ 41 | __IO uint32_t esof_counter =0; /* expected SOF counter */ 42 | __IO uint32_t wCNTR=0; 43 | 44 | /* Extern variables ----------------------------------------------------------*/ 45 | /* Private function prototypes -----------------------------------------------*/ 46 | /* Private functions ---------------------------------------------------------*/ 47 | /* function pointers to non-control endpoints service routines */ 48 | void (*pEpInt_IN[7])(void) = 49 | { 50 | EP1_IN_Callback, 51 | EP2_IN_Callback, 52 | EP3_IN_Callback, 53 | EP4_IN_Callback, 54 | EP5_IN_Callback, 55 | EP6_IN_Callback, 56 | EP7_IN_Callback, 57 | }; 58 | 59 | void (*pEpInt_OUT[7])(void) = 60 | { 61 | EP1_OUT_Callback, 62 | EP2_OUT_Callback, 63 | EP3_OUT_Callback, 64 | EP4_OUT_Callback, 65 | EP5_OUT_Callback, 66 | EP6_OUT_Callback, 67 | EP7_OUT_Callback, 68 | }; 69 | 70 | /******************************************************************************* 71 | * Function Name : USB_Istr 72 | * Description : ISTR events interrupt service routine 73 | * Input : None. 74 | * Output : None. 75 | * Return : None. 76 | *******************************************************************************/ 77 | void USB_Istr(void) 78 | { 79 | uint32_t i=0; 80 | __IO uint32_t EP[8]; 81 | 82 | wIstr = _GetISTR(); 83 | 84 | #if (IMR_MSK & ISTR_SOF) 85 | if (wIstr & ISTR_SOF & wInterrupt_Mask) 86 | { 87 | _SetISTR((uint16_t)CLR_SOF); 88 | bIntPackSOF++; 89 | 90 | #ifdef SOF_CALLBACK 91 | SOF_Callback(); 92 | #endif 93 | } 94 | #endif 95 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 96 | 97 | #if (IMR_MSK & ISTR_CTR) 98 | if (wIstr & ISTR_CTR & wInterrupt_Mask) 99 | { 100 | /* servicing of the endpoint correct transfer interrupt */ 101 | /* clear of the CTR flag into the sub */ 102 | CTR_LP(); 103 | #ifdef CTR_CALLBACK 104 | CTR_Callback(); 105 | #endif 106 | } 107 | #endif 108 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 109 | #if (IMR_MSK & ISTR_RESET) 110 | if (wIstr & ISTR_RESET & wInterrupt_Mask) 111 | { 112 | _SetISTR((uint16_t)CLR_RESET); 113 | Device_Property.Reset(); 114 | #ifdef RESET_CALLBACK 115 | RESET_Callback(); 116 | #endif 117 | } 118 | #endif 119 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 120 | #if (IMR_MSK & ISTR_DOVR) 121 | if (wIstr & ISTR_DOVR & wInterrupt_Mask) 122 | { 123 | _SetISTR((uint16_t)CLR_DOVR); 124 | #ifdef DOVR_CALLBACK 125 | DOVR_Callback(); 126 | #endif 127 | } 128 | #endif 129 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 130 | #if (IMR_MSK & ISTR_ERR) 131 | if (wIstr & ISTR_ERR & wInterrupt_Mask) 132 | { 133 | _SetISTR((uint16_t)CLR_ERR); 134 | #ifdef ERR_CALLBACK 135 | ERR_Callback(); 136 | #endif 137 | } 138 | #endif 139 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 140 | #if (IMR_MSK & ISTR_WKUP) 141 | if (wIstr & ISTR_WKUP & wInterrupt_Mask) 142 | { 143 | _SetISTR((uint16_t)CLR_WKUP); 144 | Resume(RESUME_EXTERNAL); 145 | #ifdef WKUP_CALLBACK 146 | WKUP_Callback(); 147 | #endif 148 | } 149 | #endif 150 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 151 | #if (IMR_MSK & ISTR_SUSP) 152 | if (wIstr & ISTR_SUSP & wInterrupt_Mask) 153 | { 154 | 155 | /* check if SUSPEND is possible */ 156 | if (fSuspendEnabled) 157 | { 158 | Suspend(); 159 | } 160 | else 161 | { 162 | /* if not possible then resume after xx ms */ 163 | Resume(RESUME_LATER); 164 | } 165 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ 166 | _SetISTR((uint16_t)CLR_SUSP); 167 | #ifdef SUSP_CALLBACK 168 | SUSP_Callback(); 169 | #endif 170 | } 171 | #endif 172 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 173 | 174 | #if (IMR_MSK & ISTR_ESOF) 175 | if (wIstr & ISTR_ESOF & wInterrupt_Mask) 176 | { 177 | /* clear ESOF flag in ISTR */ 178 | _SetISTR((uint16_t)CLR_ESOF); 179 | 180 | if ((_GetFNR()&FNR_RXDP)!=0) 181 | { 182 | /* increment ESOF counter */ 183 | esof_counter ++; 184 | 185 | /* test if we enter in ESOF more than 3 times with FSUSP =0 and RXDP =1=>> possible missing SUSP flag*/ 186 | if ((esof_counter >3)&&((_GetCNTR()&CNTR_FSUSP)==0)) 187 | { 188 | /* this a sequence to apply a force RESET*/ 189 | 190 | /*Store CNTR value */ 191 | wCNTR = _GetCNTR(); 192 | 193 | /*Store endpoints registers status */ 194 | for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i); 195 | 196 | /*apply FRES */ 197 | wCNTR|=CNTR_FRES; 198 | _SetCNTR(wCNTR); 199 | 200 | /*clear FRES*/ 201 | wCNTR&=~CNTR_FRES; 202 | _SetCNTR(wCNTR); 203 | 204 | /*poll for RESET flag in ISTR*/ 205 | while((_GetISTR()&ISTR_RESET) == 0); 206 | 207 | /* clear RESET flag in ISTR */ 208 | _SetISTR((uint16_t)CLR_RESET); 209 | 210 | /*restore Enpoints*/ 211 | for (i=0;i<8;i++) 212 | _SetENDPOINT(i, EP[i]); 213 | 214 | esof_counter = 0; 215 | } 216 | } 217 | else 218 | { 219 | esof_counter = 0; 220 | } 221 | 222 | /* resume handling timing is made with ESOFs */ 223 | Resume(RESUME_ESOF); /* request without change of the machine state */ 224 | 225 | #ifdef ESOF_CALLBACK 226 | ESOF_Callback(); 227 | #endif 228 | } 229 | #endif 230 | } /* USB_Istr */ 231 | 232 | 233 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 234 | -------------------------------------------------------------------------------- /USB_Device/usb_istr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief This file includes the peripherals header files in the user application. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_ISTR_H 31 | #define __USB_ISTR_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usb_conf.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | /* Exported macro ------------------------------------------------------------*/ 39 | /* Exported functions ------------------------------------------------------- */ 40 | 41 | void USB_Istr(void); 42 | 43 | /* function prototypes Automatically built defining related macros */ 44 | 45 | void EP1_IN_Callback(void); 46 | void EP2_IN_Callback(void); 47 | void EP3_IN_Callback(void); 48 | void EP4_IN_Callback(void); 49 | void EP5_IN_Callback(void); 50 | void EP6_IN_Callback(void); 51 | void EP7_IN_Callback(void); 52 | 53 | void EP1_OUT_Callback(void); 54 | void EP2_OUT_Callback(void); 55 | void EP3_OUT_Callback(void); 56 | void EP4_OUT_Callback(void); 57 | void EP5_OUT_Callback(void); 58 | void EP6_OUT_Callback(void); 59 | void EP7_OUT_Callback(void); 60 | 61 | #ifdef CTR_CALLBACK 62 | void CTR_Callback(void); 63 | #endif 64 | 65 | #ifdef DOVR_CALLBACK 66 | void DOVR_Callback(void); 67 | #endif 68 | 69 | #ifdef ERR_CALLBACK 70 | void ERR_Callback(void); 71 | #endif 72 | 73 | #ifdef WKUP_CALLBACK 74 | void WKUP_Callback(void); 75 | #endif 76 | 77 | #ifdef SUSP_CALLBACK 78 | void SUSP_Callback(void); 79 | #endif 80 | 81 | #ifdef RESET_CALLBACK 82 | void RESET_Callback(void); 83 | #endif 84 | 85 | #ifdef SOF_CALLBACK 86 | void SOF_Callback(void); 87 | #endif 88 | 89 | #ifdef ESOF_CALLBACK 90 | void ESOF_Callback(void); 91 | #endif 92 | #endif /*__USB_ISTR_H*/ 93 | 94 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /USB_Device/usb_prop.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_prop.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief All processing related to Virtual COM Port Demo (Endpoint 0) 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __usb_prop_H 31 | #define __usb_prop_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | typedef struct 36 | { 37 | uint32_t bitrate; 38 | uint8_t format; 39 | uint8_t paritytype; 40 | uint8_t datatype; 41 | }LINE_CODING; 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* Exported define -----------------------------------------------------------*/ 46 | 47 | #define Virtual_Com_Port_GetConfiguration NOP_Process 48 | //#define Virtual_Com_Port_SetConfiguration NOP_Process 49 | #define Virtual_Com_Port_GetInterface NOP_Process 50 | #define Virtual_Com_Port_SetInterface NOP_Process 51 | #define Virtual_Com_Port_GetStatus NOP_Process 52 | #define Virtual_Com_Port_ClearFeature NOP_Process 53 | #define Virtual_Com_Port_SetEndPointFeature NOP_Process 54 | #define Virtual_Com_Port_SetDeviceFeature NOP_Process 55 | //#define Virtual_Com_Port_SetDeviceAddress NOP_Process 56 | 57 | #define SEND_ENCAPSULATED_COMMAND 0x00 58 | #define GET_ENCAPSULATED_RESPONSE 0x01 59 | #define SET_COMM_FEATURE 0x02 60 | #define GET_COMM_FEATURE 0x03 61 | #define CLEAR_COMM_FEATURE 0x04 62 | #define SET_LINE_CODING 0x20 63 | #define GET_LINE_CODING 0x21 64 | #define SET_CONTROL_LINE_STATE 0x22 65 | #define SEND_BREAK 0x23 66 | 67 | /* Exported functions ------------------------------------------------------- */ 68 | void vcpInit(void); 69 | void vcpReset(void); 70 | void Virtual_Com_Port_SetConfiguration(void); 71 | void Virtual_Com_Port_SetDeviceAddress (void); 72 | void Virtual_Com_Port_Status_In (void); 73 | void Virtual_Com_Port_Status_Out (void); 74 | RESULT Virtual_Com_Port_Data_Setup(uint8_t); 75 | RESULT Virtual_Com_Port_NoData_Setup(uint8_t); 76 | RESULT Virtual_Com_Port_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting); 77 | uint8_t *Virtual_Com_Port_GetDeviceDescriptor(uint16_t ); 78 | uint8_t *Virtual_Com_Port_GetConfigDescriptor(uint16_t); 79 | uint8_t *Virtual_Com_Port_GetStringDescriptor(uint16_t); 80 | 81 | uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length); 82 | uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length); 83 | 84 | #endif /* __usb_prop_H */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | 88 | -------------------------------------------------------------------------------- /USB_Device/usb_pwr.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Connection/disconnection & power management 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_conf.h" 32 | #include "usb_pwr.h" 33 | #include "hw_config.h" 34 | 35 | /* Private typedef -----------------------------------------------------------*/ 36 | /* Private define ------------------------------------------------------------*/ 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* Private variables ---------------------------------------------------------*/ 39 | __IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */ 40 | __IO bool fSuspendEnabled = TRUE; /* true when suspend is possible */ 41 | __IO uint32_t EP[8]; 42 | 43 | struct 44 | { 45 | __IO RESUME_STATE eState; 46 | __IO uint8_t bESOFcnt; 47 | } 48 | ResumeS; 49 | 50 | __IO uint32_t remotewakeupon=0; 51 | 52 | 53 | RESULT PowerOn(void) 54 | { 55 | uint16_t wRegVal; 56 | 57 | configureUsbCable(ENABLE); 58 | 59 | /*** CNTR_PWDN = 0 ***/ 60 | wRegVal = CNTR_FRES; 61 | _SetCNTR(wRegVal); 62 | 63 | /*** CNTR_FRES = 0 ***/ 64 | wInterrupt_Mask = 0; 65 | _SetCNTR(wInterrupt_Mask); 66 | /*** Clear pending interrupts ***/ 67 | _SetISTR(0); 68 | /*** Set interrupt mask ***/ 69 | wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM; 70 | _SetCNTR(wInterrupt_Mask); 71 | 72 | return USB_SUCCESS; 73 | } 74 | 75 | RESULT PowerOff() 76 | { 77 | /* disable all interrupts and force USB reset */ 78 | _SetCNTR(CNTR_FRES); 79 | /* clear interrupt status register */ 80 | _SetISTR(0); 81 | /* Disable the Pull-Up*/ 82 | configureUsbCable(DISABLE); 83 | /* switch-off device */ 84 | _SetCNTR(CNTR_FRES + CNTR_PDWN); 85 | /* sw variables reset */ 86 | /* ... */ 87 | 88 | return USB_SUCCESS; 89 | } 90 | 91 | /******************************************************************************* 92 | * Function Name : Suspend 93 | * Description : sets suspend mode operating conditions 94 | * Input : None. 95 | * Output : None. 96 | * Return : USB_SUCCESS. 97 | *******************************************************************************/ 98 | void Suspend(void) 99 | { 100 | uint32_t i =0; 101 | uint16_t wCNTR; 102 | uint32_t tmpreg = 0; 103 | __IO uint32_t savePWR_CR=0; 104 | /* suspend preparation */ 105 | /* ... */ 106 | 107 | /*Store CNTR value */ 108 | wCNTR = _GetCNTR(); 109 | 110 | /* This a sequence to apply a force RESET to handle a robustness case */ 111 | 112 | /*Store endpoints registers status */ 113 | for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i); 114 | 115 | /* unmask RESET flag */ 116 | wCNTR|=CNTR_RESETM; 117 | _SetCNTR(wCNTR); 118 | 119 | /*apply FRES */ 120 | wCNTR|=CNTR_FRES; 121 | _SetCNTR(wCNTR); 122 | 123 | /*clear FRES*/ 124 | wCNTR&=~CNTR_FRES; 125 | _SetCNTR(wCNTR); 126 | 127 | /*poll for RESET flag in ISTR*/ 128 | while((_GetISTR()&ISTR_RESET) == 0); 129 | 130 | /* clear RESET flag in ISTR */ 131 | _SetISTR((uint16_t)CLR_RESET); 132 | 133 | /*restore Enpoints*/ 134 | for (i=0;i<8;i++) 135 | _SetENDPOINT(i, EP[i]); 136 | 137 | /* Now it is safe to enter macrocell in suspend mode */ 138 | wCNTR |= CNTR_FSUSP; 139 | _SetCNTR(wCNTR); 140 | 141 | /* force low-power mode in the macrocell */ 142 | wCNTR = _GetCNTR(); 143 | wCNTR |= CNTR_LPMODE; 144 | _SetCNTR(wCNTR); 145 | 146 | /*prepare entry in low power mode (STOP mode)*/ 147 | /* Select the regulator state in STOP mode*/ 148 | savePWR_CR = PWR->CR; 149 | tmpreg = PWR->CR; 150 | /* Clear PDDS and LPDS bits */ 151 | tmpreg &= ((uint32_t)0xFFFFFFFC); 152 | /* Set LPDS bit according to PWR_Regulator value */ 153 | tmpreg |= PWR_Regulator_LowPower; 154 | /* Store the new value */ 155 | PWR->CR = tmpreg; 156 | /* Set SLEEPDEEP bit of Cortex System Control Register */ 157 | #if defined (STM32F30X) || defined (STM32F37X) 158 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; 159 | #else 160 | SCB->SCR |= SCB_SCR_SLEEPDEEP; 161 | #endif 162 | 163 | /* enter system in STOP mode, only when wakeup flag in not set */ 164 | if((_GetISTR()&ISTR_WKUP)==0) 165 | { 166 | __WFI(); 167 | /* Reset SLEEPDEEP bit of Cortex System Control Register */ 168 | #if defined (STM32F30X) || defined (STM32F37X) 169 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); 170 | #else 171 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP); 172 | #endif 173 | } 174 | else 175 | { 176 | /* Clear Wakeup flag */ 177 | _SetISTR(CLR_WKUP); 178 | /* clear FSUSP to abort entry in suspend mode */ 179 | wCNTR = _GetCNTR(); 180 | wCNTR&=~CNTR_FSUSP; 181 | _SetCNTR(wCNTR); 182 | 183 | /*restore sleep mode configuration */ 184 | /* restore Power regulator config in sleep mode*/ 185 | PWR->CR = savePWR_CR; 186 | 187 | /* Reset SLEEPDEEP bit of Cortex System Control Register */ 188 | #if defined (STM32F30X) || defined (STM32F37X) 189 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); 190 | #else 191 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP); 192 | #endif 193 | } 194 | } 195 | 196 | /******************************************************************************* 197 | * Function Name : Resume_Init 198 | * Description : Handles wake-up restoring normal operations 199 | * Input : None. 200 | * Output : None. 201 | * Return : USB_SUCCESS. 202 | *******************************************************************************/ 203 | void Resume_Init(void) 204 | { 205 | uint16_t wCNTR; 206 | 207 | /* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */ 208 | /* restart the clocks */ 209 | /* ... */ 210 | 211 | /* CNTR_LPMODE = 0 */ 212 | wCNTR = _GetCNTR(); 213 | wCNTR &= (~CNTR_LPMODE); 214 | _SetCNTR(wCNTR); 215 | 216 | /* restore full power */ 217 | /* ... on connected devices */ 218 | Leave_LowPowerMode(); 219 | 220 | /* reset FSUSP bit */ 221 | _SetCNTR(IMR_MSK); 222 | 223 | /* reverse suspend preparation */ 224 | /* ... */ 225 | 226 | } 227 | 228 | /******************************************************************************* 229 | * Function Name : Resume 230 | * Description : This is the state machine handling resume operations and 231 | * timing sequence. The control is based on the Resume structure 232 | * variables and on the ESOF interrupt calling this subroutine 233 | * without changing machine state. 234 | * Input : a state machine value (RESUME_STATE) 235 | * RESUME_ESOF doesn't change ResumeS.eState allowing 236 | * decrementing of the ESOF counter in different states. 237 | * Output : None. 238 | * Return : None. 239 | *******************************************************************************/ 240 | void Resume(RESUME_STATE eResumeSetVal) 241 | { 242 | uint16_t wCNTR; 243 | 244 | if (eResumeSetVal != RESUME_ESOF) 245 | ResumeS.eState = eResumeSetVal; 246 | switch (ResumeS.eState) 247 | { 248 | case RESUME_EXTERNAL: 249 | if (remotewakeupon ==0) 250 | { 251 | Resume_Init(); 252 | ResumeS.eState = RESUME_OFF; 253 | } 254 | else /* RESUME detected during the RemoteWAkeup signalling => keep RemoteWakeup handling*/ 255 | { 256 | ResumeS.eState = RESUME_ON; 257 | } 258 | break; 259 | case RESUME_INTERNAL: 260 | Resume_Init(); 261 | ResumeS.eState = RESUME_START; 262 | remotewakeupon = 1; 263 | break; 264 | case RESUME_LATER: 265 | ResumeS.bESOFcnt = 2; 266 | ResumeS.eState = RESUME_WAIT; 267 | break; 268 | case RESUME_WAIT: 269 | ResumeS.bESOFcnt--; 270 | if (ResumeS.bESOFcnt == 0) 271 | ResumeS.eState = RESUME_START; 272 | break; 273 | case RESUME_START: 274 | wCNTR = _GetCNTR(); 275 | wCNTR |= CNTR_RESUME; 276 | _SetCNTR(wCNTR); 277 | ResumeS.eState = RESUME_ON; 278 | ResumeS.bESOFcnt = 10; 279 | break; 280 | case RESUME_ON: 281 | ResumeS.bESOFcnt--; 282 | if (ResumeS.bESOFcnt == 0) 283 | { 284 | wCNTR = _GetCNTR(); 285 | wCNTR &= (~CNTR_RESUME); 286 | _SetCNTR(wCNTR); 287 | ResumeS.eState = RESUME_OFF; 288 | remotewakeupon = 0; 289 | } 290 | break; 291 | case RESUME_OFF: 292 | case RESUME_ESOF: 293 | default: 294 | ResumeS.eState = RESUME_OFF; 295 | break; 296 | } 297 | } 298 | 299 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 300 | -------------------------------------------------------------------------------- /USB_Device/usb_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Connection/disconnection & power management header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_PWR_H 31 | #define __USB_PWR_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | typedef enum _RESUME_STATE 36 | { 37 | RESUME_EXTERNAL, 38 | RESUME_INTERNAL, 39 | RESUME_LATER, 40 | RESUME_WAIT, 41 | RESUME_START, 42 | RESUME_ON, 43 | RESUME_OFF, 44 | RESUME_ESOF 45 | } RESUME_STATE; 46 | 47 | typedef enum _DEVICE_STATE 48 | { 49 | UNCONNECTED, 50 | ATTACHED, 51 | POWERED, 52 | SUSPENDED, 53 | ADDRESSED, 54 | CONFIGURED 55 | } DEVICE_STATE; 56 | 57 | /* Exported constants --------------------------------------------------------*/ 58 | /* Exported macro ------------------------------------------------------------*/ 59 | /* Exported functions ------------------------------------------------------- */ 60 | void Suspend(void); 61 | void Resume_Init(void); 62 | void Resume(RESUME_STATE eResumeSetVal); 63 | 64 | RESULT PowerOn(void); 65 | RESULT PowerOff(void); 66 | 67 | /* External variables --------------------------------------------------------*/ 68 | extern __IO uint32_t bDeviceState; /* USB device status */ 69 | extern __IO bool fSuspendEnabled; /* true when suspend is possible */ 70 | 71 | #endif /*__USB_PWR_H*/ 72 | 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 74 | -------------------------------------------------------------------------------- /hw_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hw_config.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Hardware Configuration & Setup 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | #ifndef __HW_CONFIG_H 30 | #define __HW_CONFIG_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "platform_config.h" 34 | #include "usb_type.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | /* Exported macro ------------------------------------------------------------*/ 39 | /* Exported define -----------------------------------------------------------*/ 40 | #define MASS_MEMORY_START 0x04002000 41 | #define BULK_MAX_PACKET_SIZE 0x00000040 42 | #define LED_ON 0xF0 43 | #define LED_OFF 0xFF 44 | 45 | #define USART_RX_DATA_SIZE 2048 46 | /* Exported functions ------------------------------------------------------- */ 47 | void configureUsbSystem(void); 48 | void Enter_LowPowerMode(void); 49 | void Leave_LowPowerMode(void); 50 | void configureUsbInterrupts(void); 51 | void configureUsbCable(FunctionalState state); 52 | void setUsartDefaultSettings(void); 53 | bool USART_Config(void); 54 | void USB_To_USART_Send_Data(uint8_t* data_buffer, uint8_t Nb_bytes); 55 | void USART_To_USB_Send_Data(void); 56 | void Handle_USBAsynchXfer (void); 57 | void fillSerialNumber(void); 58 | 59 | /* External variables --------------------------------------------------------*/ 60 | 61 | #endif /*__HW_CONFIG_H*/ 62 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 63 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 Dmitry Lavygin (vdm.inbox@gmail.com) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | 24 | #include "hw_config.h" 25 | #include "usb_lib.h" 26 | #include "usb_desc.h" 27 | #include "usb_pwr.h" 28 | 29 | 30 | int main(void) 31 | { 32 | configureUsbSystem(); 33 | configureUsbInterrupts(); 34 | 35 | USB_Init(); 36 | 37 | while (1) 38 | { 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /platform_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file platform_config.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Evaluation board specific configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __PLATFORM_CONFIG_H 31 | #define __PLATFORM_CONFIG_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS) 35 | #include "stm32l1xx.h" 36 | #if defined (USE_STM32L152_EVAL) 37 | #include "stm32l152_eval.h" 38 | #elif defined (USE_STM32L152D_EVAL) 39 | #include "stm32l152d_eval.h" 40 | #else 41 | #error "Missing define: USE_STM32L152_EVAL or USE_STM32L152D_EVAL" 42 | #endif /* USE_STM32L152_EVAL */ 43 | #elif defined (STM32F10X_MD) || defined (STM32F10X_HD) || defined (STM32F10X_XL) 44 | #include "stm32f10x.h" 45 | #if defined (USE_STM3210B_EVAL) 46 | #include "stm3210b_eval.h" 47 | #elif defined (USE_STM3210E_EVAL) 48 | #include "stm3210e_eval.h" 49 | //#else 50 | //#error "Missing define: USE_STM3210B_EVAL or USE_STM3210E_EVAL" 51 | #endif /* USE_STM3210B_EVAL */ 52 | #elif defined (USE_STM32373C_EVAL) 53 | #include "stm32f37x.h" 54 | #include "stm32373c_eval.h" 55 | #elif defined (USE_STM32303C_EVAL) 56 | #include "stm32f30x.h" 57 | #include "stm32303c_eval.h" 58 | #endif 59 | 60 | /* Exported types ------------------------------------------------------------*/ 61 | /* Exported constants --------------------------------------------------------*/ 62 | /* Uncomment the line corresponding to the STMicroelectronics evaluation board 63 | used to run the example */ 64 | #if !defined (USE_STM3210B_EVAL) && !defined (USE_STM3210E_EVAL) && !defined (USE_STM32L152_EVAL) && !defined (USE_STM32L152D_EVAL) && !defined (USE_STM32373C_EVAL) && !defined (USE_STM32303C_EVAL) 65 | //#define USE_STM3210B_EVAL 66 | //#define USE_STM3210E_EVAL 67 | //#define USE_STM32L152_EVAL 68 | //#define USE_STM32L152D_EVAL 69 | //#define (USE_STM32373C_EVAL) 70 | //#define (USE_STM32303C_EVAL) 71 | #define USE_STM32_NO_EVAL 72 | #endif 73 | 74 | /*Unique Devices IDs register set*/ 75 | 76 | #if defined(STM32L1XX_MD) || defined(STM32L1XX_HD) || defined(STM32L1XX_MD_PLUS) 77 | 78 | #define ID1 (0x1FF80050) 79 | #define ID2 (0x1FF80054) 80 | #define ID3 (0x1FF80064) 81 | 82 | #elif defined (STM32F37X) || defined(STM32F30X) 83 | 84 | #define ID1 (0x1FFFF7AC) 85 | #define ID2 (0x1FFFF7B0) 86 | #define ID3 (0x1FFFF7B4) 87 | 88 | #else /*STM32F1x*/ 89 | 90 | #define ID1 (0x1FFFF7E8) 91 | #define ID2 (0x1FFFF7EC) 92 | #define ID3 (0x1FFFF7F0) 93 | 94 | #endif 95 | 96 | /* Define the STM32F10x hardware depending on the used evaluation board */ 97 | #ifdef USE_STM32_NO_EVAL 98 | #define EVAL_COM1_IRQHandler USART1_IRQHandler 99 | #define EVAL_COM1 USART1 100 | #define EVAL_COM1_CLK RCC_APB2Periph_USART1 101 | #define EVAL_COM1_TX_PIN GPIO_Pin_9 102 | #define EVAL_COM1_TX_GPIO_PORT GPIOA 103 | #define EVAL_COM1_TX_GPIO_CLK RCC_APB2Periph_GPIOA 104 | #define EVAL_COM1_RX_PIN GPIO_Pin_10 105 | #define EVAL_COM1_RX_GPIO_PORT GPIOA 106 | #define EVAL_COM1_RX_GPIO_CLK RCC_APB2Periph_GPIOA 107 | #define EVAL_COM1_IRQn USART1_IRQn 108 | #elif defined(USE_STM3210B_EVAL) 109 | #define USB_DISCONNECT GPIOD 110 | #define USB_DISCONNECT_PIN GPIO_Pin_9 111 | #define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOD 112 | #define EVAL_COM1_IRQHandler USART1_IRQHandler 113 | 114 | #elif defined (USE_STM3210E_EVAL) 115 | #define USB_DISCONNECT GPIOB 116 | #define USB_DISCONNECT_PIN GPIO_Pin_14 117 | #define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOB 118 | #define EVAL_COM1_IRQHandler USART1_IRQHandler 119 | 120 | 121 | #elif defined (USE_STM32L152_EVAL) || defined (USE_STM32L152D_EVAL) 122 | /* 123 | For STM32L15xx devices it is possible to use the internal USB pullup 124 | controlled by register SYSCFG_PMC (refer to RM0038 reference manual for 125 | more details). 126 | It is also possible to use external pullup (and disable the internal pullup) 127 | by setting the define USB_USE_EXTERNAL_PULLUP in file platform_config.h 128 | and configuring the right pin to be used for the external pull up configuration. 129 | To have more details on how to use an external pull up, please refer to 130 | STM3210E-EVAL evaluation board manuals. 131 | */ 132 | /* Uncomment the following define to use an external pull up instead of the 133 | integrated STM32L15xx internal pull up. In this case make sure to set up 134 | correctly the external required hardware and the GPIO defines below.*/ 135 | /* #define USB_USE_EXTERNAL_PULLUP */ 136 | 137 | #if !defined(USB_USE_EXTERNAL_PULLUP) 138 | #define STM32L15_USB_CONNECT SYSCFG_USBPuCmd(ENABLE) 139 | #define STM32L15_USB_DISCONNECT SYSCFG_USBPuCmd(DISABLE) 140 | 141 | #elif defined(USB_USE_EXTERNAL_PULLUP) 142 | /* PA0 is chosen just as illustrating example, you should modify the defines 143 | below according to your hardware configuration. */ 144 | #define USB_DISCONNECT GPIOA 145 | #define USB_DISCONNECT_PIN GPIO_Pin_0 146 | #define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOA 147 | #define STM32L15_USB_CONNECT GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN) 148 | #define STM32L15_USB_DISCONNECT GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN) 149 | #endif /* USB_USE_EXTERNAL_PULLUP */ 150 | 151 | #elif defined (USE_STM32373C_EVAL) 152 | #define USB_DISCONNECT GPIOC 153 | #define USB_DISCONNECT_PIN GPIO_Pin_5 154 | #define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOC 155 | 156 | #elif defined (USE_STM32303C_EVAL) 157 | #define USB_DISCONNECT GPIOB 158 | #define USB_DISCONNECT_PIN GPIO_Pin_8 159 | #define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOB 160 | #endif /* USE_STM3210B_EVAL */ 161 | 162 | #if defined (USE_STM32L152_EVAL) || (USE_STM32373C_EVAL) 163 | #define EVAL_COM1_IRQHandler USART2_IRQHandler 164 | #elif defined (USE_STM32L152D_EVAL) || (USE_STM32303C_EVAL) 165 | #define EVAL_COM1_IRQHandler USART1_IRQHandler 166 | #endif 167 | 168 | /* Exported macro ------------------------------------------------------------*/ 169 | /* Exported functions ------------------------------------------------------- */ 170 | 171 | #endif /* __PLATFORM_CONFIG_H */ 172 | 173 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 174 | -------------------------------------------------------------------------------- /retarget.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------- 2 | * Name: Retarget.c 3 | * Purpose: 'Retarget' layer for target-dependent low level functions 4 | * Note(s): 5 | *---------------------------------------------------------------------------- 6 | * This file is part of the uVision/ARM development tools. 7 | * This software may only be used under the terms of a valid, current, 8 | * end user licence from KEIL for a compatible version of KEIL software 9 | * development tools. Nothing else gives you the right to use this software. 10 | * 11 | * This software is supplied "AS IS" without warranties of any kind. 12 | * 13 | * Copyright (c) 2011 Keil - An ARM Company. All rights reserved. 14 | *----------------------------------------------------------------------------*/ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | #pragma import(__use_no_semihosting_swi) 22 | 23 | 24 | int SER_PutChar (int c) 25 | { 26 | while(!(USART1->SR & USART_SR_TC)) { } 27 | 28 | USART1->DR = (uint8_t) c; 29 | 30 | return c; 31 | } 32 | 33 | 34 | struct __FILE { int handle; /* Add whatever you need here */ }; 35 | FILE __stdout; 36 | FILE __stdin; 37 | 38 | 39 | int fputc(int c, FILE *f) { 40 | return (SER_PutChar(c)); 41 | } 42 | 43 | 44 | int fgetc(FILE *f) { 45 | return 0; 46 | } 47 | 48 | 49 | int ferror(FILE *f) { 50 | /* Your implementation of ferror */ 51 | return EOF; 52 | } 53 | 54 | 55 | void _ttywrch(int c) { 56 | SER_PutChar(c); 57 | } 58 | 59 | 60 | void _sys_exit(int return_code) { 61 | label: goto label; /* endless loop */ 62 | } 63 | -------------------------------------------------------------------------------- /stm32_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_it.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and peripherals 9 | * interrupt service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© COPYRIGHT 2013 STMicroelectronics

14 | * 15 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 16 | * You may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at: 18 | * 19 | * http://www.st.com/software_license_agreement_liberty_v2 20 | * 21 | * Unless required by applicable law or agreed to in writing, software 22 | * distributed under the License is distributed on an "AS IS" BASIS, 23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | * See the License for the specific language governing permissions and 25 | * limitations under the License. 26 | * 27 | ****************************************************************************** 28 | */ 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "hw_config.h" 32 | #include "stm32_it.h" 33 | #include "usb_lib.h" 34 | #include "usb_istr.h" 35 | 36 | /* Private typedef -----------------------------------------------------------*/ 37 | /* Private define ------------------------------------------------------------*/ 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* Private variables ---------------------------------------------------------*/ 40 | /* Private function prototypes -----------------------------------------------*/ 41 | /* Private functions ---------------------------------------------------------*/ 42 | /******************************************************************************/ 43 | /* Cortex-M Processor Exceptions Handlers */ 44 | /******************************************************************************/ 45 | 46 | /******************************************************************************* 47 | * Function Name : NMI_Handler 48 | * Description : This function handles NMI exception. 49 | * Input : None 50 | * Output : None 51 | * Return : None 52 | *******************************************************************************/ 53 | void NMI_Handler(void) 54 | { 55 | } 56 | 57 | /******************************************************************************* 58 | * Function Name : HardFault_Handler 59 | * Description : This function handles Hard Fault exception. 60 | * Input : None 61 | * Output : None 62 | * Return : None 63 | *******************************************************************************/ 64 | void HardFault_Handler(void) 65 | { 66 | /* Go to infinite loop when Hard Fault exception occurs */ 67 | while (1) 68 | { 69 | } 70 | } 71 | 72 | /******************************************************************************* 73 | * Function Name : MemManage_Handler 74 | * Description : This function handles Memory Manage exception. 75 | * Input : None 76 | * Output : None 77 | * Return : None 78 | *******************************************************************************/ 79 | void MemManage_Handler(void) 80 | { 81 | /* Go to infinite loop when Memory Manage exception occurs */ 82 | while (1) 83 | { 84 | } 85 | } 86 | 87 | /******************************************************************************* 88 | * Function Name : BusFault_Handler 89 | * Description : This function handles Bus Fault exception. 90 | * Input : None 91 | * Output : None 92 | * Return : None 93 | *******************************************************************************/ 94 | void BusFault_Handler(void) 95 | { 96 | /* Go to infinite loop when Bus Fault exception occurs */ 97 | while (1) 98 | { 99 | } 100 | } 101 | 102 | /******************************************************************************* 103 | * Function Name : UsageFault_Handler 104 | * Description : This function handles Usage Fault exception. 105 | * Input : None 106 | * Output : None 107 | * Return : None 108 | *******************************************************************************/ 109 | void UsageFault_Handler(void) 110 | { 111 | /* Go to infinite loop when Usage Fault exception occurs */ 112 | while (1) 113 | { 114 | } 115 | } 116 | 117 | /******************************************************************************* 118 | * Function Name : SVC_Handler 119 | * Description : This function handles SVCall exception. 120 | * Input : None 121 | * Output : None 122 | * Return : None 123 | *******************************************************************************/ 124 | void SVC_Handler(void) 125 | { 126 | } 127 | 128 | /******************************************************************************* 129 | * Function Name : DebugMon_Handler 130 | * Description : This function handles Debug Monitor exception. 131 | * Input : None 132 | * Output : None 133 | * Return : None 134 | *******************************************************************************/ 135 | void DebugMon_Handler(void) 136 | { 137 | } 138 | 139 | /******************************************************************************* 140 | * Function Name : PendSV_Handler 141 | * Description : This function handles PendSVC exception. 142 | * Input : None 143 | * Output : None 144 | * Return : None 145 | *******************************************************************************/ 146 | void PendSV_Handler(void) 147 | { 148 | } 149 | 150 | /******************************************************************************* 151 | * Function Name : SysTick_Handler 152 | * Description : This function handles SysTick Handler. 153 | * Input : None 154 | * Output : None 155 | * Return : None 156 | *******************************************************************************/ 157 | void SysTick_Handler(void) 158 | { 159 | } 160 | 161 | /******************************************************************************* 162 | * Function Name : USB_IRQHandler 163 | * Description : This function handles USB Low Priority interrupts 164 | * requests. 165 | * Input : None 166 | * Output : None 167 | * Return : None 168 | *******************************************************************************/ 169 | #if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)|| defined (STM32F37X) 170 | void USB_LP_IRQHandler(void) 171 | #else 172 | void USB_LP_CAN1_RX0_IRQHandler(void) 173 | #endif 174 | { 175 | USB_Istr(); 176 | } 177 | 178 | /******************************************************************************* 179 | * Function Name : EVAL_COM1_IRQHandler 180 | * Description : This function handles EVAL_COM1 global interrupt request. 181 | * Input : None 182 | * Output : None 183 | * Return : None 184 | *******************************************************************************/ 185 | void EVAL_COM1_IRQHandler(void) 186 | { 187 | if (USART_GetITStatus(EVAL_COM1, USART_IT_RXNE) != RESET) 188 | { 189 | /* Send the received data to the PC Host*/ 190 | USART_To_USB_Send_Data(); 191 | } 192 | 193 | /* If overrun condition occurs, clear the ORE flag and recover communication */ 194 | if (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_ORE) != RESET) 195 | { 196 | (void)USART_ReceiveData(EVAL_COM1); 197 | } 198 | } 199 | 200 | /******************************************************************************* 201 | * Function Name : USB_FS_WKUP_IRQHandler 202 | * Description : This function handles USB WakeUp interrupt request. 203 | * Input : None 204 | * Output : None 205 | * Return : None 206 | *******************************************************************************/ 207 | 208 | #if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS) 209 | void USB_FS_WKUP_IRQHandler(void) 210 | #else 211 | void USBWakeUp_IRQHandler(void) 212 | #endif 213 | { 214 | EXTI_ClearITPendingBit(EXTI_Line18); 215 | } 216 | 217 | /******************************************************************************/ 218 | /* STM32 Peripherals Interrupt Handlers */ 219 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 220 | /* available peripheral interrupt handler's name please refer to the startup */ 221 | /* file (startup_stm32xxx.s). */ 222 | /******************************************************************************/ 223 | 224 | /******************************************************************************* 225 | * Function Name : PPP_IRQHandler 226 | * Description : This function handles PPP interrupt request. 227 | * Input : None 228 | * Output : None 229 | * Return : None 230 | *******************************************************************************/ 231 | /*void PPP_IRQHandler(void) 232 | { 233 | }*/ 234 | 235 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 236 | 237 | -------------------------------------------------------------------------------- /stm32_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_it.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32_IT_H 31 | #define __STM32_IT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "platform_config.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | /* Exported macro ------------------------------------------------------------*/ 39 | /* Exported functions ------------------------------------------------------- */ 40 | 41 | void NMI_Handler(void); 42 | void HardFault_Handler(void); 43 | void MemManage_Handler(void); 44 | void BusFault_Handler(void); 45 | void UsageFault_Handler(void); 46 | void SVC_Handler(void); 47 | void DebugMon_Handler(void); 48 | void PendSV_Handler(void); 49 | void SysTick_Handler(void); 50 | void USB_LP_CAN1_RX0_IRQHandler(void); 51 | 52 | #if defined (USE_STM32L152_EVAL) || (USE_STM32373C_EVAL) 53 | void USART2_IRQHandler(void); 54 | #else 55 | void USART1_IRQHandler(void); 56 | #endif /* USE_STM32L152_EVAL */ 57 | #endif /* __STM32_IT_H */ 58 | 59 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 60 | --------------------------------------------------------------------------------