├── .gitignore ├── CORE ├── core_cm4.h ├── core_cm4_simd.h ├── core_cmFunc.h ├── core_cmInstr.h └── startup_stm32f40_41xxx.s ├── FWLIB ├── inc │ ├── misc.h │ ├── stm32f4xx_adc.h │ ├── stm32f4xx_can.h │ ├── stm32f4xx_crc.h │ ├── stm32f4xx_cryp.h │ ├── stm32f4xx_dac.h │ ├── stm32f4xx_dbgmcu.h │ ├── stm32f4xx_dcmi.h │ ├── stm32f4xx_dma.h │ ├── stm32f4xx_dma2d.h │ ├── stm32f4xx_exti.h │ ├── stm32f4xx_flash.h │ ├── stm32f4xx_flash_ramfunc.h │ ├── stm32f4xx_fmc.h │ ├── stm32f4xx_fsmc.h │ ├── stm32f4xx_gpio.h │ ├── stm32f4xx_hash.h │ ├── stm32f4xx_i2c.h │ ├── stm32f4xx_iwdg.h │ ├── stm32f4xx_ltdc.h │ ├── stm32f4xx_pwr.h │ ├── stm32f4xx_rcc.h │ ├── stm32f4xx_rng.h │ ├── stm32f4xx_rtc.h │ ├── stm32f4xx_sai.h │ ├── stm32f4xx_sdio.h │ ├── stm32f4xx_spi.h │ ├── stm32f4xx_syscfg.h │ ├── stm32f4xx_tim.h │ ├── stm32f4xx_usart.h │ └── stm32f4xx_wwdg.h └── src │ ├── misc.c │ ├── stm32f4xx_adc.c │ ├── stm32f4xx_can.c │ ├── stm32f4xx_crc.c │ ├── stm32f4xx_cryp.c │ ├── stm32f4xx_cryp_aes.c │ ├── stm32f4xx_cryp_des.c │ ├── stm32f4xx_cryp_tdes.c │ ├── stm32f4xx_dac.c │ ├── stm32f4xx_dbgmcu.c │ ├── stm32f4xx_dcmi.c │ ├── stm32f4xx_dma.c │ ├── stm32f4xx_dma2d.c │ ├── stm32f4xx_exti.c │ ├── stm32f4xx_flash.c │ ├── stm32f4xx_flash_ramfunc.c │ ├── stm32f4xx_fmc.c │ ├── stm32f4xx_fsmc.c │ ├── stm32f4xx_gpio.c │ ├── stm32f4xx_hash.c │ ├── stm32f4xx_hash_md5.c │ ├── stm32f4xx_hash_sha1.c │ ├── stm32f4xx_i2c.c │ ├── stm32f4xx_iwdg.c │ ├── stm32f4xx_ltdc.c │ ├── stm32f4xx_pwr.c │ ├── stm32f4xx_rcc.c │ ├── stm32f4xx_rng.c │ ├── stm32f4xx_rtc.c │ ├── stm32f4xx_sai.c │ ├── stm32f4xx_sdio.c │ ├── stm32f4xx_spi.c │ ├── stm32f4xx_syscfg.c │ ├── stm32f4xx_tim.c │ ├── stm32f4xx_usart.c │ └── stm32f4xx_wwdg.c ├── HARDWARE ├── ADC │ ├── adc.c │ └── adc.h ├── BEEP │ ├── beep.c │ └── beep.h ├── DAC │ ├── dac.c │ └── dac.h ├── KEY │ ├── key.c │ └── key.h ├── LCD │ ├── FONT.H │ ├── lcd.c │ └── lcd.h ├── LED │ ├── led.c │ └── led.h ├── TIMER │ ├── timer.c │ └── timer.h └── TOUCH │ ├── rtouch.c │ └── rtouch.h ├── OBJ └── LCD.hex ├── README.md ├── SYSTEM ├── delay │ ├── delay.c │ └── delay.h ├── sys │ ├── sys.c │ └── sys.h └── usart │ ├── usart.c │ └── usart.h └── USER ├── JLinkSettings.ini ├── LCD.uvoptx ├── LCD.uvprojx ├── main.c ├── stm32f4xx.h ├── stm32f4xx_conf.h ├── stm32f4xx_it.c ├── stm32f4xx_it.h ├── system_stm32f4xx.c ├── system_stm32f4xx.h ├── waveform.c └── waveform.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # Listing Files 55 | *.COD 56 | *.HTM 57 | *.I 58 | *.LST 59 | *.MAP 60 | *.M51 61 | *.M66 62 | *.SCR 63 | 64 | # Object and HEX Files 65 | # *. 66 | *.AXF 67 | *.B[00-31] 68 | *.D 69 | *.CRF 70 | *.ELF 71 | *.HEX 72 | *.H86 73 | *.LIB 74 | *.OBJ 75 | *.O 76 | *.SBR 77 | 78 | # Build Files 79 | *.BAT 80 | *._IA 81 | *.__I 82 | *._II 83 | *.SCR 84 | 85 | # Debugger Files 86 | *.INI 87 | 88 | # Other Files 89 | *.BUILD_LOG.HTM 90 | *.CDB 91 | *.DEP 92 | *.IC 93 | *.LIN 94 | *.LNP 95 | *.ORC 96 | *.PACK 97 | *.PDSC 98 | *.PLG 99 | PROJECT_GUI.XSD 100 | PROJECT_MPW.XSD 101 | PROJECT_OPT.XSD 102 | PROJECT_PROJ.XSD 103 | *.SCT 104 | *.UVL 105 | *.UVLA 106 | *.UVTSK 107 | *.SFD 108 | *.SFR 109 | *.SVD.XML 110 | *.SVD 111 | *.XML 112 | bash.exe.stackdump 113 | 114 | *.bak 115 | 116 | OBJ/* 117 | !OBJ/*.hex 118 | USER/* 119 | !USER/*.c 120 | !USER/*.h 121 | !USER/*.uvprojx 122 | !USER/*.uvoptx 123 | !USER/*.ini 124 | -------------------------------------------------------------------------------- /FWLIB/inc/misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 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 2014 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 "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup MISC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief NVIC Init Structure definition 52 | */ 53 | 54 | typedef struct 55 | { 56 | uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. 57 | This parameter can be an enumerator of @ref IRQn_Type 58 | enumeration (For the complete STM32 Devices IRQ Channels 59 | list, please refer to stm32f4xx.h file) */ 60 | 61 | uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel 62 | specified in NVIC_IRQChannel. This parameter can be a value 63 | between 0 and 15 as described in the table @ref MISC_NVIC_Priority_Table 64 | A lower priority value indicates a higher priority */ 65 | 66 | uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified 67 | in NVIC_IRQChannel. This parameter can be a value 68 | between 0 and 15 as described in the table @ref MISC_NVIC_Priority_Table 69 | A lower priority value indicates a higher priority */ 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 | /* Exported constants --------------------------------------------------------*/ 77 | 78 | /** @defgroup MISC_Exported_Constants 79 | * @{ 80 | */ 81 | 82 | /** @defgroup MISC_Vector_Table_Base 83 | * @{ 84 | */ 85 | 86 | #define NVIC_VectTab_RAM ((uint32_t)0x20000000) 87 | #define NVIC_VectTab_FLASH ((uint32_t)0x08000000) 88 | #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \ 89 | ((VECTTAB) == NVIC_VectTab_FLASH)) 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup MISC_System_Low_Power 95 | * @{ 96 | */ 97 | 98 | #define NVIC_LP_SEVONPEND ((uint8_t)0x10) 99 | #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04) 100 | #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02) 101 | #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \ 102 | ((LP) == NVIC_LP_SLEEPDEEP) || \ 103 | ((LP) == NVIC_LP_SLEEPONEXIT)) 104 | /** 105 | * @} 106 | */ 107 | 108 | /** @defgroup MISC_Preemption_Priority_Group 109 | * @{ 110 | */ 111 | 112 | #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority 113 | 4 bits for subpriority */ 114 | #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority 115 | 3 bits for subpriority */ 116 | #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority 117 | 2 bits for subpriority */ 118 | #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority 119 | 1 bits for subpriority */ 120 | #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority 121 | 0 bits for subpriority */ 122 | 123 | #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \ 124 | ((GROUP) == NVIC_PriorityGroup_1) || \ 125 | ((GROUP) == NVIC_PriorityGroup_2) || \ 126 | ((GROUP) == NVIC_PriorityGroup_3) || \ 127 | ((GROUP) == NVIC_PriorityGroup_4)) 128 | 129 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 130 | 131 | #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 132 | 133 | #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF) 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | /** @defgroup MISC_SysTick_clock_source 140 | * @{ 141 | */ 142 | 143 | #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB) 144 | #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004) 145 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \ 146 | ((SOURCE) == SysTick_CLKSource_HCLK_Div8)) 147 | /** 148 | * @} 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /* Exported macro ------------------------------------------------------------*/ 156 | /* Exported functions --------------------------------------------------------*/ 157 | 158 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup); 159 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); 160 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset); 161 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState); 162 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); 163 | 164 | #ifdef __cplusplus 165 | } 166 | #endif 167 | 168 | #endif /* __MISC_H */ 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | /** 175 | * @} 176 | */ 177 | 178 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 179 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the DBGMCU firmware library. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 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 __STM32F4xx_DBGMCU_H 30 | #define __STM32F4xx_DBGMCU_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /** @addtogroup STM32F4xx_StdPeriph_Driver 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup DBGMCU 44 | * @{ 45 | */ 46 | 47 | /* Exported types ------------------------------------------------------------*/ 48 | /* Exported constants --------------------------------------------------------*/ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 54 | #define DBGMCU_STOP ((uint32_t)0x00000002) 55 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 56 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFFFF8) == 0x00) && ((PERIPH) != 0x00)) 57 | 58 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000001) 59 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00000002) 60 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00000004) 61 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00000008) 62 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00000010) 63 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00000020) 64 | #define DBGMCU_TIM12_STOP ((uint32_t)0x00000040) 65 | #define DBGMCU_TIM13_STOP ((uint32_t)0x00000080) 66 | #define DBGMCU_TIM14_STOP ((uint32_t)0x00000100) 67 | #define DBGMCU_RTC_STOP ((uint32_t)0x00000400) 68 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000800) 69 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00001000) 70 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00200000) 71 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00400000) 72 | #define DBGMCU_I2C3_SMBUS_TIMEOUT ((uint32_t)0x00800000) 73 | #define DBGMCU_CAN1_STOP ((uint32_t)0x02000000) 74 | #define DBGMCU_CAN2_STOP ((uint32_t)0x04000000) 75 | #define IS_DBGMCU_APB1PERIPH(PERIPH) ((((PERIPH) & 0xF91FE200) == 0x00) && ((PERIPH) != 0x00)) 76 | 77 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000001) 78 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00000002) 79 | #define DBGMCU_TIM9_STOP ((uint32_t)0x00010000) 80 | #define DBGMCU_TIM10_STOP ((uint32_t)0x00020000) 81 | #define DBGMCU_TIM11_STOP ((uint32_t)0x00040000) 82 | #define IS_DBGMCU_APB2PERIPH(PERIPH) ((((PERIPH) & 0xFFF8FFFC) == 0x00) && ((PERIPH) != 0x00)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions --------------------------------------------------------*/ 89 | uint32_t DBGMCU_GetREVID(void); 90 | uint32_t DBGMCU_GetDEVID(void); 91 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 92 | void DBGMCU_APB1PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 93 | void DBGMCU_APB2PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* __STM32F4xx_DBGMCU_H */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 110 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_exti.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the EXTI firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_EXTI_H 31 | #define __STM32F4xx_EXTI_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup EXTI 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief EXTI mode enumeration 52 | */ 53 | 54 | typedef enum 55 | { 56 | EXTI_Mode_Interrupt = 0x00, 57 | EXTI_Mode_Event = 0x04 58 | }EXTIMode_TypeDef; 59 | 60 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) 61 | 62 | /** 63 | * @brief EXTI Trigger enumeration 64 | */ 65 | 66 | typedef enum 67 | { 68 | EXTI_Trigger_Rising = 0x08, 69 | EXTI_Trigger_Falling = 0x0C, 70 | EXTI_Trigger_Rising_Falling = 0x10 71 | }EXTITrigger_TypeDef; 72 | 73 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \ 74 | ((TRIGGER) == EXTI_Trigger_Falling) || \ 75 | ((TRIGGER) == EXTI_Trigger_Rising_Falling)) 76 | /** 77 | * @brief EXTI Init Structure definition 78 | */ 79 | 80 | typedef struct 81 | { 82 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. 83 | This parameter can be any combination value of @ref EXTI_Lines */ 84 | 85 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. 86 | This parameter can be a value of @ref EXTIMode_TypeDef */ 87 | 88 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. 89 | This parameter can be a value of @ref EXTITrigger_TypeDef */ 90 | 91 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. 92 | This parameter can be set either to ENABLE or DISABLE */ 93 | }EXTI_InitTypeDef; 94 | 95 | /* Exported constants --------------------------------------------------------*/ 96 | 97 | /** @defgroup EXTI_Exported_Constants 98 | * @{ 99 | */ 100 | 101 | /** @defgroup EXTI_Lines 102 | * @{ 103 | */ 104 | 105 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */ 106 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */ 107 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */ 108 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */ 109 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */ 110 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */ 111 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */ 112 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */ 113 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */ 114 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */ 115 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */ 116 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */ 117 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */ 118 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */ 119 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */ 120 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */ 121 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */ 122 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 123 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB OTG FS Wakeup from suspend event */ 124 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */ 125 | #define EXTI_Line20 ((uint32_t)0x00100000) /*!< External interrupt line 20 Connected to the USB OTG HS (configured in FS) Wakeup event */ 126 | #define EXTI_Line21 ((uint32_t)0x00200000) /*!< External interrupt line 21 Connected to the RTC Tamper and Time Stamp events */ 127 | #define EXTI_Line22 ((uint32_t)0x00400000) /*!< External interrupt line 22 Connected to the RTC Wakeup event */ 128 | 129 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFF800000) == 0x00) && ((LINE) != (uint16_t)0x00)) 130 | 131 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \ 132 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \ 133 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \ 134 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \ 135 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \ 136 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \ 137 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \ 138 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \ 139 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \ 140 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19) || \ 141 | ((LINE) == EXTI_Line20) || ((LINE) == EXTI_Line21) ||\ 142 | ((LINE) == EXTI_Line22)) 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /* Exported macro ------------------------------------------------------------*/ 153 | /* Exported functions --------------------------------------------------------*/ 154 | 155 | /* Function used to set the EXTI configuration to the default reset state *****/ 156 | void EXTI_DeInit(void); 157 | 158 | /* Initialization and Configuration functions *********************************/ 159 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); 160 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct); 161 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line); 162 | 163 | /* Interrupts and flags management functions **********************************/ 164 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line); 165 | void EXTI_ClearFlag(uint32_t EXTI_Line); 166 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line); 167 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line); 168 | 169 | #ifdef __cplusplus 170 | } 171 | #endif 172 | 173 | #endif /* __STM32F4xx_EXTI_H */ 174 | 175 | /** 176 | * @} 177 | */ 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 184 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Header file of FLASH RAMFUNC driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 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 __STM32F4xx_FLASH_RAMFUNC_H 31 | #define __STM32F4xx_FLASH_RAMFUNC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup FLASH RAMFUNC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Private define ------------------------------------------------------------*/ 50 | /** 51 | * @brief __RAM_FUNC definition 52 | */ 53 | #if defined ( __CC_ARM ) 54 | /* ARM Compiler 55 | ------------ 56 | RAM functions are defined using the toolchain options. 57 | Functions that are executed in RAM should reside in a separate source module. 58 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 59 | area of a module to a memory space in physical RAM. 60 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 61 | dialog. 62 | */ 63 | #define __RAM_FUNC void 64 | 65 | #elif defined ( __ICCARM__ ) 66 | /* ICCARM Compiler 67 | --------------- 68 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 69 | */ 70 | #define __RAM_FUNC __ramfunc void 71 | 72 | #elif defined ( __GNUC__ ) 73 | /* GNU Compiler 74 | ------------ 75 | RAM functions are defined using a specific toolchain attribute 76 | "__attribute__((section(".RamFunc")))". 77 | */ 78 | #define __RAM_FUNC void __attribute__((section(".RamFunc"))) 79 | 80 | #endif 81 | /* Exported constants --------------------------------------------------------*/ 82 | /* Exported macro ------------------------------------------------------------*/ 83 | /* Exported functions --------------------------------------------------------*/ 84 | __RAM_FUNC FLASH_FlashInterfaceCmd(FunctionalState NewState); 85 | __RAM_FUNC FLASH_FlashSleepModeCmd(FunctionalState NewState); 86 | 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_hash.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hash.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the HASH 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_HASH_H 31 | #define __STM32F4xx_HASH_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup HASH 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief HASH Init structure definition 52 | */ 53 | typedef struct 54 | { 55 | uint32_t HASH_AlgoSelection; /*!< SHA-1, SHA-224, SHA-256 or MD5. This parameter 56 | can be a value of @ref HASH_Algo_Selection */ 57 | uint32_t HASH_AlgoMode; /*!< HASH or HMAC. This parameter can be a value 58 | of @ref HASH_processor_Algorithm_Mode */ 59 | uint32_t HASH_DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 60 | bit string. This parameter can be a value of 61 | @ref HASH_Data_Type */ 62 | uint32_t HASH_HMACKeyType; /*!< HMAC Short key or HMAC Long Key. This parameter 63 | can be a value of @ref HASH_HMAC_Long_key_only_for_HMAC_mode */ 64 | }HASH_InitTypeDef; 65 | 66 | /** 67 | * @brief HASH message digest result structure definition 68 | */ 69 | typedef struct 70 | { 71 | uint32_t Data[8]; /*!< Message digest result : 8x 32bit wors for SHA-256, 72 | 7x 32bit wors for SHA-224, 73 | 5x 32bit words for SHA-1 or 74 | 4x 32bit words for MD5 */ 75 | } HASH_MsgDigest; 76 | 77 | /** 78 | * @brief HASH context swapping structure definition 79 | */ 80 | typedef struct 81 | { 82 | uint32_t HASH_IMR; 83 | uint32_t HASH_STR; 84 | uint32_t HASH_CR; 85 | uint32_t HASH_CSR[54]; 86 | }HASH_Context; 87 | 88 | /* Exported constants --------------------------------------------------------*/ 89 | 90 | /** @defgroup HASH_Exported_Constants 91 | * @{ 92 | */ 93 | 94 | /** @defgroup HASH_Algo_Selection 95 | * @{ 96 | */ 97 | #define HASH_AlgoSelection_SHA1 ((uint32_t)0x0000) /*!< HASH function is SHA1 */ 98 | #define HASH_AlgoSelection_SHA224 HASH_CR_ALGO_1 /*!< HASH function is SHA224 */ 99 | #define HASH_AlgoSelection_SHA256 HASH_CR_ALGO /*!< HASH function is SHA256 */ 100 | #define HASH_AlgoSelection_MD5 HASH_CR_ALGO_0 /*!< HASH function is MD5 */ 101 | 102 | #define IS_HASH_ALGOSELECTION(ALGOSELECTION) (((ALGOSELECTION) == HASH_AlgoSelection_SHA1) || \ 103 | ((ALGOSELECTION) == HASH_AlgoSelection_SHA224) || \ 104 | ((ALGOSELECTION) == HASH_AlgoSelection_SHA256) || \ 105 | ((ALGOSELECTION) == HASH_AlgoSelection_MD5)) 106 | /** 107 | * @} 108 | */ 109 | 110 | /** @defgroup HASH_processor_Algorithm_Mode 111 | * @{ 112 | */ 113 | #define HASH_AlgoMode_HASH ((uint32_t)0x00000000) /*!< Algorithm is HASH */ 114 | #define HASH_AlgoMode_HMAC HASH_CR_MODE /*!< Algorithm is HMAC */ 115 | 116 | #define IS_HASH_ALGOMODE(ALGOMODE) (((ALGOMODE) == HASH_AlgoMode_HASH) || \ 117 | ((ALGOMODE) == HASH_AlgoMode_HMAC)) 118 | /** 119 | * @} 120 | */ 121 | 122 | /** @defgroup HASH_Data_Type 123 | * @{ 124 | */ 125 | #define HASH_DataType_32b ((uint32_t)0x0000) /*!< 32-bit data. No swapping */ 126 | #define HASH_DataType_16b HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped */ 127 | #define HASH_DataType_8b HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped */ 128 | #define HASH_DataType_1b HASH_CR_DATATYPE /*!< 1-bit data. In the word all bits are swapped */ 129 | 130 | #define IS_HASH_DATATYPE(DATATYPE) (((DATATYPE) == HASH_DataType_32b)|| \ 131 | ((DATATYPE) == HASH_DataType_16b)|| \ 132 | ((DATATYPE) == HASH_DataType_8b) || \ 133 | ((DATATYPE) == HASH_DataType_1b)) 134 | /** 135 | * @} 136 | */ 137 | 138 | /** @defgroup HASH_HMAC_Long_key_only_for_HMAC_mode 139 | * @{ 140 | */ 141 | #define HASH_HMACKeyType_ShortKey ((uint32_t)0x00000000) /*!< HMAC Key is <= 64 bytes */ 142 | #define HASH_HMACKeyType_LongKey HASH_CR_LKEY /*!< HMAC Key is > 64 bytes */ 143 | 144 | #define IS_HASH_HMAC_KEYTYPE(KEYTYPE) (((KEYTYPE) == HASH_HMACKeyType_ShortKey) || \ 145 | ((KEYTYPE) == HASH_HMACKeyType_LongKey)) 146 | /** 147 | * @} 148 | */ 149 | 150 | /** @defgroup Number_of_valid_bits_in_last_word_of_the_message 151 | * @{ 152 | */ 153 | #define IS_HASH_VALIDBITSNUMBER(VALIDBITS) ((VALIDBITS) <= 0x1F) 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /** @defgroup HASH_interrupts_definition 160 | * @{ 161 | */ 162 | #define HASH_IT_DINI HASH_IMR_DINIM /*!< A new block can be entered into the input buffer (DIN) */ 163 | #define HASH_IT_DCI HASH_IMR_DCIM /*!< Digest calculation complete */ 164 | 165 | #define IS_HASH_IT(IT) ((((IT) & (uint32_t)0xFFFFFFFC) == 0x00000000) && ((IT) != 0x00000000)) 166 | #define IS_HASH_GET_IT(IT) (((IT) == HASH_IT_DINI) || ((IT) == HASH_IT_DCI)) 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | /** @defgroup HASH_flags_definition 173 | * @{ 174 | */ 175 | #define HASH_FLAG_DINIS HASH_SR_DINIS /*!< 16 locations are free in the DIN : A new block can be entered into the input buffer */ 176 | #define HASH_FLAG_DCIS HASH_SR_DCIS /*!< Digest calculation complete */ 177 | #define HASH_FLAG_DMAS HASH_SR_DMAS /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing */ 178 | #define HASH_FLAG_BUSY HASH_SR_BUSY /*!< The hash core is Busy : processing a block of data */ 179 | #define HASH_FLAG_DINNE HASH_CR_DINNE /*!< DIN not empty : The input buffer contains at least one word of data */ 180 | 181 | #define IS_HASH_GET_FLAG(FLAG) (((FLAG) == HASH_FLAG_DINIS) || \ 182 | ((FLAG) == HASH_FLAG_DCIS) || \ 183 | ((FLAG) == HASH_FLAG_DMAS) || \ 184 | ((FLAG) == HASH_FLAG_BUSY) || \ 185 | ((FLAG) == HASH_FLAG_DINNE)) 186 | 187 | #define IS_HASH_CLEAR_FLAG(FLAG)(((FLAG) == HASH_FLAG_DINIS) || \ 188 | ((FLAG) == HASH_FLAG_DCIS)) 189 | 190 | /** 191 | * @} 192 | */ 193 | 194 | /** 195 | * @} 196 | */ 197 | 198 | /* Exported macro ------------------------------------------------------------*/ 199 | /* Exported functions --------------------------------------------------------*/ 200 | 201 | /* Function used to set the HASH configuration to the default reset state ****/ 202 | void HASH_DeInit(void); 203 | 204 | /* HASH Configuration function ************************************************/ 205 | void HASH_Init(HASH_InitTypeDef* HASH_InitStruct); 206 | void HASH_StructInit(HASH_InitTypeDef* HASH_InitStruct); 207 | void HASH_Reset(void); 208 | 209 | /* HASH Message Digest generation functions ***********************************/ 210 | void HASH_DataIn(uint32_t Data); 211 | uint8_t HASH_GetInFIFOWordsNbr(void); 212 | void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber); 213 | void HASH_StartDigest(void); 214 | void HASH_AutoStartDigest(FunctionalState NewState); 215 | void HASH_GetDigest(HASH_MsgDigest* HASH_MessageDigest); 216 | 217 | /* HASH Context swapping functions ********************************************/ 218 | void HASH_SaveContext(HASH_Context* HASH_ContextSave); 219 | void HASH_RestoreContext(HASH_Context* HASH_ContextRestore); 220 | 221 | /* HASH DMA interface function ************************************************/ 222 | void HASH_DMACmd(FunctionalState NewState); 223 | 224 | /* HASH Interrupts and flags management functions *****************************/ 225 | void HASH_ITConfig(uint32_t HASH_IT, FunctionalState NewState); 226 | FlagStatus HASH_GetFlagStatus(uint32_t HASH_FLAG); 227 | void HASH_ClearFlag(uint32_t HASH_FLAG); 228 | ITStatus HASH_GetITStatus(uint32_t HASH_IT); 229 | void HASH_ClearITPendingBit(uint32_t HASH_IT); 230 | 231 | /* High Level SHA1 functions **************************************************/ 232 | ErrorStatus HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20]); 233 | ErrorStatus HMAC_SHA1(uint8_t *Key, uint32_t Keylen, 234 | uint8_t *Input, uint32_t Ilen, 235 | uint8_t Output[20]); 236 | 237 | /* High Level MD5 functions ***************************************************/ 238 | ErrorStatus HASH_MD5(uint8_t *Input, uint32_t Ilen, uint8_t Output[16]); 239 | ErrorStatus HMAC_MD5(uint8_t *Key, uint32_t Keylen, 240 | uint8_t *Input, uint32_t Ilen, 241 | uint8_t Output[16]); 242 | 243 | #ifdef __cplusplus 244 | } 245 | #endif 246 | 247 | #endif /*__STM32F4xx_HASH_H */ 248 | 249 | /** 250 | * @} 251 | */ 252 | 253 | /** 254 | * @} 255 | */ 256 | 257 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 258 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_iwdg.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_IWDG_H 31 | #define __STM32F4xx_IWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup IWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup IWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup IWDG_WriteAccess 56 | * @{ 57 | */ 58 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 59 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 60 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 61 | ((ACCESS) == IWDG_WriteAccess_Disable)) 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup IWDG_prescaler 67 | * @{ 68 | */ 69 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 70 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 71 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 72 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 73 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 74 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 75 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 76 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 77 | ((PRESCALER) == IWDG_Prescaler_8) || \ 78 | ((PRESCALER) == IWDG_Prescaler_16) || \ 79 | ((PRESCALER) == IWDG_Prescaler_32) || \ 80 | ((PRESCALER) == IWDG_Prescaler_64) || \ 81 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 82 | ((PRESCALER) == IWDG_Prescaler_256)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @defgroup IWDG_Flag 88 | * @{ 89 | */ 90 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 91 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 92 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 93 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /* Exported macro ------------------------------------------------------------*/ 103 | /* Exported functions --------------------------------------------------------*/ 104 | 105 | /* Prescaler and Counter configuration functions ******************************/ 106 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 107 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 108 | void IWDG_SetReload(uint16_t Reload); 109 | void IWDG_ReloadCounter(void); 110 | 111 | /* IWDG activation function ***************************************************/ 112 | void IWDG_Enable(void); 113 | 114 | /* Flag management function ***************************************************/ 115 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif /* __STM32F4xx_IWDG_H */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_pwr.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_PWR_H 31 | #define __STM32F4xx_PWR_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup PWR 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup PWR_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup PWR_PVD_detection_level 56 | * @{ 57 | */ 58 | #define PWR_PVDLevel_0 PWR_CR_PLS_LEV0 59 | #define PWR_PVDLevel_1 PWR_CR_PLS_LEV1 60 | #define PWR_PVDLevel_2 PWR_CR_PLS_LEV2 61 | #define PWR_PVDLevel_3 PWR_CR_PLS_LEV3 62 | #define PWR_PVDLevel_4 PWR_CR_PLS_LEV4 63 | #define PWR_PVDLevel_5 PWR_CR_PLS_LEV5 64 | #define PWR_PVDLevel_6 PWR_CR_PLS_LEV6 65 | #define PWR_PVDLevel_7 PWR_CR_PLS_LEV7 66 | 67 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \ 68 | ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \ 69 | ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \ 70 | ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7)) 71 | /** 72 | * @} 73 | */ 74 | 75 | 76 | /** @defgroup PWR_Regulator_state_in_STOP_mode 77 | * @{ 78 | */ 79 | #define PWR_MainRegulator_ON ((uint32_t)0x00000000) 80 | #define PWR_LowPowerRegulator_ON PWR_CR_LPDS 81 | 82 | /* --- PWR_Legacy ---*/ 83 | #define PWR_Regulator_ON PWR_MainRegulator_ON 84 | #define PWR_Regulator_LowPower PWR_LowPowerRegulator_ON 85 | 86 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MainRegulator_ON) || \ 87 | ((REGULATOR) == PWR_LowPowerRegulator_ON)) 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** @defgroup PWR_Regulator_state_in_UnderDrive_mode 94 | * @{ 95 | */ 96 | #define PWR_MainRegulator_UnderDrive_ON PWR_CR_MRUDS 97 | #define PWR_LowPowerRegulator_UnderDrive_ON ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS)) 98 | 99 | #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MainRegulator_UnderDrive_ON) || \ 100 | ((REGULATOR) == PWR_LowPowerRegulator_UnderDrive_ON)) 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | /** @defgroup PWR_STOP_mode_entry 107 | * @{ 108 | */ 109 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 110 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 111 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 112 | /** 113 | * @} 114 | */ 115 | 116 | /** @defgroup PWR_Regulator_Voltage_Scale 117 | * @{ 118 | */ 119 | #define PWR_Regulator_Voltage_Scale1 ((uint32_t)0x0000C000) 120 | #define PWR_Regulator_Voltage_Scale2 ((uint32_t)0x00008000) 121 | #define PWR_Regulator_Voltage_Scale3 ((uint32_t)0x00004000) 122 | #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_Regulator_Voltage_Scale1) || \ 123 | ((VOLTAGE) == PWR_Regulator_Voltage_Scale2) || \ 124 | ((VOLTAGE) == PWR_Regulator_Voltage_Scale3)) 125 | /** 126 | * @} 127 | */ 128 | 129 | /** @defgroup PWR_Flag 130 | * @{ 131 | */ 132 | #define PWR_FLAG_WU PWR_CSR_WUF 133 | #define PWR_FLAG_SB PWR_CSR_SBF 134 | #define PWR_FLAG_PVDO PWR_CSR_PVDO 135 | #define PWR_FLAG_BRR PWR_CSR_BRR 136 | #define PWR_FLAG_VOSRDY PWR_CSR_VOSRDY 137 | #define PWR_FLAG_ODRDY PWR_CSR_ODRDY 138 | #define PWR_FLAG_ODSWRDY PWR_CSR_ODSWRDY 139 | #define PWR_FLAG_UDRDY PWR_CSR_UDSWRDY 140 | 141 | /* --- FLAG Legacy ---*/ 142 | #define PWR_FLAG_REGRDY PWR_FLAG_VOSRDY 143 | 144 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 145 | ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR) || \ 146 | ((FLAG) == PWR_FLAG_VOSRDY) || ((FLAG) == PWR_FLAG_ODRDY) || \ 147 | ((FLAG) == PWR_FLAG_ODSWRDY) || ((FLAG) == PWR_FLAG_UDRDY)) 148 | 149 | 150 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 151 | ((FLAG) == PWR_FLAG_UDRDY)) 152 | 153 | /** 154 | * @} 155 | */ 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /* Exported macro ------------------------------------------------------------*/ 162 | /* Exported functions --------------------------------------------------------*/ 163 | 164 | /* Function used to set the PWR configuration to the default reset state ******/ 165 | void PWR_DeInit(void); 166 | 167 | /* Backup Domain Access function **********************************************/ 168 | void PWR_BackupAccessCmd(FunctionalState NewState); 169 | 170 | /* PVD configuration functions ************************************************/ 171 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 172 | void PWR_PVDCmd(FunctionalState NewState); 173 | 174 | /* WakeUp pins configuration functions ****************************************/ 175 | void PWR_WakeUpPinCmd(FunctionalState NewState); 176 | 177 | /* Main and Backup Regulators configuration functions *************************/ 178 | void PWR_BackupRegulatorCmd(FunctionalState NewState); 179 | void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage); 180 | void PWR_OverDriveCmd(FunctionalState NewState); 181 | void PWR_OverDriveSWCmd(FunctionalState NewState); 182 | void PWR_UnderDriveCmd(FunctionalState NewState); 183 | void PWR_MainRegulatorLowVoltageCmd(FunctionalState NewState); 184 | void PWR_LowRegulatorLowVoltageCmd(FunctionalState NewState); 185 | 186 | /* FLASH Power Down configuration functions ***********************************/ 187 | void PWR_FlashPowerDownCmd(FunctionalState NewState); 188 | 189 | /* Low Power modes configuration functions ************************************/ 190 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 191 | void PWR_EnterUnderDriveSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 192 | void PWR_EnterSTANDBYMode(void); 193 | 194 | /* Flags management functions *************************************************/ 195 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 196 | void PWR_ClearFlag(uint32_t PWR_FLAG); 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif 201 | 202 | #endif /* __STM32F4xx_PWR_H */ 203 | 204 | /** 205 | * @} 206 | */ 207 | 208 | /** 209 | * @} 210 | */ 211 | 212 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 213 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_rng.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_rng.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the Random 8 | * Number Generator(RNG) firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_RNG_H 31 | #define __STM32F4xx_RNG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup RNG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup RNG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup RNG_flags_definition 56 | * @{ 57 | */ 58 | #define RNG_FLAG_DRDY ((uint8_t)0x0001) /*!< Data ready */ 59 | #define RNG_FLAG_CECS ((uint8_t)0x0002) /*!< Clock error current status */ 60 | #define RNG_FLAG_SECS ((uint8_t)0x0004) /*!< Seed error current status */ 61 | 62 | #define IS_RNG_GET_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_DRDY) || \ 63 | ((RNG_FLAG) == RNG_FLAG_CECS) || \ 64 | ((RNG_FLAG) == RNG_FLAG_SECS)) 65 | #define IS_RNG_CLEAR_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_CECS) || \ 66 | ((RNG_FLAG) == RNG_FLAG_SECS)) 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup RNG_interrupts_definition 72 | * @{ 73 | */ 74 | #define RNG_IT_CEI ((uint8_t)0x20) /*!< Clock error interrupt */ 75 | #define RNG_IT_SEI ((uint8_t)0x40) /*!< Seed error interrupt */ 76 | 77 | #define IS_RNG_IT(IT) ((((IT) & (uint8_t)0x9F) == 0x00) && ((IT) != 0x00)) 78 | #define IS_RNG_GET_IT(RNG_IT) (((RNG_IT) == RNG_IT_CEI) || ((RNG_IT) == RNG_IT_SEI)) 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions --------------------------------------------------------*/ 89 | 90 | /* Function used to set the RNG configuration to the default reset state *****/ 91 | void RNG_DeInit(void); 92 | 93 | /* Configuration function *****************************************************/ 94 | void RNG_Cmd(FunctionalState NewState); 95 | 96 | /* Get 32 bit Random number function ******************************************/ 97 | uint32_t RNG_GetRandomNumber(void); 98 | 99 | /* Interrupts and flags management functions **********************************/ 100 | void RNG_ITConfig(FunctionalState NewState); 101 | FlagStatus RNG_GetFlagStatus(uint8_t RNG_FLAG); 102 | void RNG_ClearFlag(uint8_t RNG_FLAG); 103 | ITStatus RNG_GetITStatus(uint8_t RNG_IT); 104 | void RNG_ClearITPendingBit(uint8_t RNG_IT); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /*__STM32F4xx_RNG_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 121 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_syscfg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_syscfg.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the SYSCFG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_SYSCFG_H 31 | #define __STM32F4xx_SYSCFG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup SYSCFG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup SYSCFG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup SYSCFG_EXTI_Port_Sources 56 | * @{ 57 | */ 58 | #define EXTI_PortSourceGPIOA ((uint8_t)0x00) 59 | #define EXTI_PortSourceGPIOB ((uint8_t)0x01) 60 | #define EXTI_PortSourceGPIOC ((uint8_t)0x02) 61 | #define EXTI_PortSourceGPIOD ((uint8_t)0x03) 62 | #define EXTI_PortSourceGPIOE ((uint8_t)0x04) 63 | #define EXTI_PortSourceGPIOF ((uint8_t)0x05) 64 | #define EXTI_PortSourceGPIOG ((uint8_t)0x06) 65 | #define EXTI_PortSourceGPIOH ((uint8_t)0x07) 66 | #define EXTI_PortSourceGPIOI ((uint8_t)0x08) 67 | #define EXTI_PortSourceGPIOJ ((uint8_t)0x09) 68 | #define EXTI_PortSourceGPIOK ((uint8_t)0x0A) 69 | 70 | #define IS_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == EXTI_PortSourceGPIOA) || \ 71 | ((PORTSOURCE) == EXTI_PortSourceGPIOB) || \ 72 | ((PORTSOURCE) == EXTI_PortSourceGPIOC) || \ 73 | ((PORTSOURCE) == EXTI_PortSourceGPIOD) || \ 74 | ((PORTSOURCE) == EXTI_PortSourceGPIOE) || \ 75 | ((PORTSOURCE) == EXTI_PortSourceGPIOF) || \ 76 | ((PORTSOURCE) == EXTI_PortSourceGPIOG) || \ 77 | ((PORTSOURCE) == EXTI_PortSourceGPIOH) || \ 78 | ((PORTSOURCE) == EXTI_PortSourceGPIOI) || \ 79 | ((PORTSOURCE) == EXTI_PortSourceGPIOJ) || \ 80 | ((PORTSOURCE) == EXTI_PortSourceGPIOK)) 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | 87 | /** @defgroup SYSCFG_EXTI_Pin_Sources 88 | * @{ 89 | */ 90 | #define EXTI_PinSource0 ((uint8_t)0x00) 91 | #define EXTI_PinSource1 ((uint8_t)0x01) 92 | #define EXTI_PinSource2 ((uint8_t)0x02) 93 | #define EXTI_PinSource3 ((uint8_t)0x03) 94 | #define EXTI_PinSource4 ((uint8_t)0x04) 95 | #define EXTI_PinSource5 ((uint8_t)0x05) 96 | #define EXTI_PinSource6 ((uint8_t)0x06) 97 | #define EXTI_PinSource7 ((uint8_t)0x07) 98 | #define EXTI_PinSource8 ((uint8_t)0x08) 99 | #define EXTI_PinSource9 ((uint8_t)0x09) 100 | #define EXTI_PinSource10 ((uint8_t)0x0A) 101 | #define EXTI_PinSource11 ((uint8_t)0x0B) 102 | #define EXTI_PinSource12 ((uint8_t)0x0C) 103 | #define EXTI_PinSource13 ((uint8_t)0x0D) 104 | #define EXTI_PinSource14 ((uint8_t)0x0E) 105 | #define EXTI_PinSource15 ((uint8_t)0x0F) 106 | #define IS_EXTI_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == EXTI_PinSource0) || \ 107 | ((PINSOURCE) == EXTI_PinSource1) || \ 108 | ((PINSOURCE) == EXTI_PinSource2) || \ 109 | ((PINSOURCE) == EXTI_PinSource3) || \ 110 | ((PINSOURCE) == EXTI_PinSource4) || \ 111 | ((PINSOURCE) == EXTI_PinSource5) || \ 112 | ((PINSOURCE) == EXTI_PinSource6) || \ 113 | ((PINSOURCE) == EXTI_PinSource7) || \ 114 | ((PINSOURCE) == EXTI_PinSource8) || \ 115 | ((PINSOURCE) == EXTI_PinSource9) || \ 116 | ((PINSOURCE) == EXTI_PinSource10) || \ 117 | ((PINSOURCE) == EXTI_PinSource11) || \ 118 | ((PINSOURCE) == EXTI_PinSource12) || \ 119 | ((PINSOURCE) == EXTI_PinSource13) || \ 120 | ((PINSOURCE) == EXTI_PinSource14) || \ 121 | ((PINSOURCE) == EXTI_PinSource15)) 122 | /** 123 | * @} 124 | */ 125 | 126 | 127 | /** @defgroup SYSCFG_Memory_Remap_Config 128 | * @{ 129 | */ 130 | #define SYSCFG_MemoryRemap_Flash ((uint8_t)0x00) 131 | #define SYSCFG_MemoryRemap_SystemFlash ((uint8_t)0x01) 132 | #define SYSCFG_MemoryRemap_SRAM ((uint8_t)0x03) 133 | #define SYSCFG_MemoryRemap_SDRAM ((uint8_t)0x04) 134 | 135 | #if defined (STM32F40_41xxx) 136 | #define SYSCFG_MemoryRemap_FSMC ((uint8_t)0x02) 137 | #endif /* STM32F40_41xxx */ 138 | 139 | #if defined (STM32F427_437xx) || defined (STM32F429_439xx) 140 | #define SYSCFG_MemoryRemap_FMC ((uint8_t)0x02) 141 | #endif /* STM32F427_437xx || STM32F429_439xx */ 142 | 143 | #if defined (STM32F40_41xxx) 144 | #define IS_SYSCFG_MEMORY_REMAP_CONFING(REMAP) (((REMAP) == SYSCFG_MemoryRemap_Flash) || \ 145 | ((REMAP) == SYSCFG_MemoryRemap_SystemFlash) || \ 146 | ((REMAP) == SYSCFG_MemoryRemap_SRAM) || \ 147 | ((REMAP) == SYSCFG_MemoryRemap_FSMC)) 148 | #endif /* STM32F40_41xxx */ 149 | 150 | #if defined (STM32F401xx) || defined (STM32F411xE) 151 | #define IS_SYSCFG_MEMORY_REMAP_CONFING(REMAP) (((REMAP) == SYSCFG_MemoryRemap_Flash) || \ 152 | ((REMAP) == SYSCFG_MemoryRemap_SystemFlash) || \ 153 | ((REMAP) == SYSCFG_MemoryRemap_SRAM)) 154 | #endif /* STM32F401xx || STM32F411xE */ 155 | 156 | #if defined (STM32F427_437xx) || defined (STM32F429_439xx) 157 | #define IS_SYSCFG_MEMORY_REMAP_CONFING(REMAP) (((REMAP) == SYSCFG_MemoryRemap_Flash) || \ 158 | ((REMAP) == SYSCFG_MemoryRemap_SystemFlash) || \ 159 | ((REMAP) == SYSCFG_MemoryRemap_SRAM) || \ 160 | ((REMAP) == SYSCFG_MemoryRemap_SDRAM) || \ 161 | ((REMAP) == SYSCFG_MemoryRemap_FMC)) 162 | #endif /* STM32F427_437xx || STM32F429_439xx */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | 169 | /** @defgroup SYSCFG_ETHERNET_Media_Interface 170 | * @{ 171 | */ 172 | #define SYSCFG_ETH_MediaInterface_MII ((uint32_t)0x00000000) 173 | #define SYSCFG_ETH_MediaInterface_RMII ((uint32_t)0x00000001) 174 | 175 | #define IS_SYSCFG_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == SYSCFG_ETH_MediaInterface_MII) || \ 176 | ((INTERFACE) == SYSCFG_ETH_MediaInterface_RMII)) 177 | /** 178 | * @} 179 | */ 180 | 181 | /** 182 | * @} 183 | */ 184 | 185 | /* Exported macro ------------------------------------------------------------*/ 186 | /* Exported functions --------------------------------------------------------*/ 187 | 188 | void SYSCFG_DeInit(void); 189 | void SYSCFG_MemoryRemapConfig(uint8_t SYSCFG_MemoryRemap); 190 | void SYSCFG_MemorySwappingBank(FunctionalState NewState); 191 | void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex); 192 | void SYSCFG_ETH_MediaInterfaceConfig(uint32_t SYSCFG_ETH_MediaInterface); 193 | void SYSCFG_CompensationCellCmd(FunctionalState NewState); 194 | FlagStatus SYSCFG_GetCompensationCellStatus(void); 195 | 196 | #ifdef __cplusplus 197 | } 198 | #endif 199 | 200 | #endif /*__STM32F4xx_SYSCFG_H */ 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | /** 207 | * @} 208 | */ 209 | 210 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 211 | -------------------------------------------------------------------------------- /FWLIB/inc/stm32f4xx_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 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 __STM32F4xx_WWDG_H 31 | #define __STM32F4xx_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup WWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup WWDG_Prescaler 56 | * @{ 57 | */ 58 | 59 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 60 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 61 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 62 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 63 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 64 | ((PRESCALER) == WWDG_Prescaler_2) || \ 65 | ((PRESCALER) == WWDG_Prescaler_4) || \ 66 | ((PRESCALER) == WWDG_Prescaler_8)) 67 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 68 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /* Exported macro ------------------------------------------------------------*/ 79 | /* Exported functions --------------------------------------------------------*/ 80 | 81 | /* Function used to set the WWDG configuration to the default reset state ****/ 82 | void WWDG_DeInit(void); 83 | 84 | /* Prescaler, Refresh window and Counter configuration functions **************/ 85 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 86 | void WWDG_SetWindowValue(uint8_t WindowValue); 87 | void WWDG_EnableIT(void); 88 | void WWDG_SetCounter(uint8_t Counter); 89 | 90 | /* WWDG activation function ***************************************************/ 91 | void WWDG_Enable(uint8_t Counter); 92 | 93 | /* Interrupts and flags management functions **********************************/ 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F4xx_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /FWLIB/src/stm32f4xx_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.c 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 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 "stm32f4xx_crc.h" 30 | 31 | /** @addtogroup STM32F4xx_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup CRC 36 | * @brief CRC driver modules 37 | * @{ 38 | */ 39 | 40 | /* Private typedef -----------------------------------------------------------*/ 41 | /* Private define ------------------------------------------------------------*/ 42 | /* Private macro -------------------------------------------------------------*/ 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* Private function prototypes -----------------------------------------------*/ 45 | /* Private functions ---------------------------------------------------------*/ 46 | 47 | /** @defgroup CRC_Private_Functions 48 | * @{ 49 | */ 50 | 51 | /** 52 | * @brief Resets the CRC Data register (DR). 53 | * @param None 54 | * @retval None 55 | */ 56 | void CRC_ResetDR(void) 57 | { 58 | /* Reset CRC generator */ 59 | CRC->CR = CRC_CR_RESET; 60 | } 61 | 62 | /** 63 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 64 | * @param Data: data word(32-bit) to compute its CRC 65 | * @retval 32-bit CRC 66 | */ 67 | uint32_t CRC_CalcCRC(uint32_t Data) 68 | { 69 | CRC->DR = Data; 70 | 71 | return (CRC->DR); 72 | } 73 | 74 | /** 75 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 76 | * @param pBuffer: pointer to the buffer containing the data to be computed 77 | * @param BufferLength: length of the buffer to be computed 78 | * @retval 32-bit CRC 79 | */ 80 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 81 | { 82 | uint32_t index = 0; 83 | 84 | for(index = 0; index < BufferLength; index++) 85 | { 86 | CRC->DR = pBuffer[index]; 87 | } 88 | return (CRC->DR); 89 | } 90 | 91 | /** 92 | * @brief Returns the current CRC value. 93 | * @param None 94 | * @retval 32-bit CRC 95 | */ 96 | uint32_t CRC_GetCRC(void) 97 | { 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 103 | * @param IDValue: 8-bit value to be stored in the ID register 104 | * @retval None 105 | */ 106 | void CRC_SetIDRegister(uint8_t IDValue) 107 | { 108 | CRC->IDR = IDValue; 109 | } 110 | 111 | /** 112 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 113 | * @param None 114 | * @retval 8-bit value of the ID register 115 | */ 116 | uint8_t CRC_GetIDRegister(void) 117 | { 118 | return (CRC->IDR); 119 | } 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 134 | -------------------------------------------------------------------------------- /FWLIB/src/stm32f4xx_cryp_des.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_cryp_des.c 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file provides high level functions to encrypt and decrypt an 8 | * input message using DES in ECB/CBC modes. 9 | * It uses the stm32f4xx_cryp.c/.h drivers to access the STM32F4xx CRYP 10 | * peripheral. 11 | * 12 | @verbatim 13 | 14 | =================================================================== 15 | ##### How to use this driver ##### 16 | =================================================================== 17 | [..] 18 | (#) Enable The CRYP controller clock using 19 | RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_CRYP, ENABLE); function. 20 | 21 | (#) Encrypt and decrypt using DES in ECB Mode using CRYP_DES_ECB() function. 22 | 23 | (#) Encrypt and decrypt using DES in CBC Mode using CRYP_DES_CBC() function. 24 | 25 | @endverbatim 26 | * 27 | ****************************************************************************** 28 | * @attention 29 | * 30 | *

© COPYRIGHT 2014 STMicroelectronics

31 | * 32 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 33 | * You may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at: 35 | * 36 | * http://www.st.com/software_license_agreement_liberty_v2 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | * 44 | ****************************************************************************** 45 | */ 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "stm32f4xx_cryp.h" 49 | 50 | 51 | /** @addtogroup STM32F4xx_StdPeriph_Driver 52 | * @{ 53 | */ 54 | 55 | /** @defgroup CRYP 56 | * @brief CRYP driver modules 57 | * @{ 58 | */ 59 | 60 | /* Private typedef -----------------------------------------------------------*/ 61 | /* Private define ------------------------------------------------------------*/ 62 | #define DESBUSY_TIMEOUT ((uint32_t) 0x00010000) 63 | 64 | /* Private macro -------------------------------------------------------------*/ 65 | /* Private variables ---------------------------------------------------------*/ 66 | /* Private function prototypes -----------------------------------------------*/ 67 | /* Private functions ---------------------------------------------------------*/ 68 | 69 | 70 | /** @defgroup CRYP_Private_Functions 71 | * @{ 72 | */ 73 | 74 | /** @defgroup CRYP_Group8 High Level DES functions 75 | * @brief High Level DES functions 76 | * 77 | @verbatim 78 | =============================================================================== 79 | ##### High Level DES functions ##### 80 | =============================================================================== 81 | @endverbatim 82 | * @{ 83 | */ 84 | 85 | /** 86 | * @brief Encrypt and decrypt using DES in ECB Mode 87 | * @param Mode: encryption or decryption Mode. 88 | * This parameter can be one of the following values: 89 | * @arg MODE_ENCRYPT: Encryption 90 | * @arg MODE_DECRYPT: Decryption 91 | * @param Key: Key used for DES algorithm. 92 | * @param Ilength: length of the Input buffer, must be a multiple of 8. 93 | * @param Input: pointer to the Input buffer. 94 | * @param Output: pointer to the returned buffer. 95 | * @retval An ErrorStatus enumeration value: 96 | * - SUCCESS: Operation done 97 | * - ERROR: Operation failed 98 | */ 99 | ErrorStatus CRYP_DES_ECB(uint8_t Mode, uint8_t Key[8], uint8_t *Input, 100 | uint32_t Ilength, uint8_t *Output) 101 | { 102 | CRYP_InitTypeDef DES_CRYP_InitStructure; 103 | CRYP_KeyInitTypeDef DES_CRYP_KeyInitStructure; 104 | __IO uint32_t counter = 0; 105 | uint32_t busystatus = 0; 106 | ErrorStatus status = SUCCESS; 107 | uint32_t keyaddr = (uint32_t)Key; 108 | uint32_t inputaddr = (uint32_t)Input; 109 | uint32_t outputaddr = (uint32_t)Output; 110 | uint32_t i = 0; 111 | 112 | /* Crypto structures initialisation*/ 113 | CRYP_KeyStructInit(&DES_CRYP_KeyInitStructure); 114 | 115 | /* Crypto Init for Encryption process */ 116 | if( Mode == MODE_ENCRYPT ) /* DES encryption */ 117 | { 118 | DES_CRYP_InitStructure.CRYP_AlgoDir = CRYP_AlgoDir_Encrypt; 119 | } 120 | else/* if( Mode == MODE_DECRYPT )*/ /* DES decryption */ 121 | { 122 | DES_CRYP_InitStructure.CRYP_AlgoDir = CRYP_AlgoDir_Decrypt; 123 | } 124 | 125 | DES_CRYP_InitStructure.CRYP_AlgoMode = CRYP_AlgoMode_DES_ECB; 126 | DES_CRYP_InitStructure.CRYP_DataType = CRYP_DataType_8b; 127 | CRYP_Init(&DES_CRYP_InitStructure); 128 | 129 | /* Key Initialisation */ 130 | DES_CRYP_KeyInitStructure.CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr)); 131 | keyaddr+=4; 132 | DES_CRYP_KeyInitStructure.CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr)); 133 | CRYP_KeyInit(& DES_CRYP_KeyInitStructure); 134 | 135 | /* Flush IN/OUT FIFO */ 136 | CRYP_FIFOFlush(); 137 | 138 | /* Enable Crypto processor */ 139 | CRYP_Cmd(ENABLE); 140 | 141 | if(CRYP_GetCmdStatus() == DISABLE) 142 | { 143 | /* The CRYP peripheral clock is not enabled or the device doesn't embedd 144 | the CRYP peripheral (please check the device sales type. */ 145 | return(ERROR); 146 | } 147 | for(i=0; ((i
© COPYRIGHT 2014 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 "stm32f4xx_dbgmcu.h" 30 | 31 | /** @addtogroup STM32F4xx_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup DBGMCU 36 | * @brief DBGMCU driver modules 37 | * @{ 38 | */ 39 | 40 | /* Private typedef -----------------------------------------------------------*/ 41 | /* Private define ------------------------------------------------------------*/ 42 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 43 | 44 | /* Private macro -------------------------------------------------------------*/ 45 | /* Private variables ---------------------------------------------------------*/ 46 | /* Private function prototypes -----------------------------------------------*/ 47 | /* Private functions ---------------------------------------------------------*/ 48 | 49 | /** @defgroup DBGMCU_Private_Functions 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @brief Returns the device revision identifier. 55 | * @param None 56 | * @retval Device revision identifier 57 | */ 58 | uint32_t DBGMCU_GetREVID(void) 59 | { 60 | return(DBGMCU->IDCODE >> 16); 61 | } 62 | 63 | /** 64 | * @brief Returns the device identifier. 65 | * @param None 66 | * @retval Device identifier 67 | */ 68 | uint32_t DBGMCU_GetDEVID(void) 69 | { 70 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 71 | } 72 | 73 | /** 74 | * @brief Configures low power mode behavior when the MCU is in Debug mode. 75 | * @param DBGMCU_Periph: specifies the low power mode. 76 | * This parameter can be any combination of the following values: 77 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 78 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 79 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 80 | * @param NewState: new state of the specified low power mode in Debug mode. 81 | * This parameter can be: ENABLE or DISABLE. 82 | * @retval None 83 | */ 84 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 85 | { 86 | /* Check the parameters */ 87 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 88 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 89 | if (NewState != DISABLE) 90 | { 91 | DBGMCU->CR |= DBGMCU_Periph; 92 | } 93 | else 94 | { 95 | DBGMCU->CR &= ~DBGMCU_Periph; 96 | } 97 | } 98 | 99 | /** 100 | * @brief Configures APB1 peripheral behavior when the MCU is in Debug mode. 101 | * @param DBGMCU_Periph: specifies the APB1 peripheral. 102 | * This parameter can be any combination of the following values: 103 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 104 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 105 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 106 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 107 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 108 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 109 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 110 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 111 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 112 | * @arg DBGMCU_RTC_STOP: RTC Calendar and Wakeup counter stopped when Core is halted. 113 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 114 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 115 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 116 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 117 | * @arg DBGMCU_I2C3_SMBUS_TIMEOUT: I2C3 SMBUS timeout mode stopped when Core is halted 118 | * @arg DBGMCU_CAN2_STOP: Debug CAN1 stopped when Core is halted 119 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 120 | * This parameter can be: ENABLE or DISABLE. 121 | * @retval None 122 | */ 123 | void DBGMCU_APB1PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState) 124 | { 125 | /* Check the parameters */ 126 | assert_param(IS_DBGMCU_APB1PERIPH(DBGMCU_Periph)); 127 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 128 | 129 | if (NewState != DISABLE) 130 | { 131 | DBGMCU->APB1FZ |= DBGMCU_Periph; 132 | } 133 | else 134 | { 135 | DBGMCU->APB1FZ &= ~DBGMCU_Periph; 136 | } 137 | } 138 | 139 | /** 140 | * @brief Configures APB2 peripheral behavior when the MCU is in Debug mode. 141 | * @param DBGMCU_Periph: specifies the APB2 peripheral. 142 | * This parameter can be any combination of the following values: 143 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 144 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 145 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 146 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 147 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 148 | * @param NewState: new state of the specified peripheral in Debug mode. 149 | * This parameter can be: ENABLE or DISABLE. 150 | * @retval None 151 | */ 152 | void DBGMCU_APB2PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState) 153 | { 154 | /* Check the parameters */ 155 | assert_param(IS_DBGMCU_APB2PERIPH(DBGMCU_Periph)); 156 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 157 | 158 | if (NewState != DISABLE) 159 | { 160 | DBGMCU->APB2FZ |= DBGMCU_Periph; 161 | } 162 | else 163 | { 164 | DBGMCU->APB2FZ &= ~DBGMCU_Periph; 165 | } 166 | } 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 181 | -------------------------------------------------------------------------------- /FWLIB/src/stm32f4xx_exti.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_exti.c 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file provides firmware functions to manage the following 8 | * functionalities of the EXTI peripheral: 9 | * + Initialization and Configuration 10 | * + Interrupts and flags management 11 | * 12 | @verbatim 13 | 14 | =============================================================================== 15 | ##### EXTI features ##### 16 | =============================================================================== 17 | 18 | [..] External interrupt/event lines are mapped as following: 19 | (#) All available GPIO pins are connected to the 16 external 20 | interrupt/event lines from EXTI0 to EXTI15. 21 | (#) EXTI line 16 is connected to the PVD Output 22 | (#) EXTI line 17 is connected to the RTC Alarm event 23 | (#) EXTI line 18 is connected to the USB OTG FS Wakeup from suspend event 24 | (#) EXTI line 19 is connected to the Ethernet Wakeup event 25 | (#) EXTI line 20 is connected to the USB OTG HS (configured in FS) Wakeup event 26 | (#) EXTI line 21 is connected to the RTC Tamper and Time Stamp events 27 | (#) EXTI line 22 is connected to the RTC Wakeup event 28 | 29 | ##### How to use this driver ##### 30 | =============================================================================== 31 | 32 | [..] In order to use an I/O pin as an external interrupt source, follow steps 33 | below: 34 | (#) Configure the I/O in input mode using GPIO_Init() 35 | (#) Select the input source pin for the EXTI line using SYSCFG_EXTILineConfig() 36 | (#) Select the mode(interrupt, event) and configure the trigger 37 | selection (Rising, falling or both) using EXTI_Init() 38 | (#) Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init() 39 | 40 | [..] 41 | (@) SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx 42 | registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 43 | 44 | @endverbatim 45 | * 46 | ****************************************************************************** 47 | * @attention 48 | * 49 | *

© COPYRIGHT 2014 STMicroelectronics

50 | * 51 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 52 | * You may not use this file except in compliance with the License. 53 | * You may obtain a copy of the License at: 54 | * 55 | * http://www.st.com/software_license_agreement_liberty_v2 56 | * 57 | * Unless required by applicable law or agreed to in writing, software 58 | * distributed under the License is distributed on an "AS IS" BASIS, 59 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 60 | * See the License for the specific language governing permissions and 61 | * limitations under the License. 62 | * 63 | ****************************************************************************** 64 | */ 65 | 66 | /* Includes ------------------------------------------------------------------*/ 67 | #include "stm32f4xx_exti.h" 68 | 69 | /** @addtogroup STM32F4xx_StdPeriph_Driver 70 | * @{ 71 | */ 72 | 73 | /** @defgroup EXTI 74 | * @brief EXTI driver modules 75 | * @{ 76 | */ 77 | 78 | /* Private typedef -----------------------------------------------------------*/ 79 | /* Private define ------------------------------------------------------------*/ 80 | 81 | #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */ 82 | 83 | /* Private macro -------------------------------------------------------------*/ 84 | /* Private variables ---------------------------------------------------------*/ 85 | /* Private function prototypes -----------------------------------------------*/ 86 | /* Private functions ---------------------------------------------------------*/ 87 | 88 | /** @defgroup EXTI_Private_Functions 89 | * @{ 90 | */ 91 | 92 | /** @defgroup EXTI_Group1 Initialization and Configuration functions 93 | * @brief Initialization and Configuration functions 94 | * 95 | @verbatim 96 | =============================================================================== 97 | ##### Initialization and Configuration functions ##### 98 | =============================================================================== 99 | 100 | @endverbatim 101 | * @{ 102 | */ 103 | 104 | /** 105 | * @brief Deinitializes the EXTI peripheral registers to their default reset values. 106 | * @param None 107 | * @retval None 108 | */ 109 | void EXTI_DeInit(void) 110 | { 111 | EXTI->IMR = 0x00000000; 112 | EXTI->EMR = 0x00000000; 113 | EXTI->RTSR = 0x00000000; 114 | EXTI->FTSR = 0x00000000; 115 | EXTI->PR = 0x007FFFFF; 116 | } 117 | 118 | /** 119 | * @brief Initializes the EXTI peripheral according to the specified 120 | * parameters in the EXTI_InitStruct. 121 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 122 | * that contains the configuration information for the EXTI peripheral. 123 | * @retval None 124 | */ 125 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct) 126 | { 127 | uint32_t tmp = 0; 128 | 129 | /* Check the parameters */ 130 | assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); 131 | assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); 132 | assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); 133 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); 134 | 135 | tmp = (uint32_t)EXTI_BASE; 136 | 137 | if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) 138 | { 139 | /* Clear EXTI line configuration */ 140 | EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; 141 | EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; 142 | 143 | tmp += EXTI_InitStruct->EXTI_Mode; 144 | 145 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 146 | 147 | /* Clear Rising Falling edge configuration */ 148 | EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; 149 | EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; 150 | 151 | /* Select the trigger for the selected external interrupts */ 152 | if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) 153 | { 154 | /* Rising Falling edge */ 155 | EXTI->RTSR |= EXTI_InitStruct->EXTI_Line; 156 | EXTI->FTSR |= EXTI_InitStruct->EXTI_Line; 157 | } 158 | else 159 | { 160 | tmp = (uint32_t)EXTI_BASE; 161 | tmp += EXTI_InitStruct->EXTI_Trigger; 162 | 163 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 164 | } 165 | } 166 | else 167 | { 168 | tmp += EXTI_InitStruct->EXTI_Mode; 169 | 170 | /* Disable the selected external lines */ 171 | *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; 172 | } 173 | } 174 | 175 | /** 176 | * @brief Fills each EXTI_InitStruct member with its reset value. 177 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will 178 | * be initialized. 179 | * @retval None 180 | */ 181 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct) 182 | { 183 | EXTI_InitStruct->EXTI_Line = EXTI_LINENONE; 184 | EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; 185 | EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; 186 | EXTI_InitStruct->EXTI_LineCmd = DISABLE; 187 | } 188 | 189 | /** 190 | * @brief Generates a Software interrupt on selected EXTI line. 191 | * @param EXTI_Line: specifies the EXTI line on which the software interrupt 192 | * will be generated. 193 | * This parameter can be any combination of EXTI_Linex where x can be (0..22) 194 | * @retval None 195 | */ 196 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line) 197 | { 198 | /* Check the parameters */ 199 | assert_param(IS_EXTI_LINE(EXTI_Line)); 200 | 201 | EXTI->SWIER |= EXTI_Line; 202 | } 203 | 204 | /** 205 | * @} 206 | */ 207 | 208 | /** @defgroup EXTI_Group2 Interrupts and flags management functions 209 | * @brief Interrupts and flags management functions 210 | * 211 | @verbatim 212 | =============================================================================== 213 | ##### Interrupts and flags management functions ##### 214 | =============================================================================== 215 | 216 | @endverbatim 217 | * @{ 218 | */ 219 | 220 | /** 221 | * @brief Checks whether the specified EXTI line flag is set or not. 222 | * @param EXTI_Line: specifies the EXTI line flag to check. 223 | * This parameter can be EXTI_Linex where x can be(0..22) 224 | * @retval The new state of EXTI_Line (SET or RESET). 225 | */ 226 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line) 227 | { 228 | FlagStatus bitstatus = RESET; 229 | /* Check the parameters */ 230 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 231 | 232 | if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 233 | { 234 | bitstatus = SET; 235 | } 236 | else 237 | { 238 | bitstatus = RESET; 239 | } 240 | return bitstatus; 241 | } 242 | 243 | /** 244 | * @brief Clears the EXTI's line pending flags. 245 | * @param EXTI_Line: specifies the EXTI lines flags to clear. 246 | * This parameter can be any combination of EXTI_Linex where x can be (0..22) 247 | * @retval None 248 | */ 249 | void EXTI_ClearFlag(uint32_t EXTI_Line) 250 | { 251 | /* Check the parameters */ 252 | assert_param(IS_EXTI_LINE(EXTI_Line)); 253 | 254 | EXTI->PR = EXTI_Line; 255 | } 256 | 257 | /** 258 | * @brief Checks whether the specified EXTI line is asserted or not. 259 | * @param EXTI_Line: specifies the EXTI line to check. 260 | * This parameter can be EXTI_Linex where x can be(0..22) 261 | * @retval The new state of EXTI_Line (SET or RESET). 262 | */ 263 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line) 264 | { 265 | FlagStatus bitstatus = RESET; 266 | /* Check the parameters */ 267 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 268 | 269 | if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 270 | { 271 | bitstatus = SET; 272 | } 273 | else 274 | { 275 | bitstatus = RESET; 276 | } 277 | return bitstatus; 278 | 279 | } 280 | 281 | /** 282 | * @brief Clears the EXTI's line pending bits. 283 | * @param EXTI_Line: specifies the EXTI lines to clear. 284 | * This parameter can be any combination of EXTI_Linex where x can be (0..22) 285 | * @retval None 286 | */ 287 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line) 288 | { 289 | /* Check the parameters */ 290 | assert_param(IS_EXTI_LINE(EXTI_Line)); 291 | 292 | EXTI->PR = EXTI_Line; 293 | } 294 | 295 | /** 296 | * @} 297 | */ 298 | 299 | /** 300 | * @} 301 | */ 302 | 303 | /** 304 | * @} 305 | */ 306 | 307 | /** 308 | * @} 309 | */ 310 | 311 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 312 | -------------------------------------------------------------------------------- /FWLIB/src/stm32f4xx_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief FLASH RAMFUNC module driver. 8 | * This file provides a FLASH firmware functions which should be 9 | * executed from internal SRAM 10 | * + Stop/Start the flash interface while System Run 11 | * + Enable/Disable the flash sleep while System Run 12 | * 13 | @verbatim 14 | ============================================================================== 15 | ##### APIs executed from Internal RAM ##### 16 | ============================================================================== 17 | [..] 18 | *** ARM Compiler *** 19 | -------------------- 20 | [..] RAM functions are defined using the toolchain options. 21 | Functions that are be executed in RAM should reside in a separate 22 | source module. Using the 'Options for File' dialog you can simply change 23 | the 'Code / Const' area of a module to a memory space in physical RAM. 24 | Available memory areas are declared in the 'Target' tab of the 25 | Options for Target' dialog. 26 | 27 | *** ICCARM Compiler *** 28 | ----------------------- 29 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 30 | 31 | *** GNU Compiler *** 32 | -------------------- 33 | [..] RAM functions are defined using a specific toolchain attribute 34 | "__attribute__((section(".RamFunc")))". 35 | 36 | @endverbatim 37 | ****************************************************************************** 38 | * @attention 39 | * 40 | *

© COPYRIGHT 2014 STMicroelectronics

41 | * 42 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 43 | * You may not use this file except in compliance with the License. 44 | * You may obtain a copy of the License at: 45 | * 46 | * http://www.st.com/software_license_agreement_liberty_v2 47 | * 48 | * Unless required by applicable law or agreed to in writing, software 49 | * distributed under the License is distributed on an "AS IS" BASIS, 50 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 51 | * See the License for the specific language governing permissions and 52 | * limitations under the License. 53 | * 54 | ****************************************************************************** 55 | */ 56 | 57 | /* Includes ------------------------------------------------------------------*/ 58 | #include "stm32f4xx_flash_ramfunc.h" 59 | 60 | /** @addtogroup STM32F4xx_StdPeriph_Driver 61 | * @{ 62 | */ 63 | 64 | /** @defgroup FLASH RAMFUNC 65 | * @brief FLASH RAMFUNC driver modules 66 | * @{ 67 | */ 68 | 69 | /* Private typedef -----------------------------------------------------------*/ 70 | /* Private define ------------------------------------------------------------*/ 71 | /* Private macro -------------------------------------------------------------*/ 72 | /* Private variables ---------------------------------------------------------*/ 73 | /* Private function prototypes -----------------------------------------------*/ 74 | /* Private functions ---------------------------------------------------------*/ 75 | 76 | /** @defgroup FLASH_RAMFUNC_Private_Functions 77 | * @{ 78 | */ 79 | 80 | /** @defgroup FLASH_RAMFUNC_Group1 Peripheral features functions executed from internal RAM 81 | * @brief Peripheral Extended features functions 82 | * 83 | @verbatim 84 | 85 | =============================================================================== 86 | ##### ramfunc functions ##### 87 | =============================================================================== 88 | [..] 89 | This subsection provides a set of functions that should be executed from RAM 90 | transfers. 91 | 92 | @endverbatim 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @brief Start/Stop the flash interface while System Run 98 | * @note This mode is only available for STM32F411xx devices. 99 | * @note This mode could n't be set while executing with the flash itself. 100 | * It should be done with specific routine executed from RAM. 101 | * @param NewState: new state of the Smart Card mode. 102 | * This parameter can be: ENABLE or DISABLE. 103 | * @retval None 104 | */ 105 | __RAM_FUNC FLASH_FlashInterfaceCmd(FunctionalState NewState) 106 | { 107 | if (NewState != DISABLE) 108 | { 109 | /* Start the flash interface while System Run */ 110 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR); 111 | } 112 | else 113 | { 114 | /* Stop the flash interface while System Run */ 115 | SET_BIT(PWR->CR, PWR_CR_FISSR); 116 | } 117 | } 118 | 119 | /** 120 | * @brief Enable/Disable the flash sleep while System Run 121 | * @note This mode is only available for STM32F411xx devices. 122 | * @note This mode could n't be set while executing with the flash itself. 123 | * It should be done with specific routine executed from RAM. 124 | * @param NewState: new state of the Smart Card mode. 125 | * This parameter can be: ENABLE or DISABLE. 126 | * @retval None 127 | */ 128 | __RAM_FUNC FLASH_FlashSleepModeCmd(FunctionalState NewState) 129 | { 130 | if (NewState != DISABLE) 131 | { 132 | /* Enable the flash sleep while System Run */ 133 | SET_BIT(PWR->CR, PWR_CR_FMSSR); 134 | } 135 | else 136 | { 137 | /* Disable the flash sleep while System Run */ 138 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR); 139 | } 140 | } 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** 147 | * @} 148 | */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 159 | -------------------------------------------------------------------------------- /FWLIB/src/stm32f4xx_hash_md5.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hash_md5.c 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file provides high level functions to compute the HASH MD5 and 8 | * HMAC MD5 Digest of an input message. 9 | * It uses the stm32f4xx_hash.c/.h drivers to access the STM32F4xx HASH 10 | * peripheral. 11 | * 12 | @verbatim 13 | =================================================================== 14 | ##### How to use this driver ##### 15 | =================================================================== 16 | [..] 17 | (#) Enable The HASH controller clock using 18 | RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_HASH, ENABLE); function. 19 | 20 | (#) Calculate the HASH MD5 Digest using HASH_MD5() function. 21 | 22 | (#) Calculate the HMAC MD5 Digest using HMAC_MD5() function. 23 | 24 | @endverbatim 25 | * 26 | ****************************************************************************** 27 | * @attention 28 | * 29 | *

© COPYRIGHT 2014 STMicroelectronics

30 | * 31 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 32 | * You may not use this file except in compliance with the License. 33 | * You may obtain a copy of the License at: 34 | * 35 | * http://www.st.com/software_license_agreement_liberty_v2 36 | * 37 | * Unless required by applicable law or agreed to in writing, software 38 | * distributed under the License is distributed on an "AS IS" BASIS, 39 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 | * See the License for the specific language governing permissions and 41 | * limitations under the License. 42 | * 43 | ****************************************************************************** 44 | */ 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f4xx_hash.h" 48 | 49 | /** @addtogroup STM32F4xx_StdPeriph_Driver 50 | * @{ 51 | */ 52 | 53 | /** @defgroup HASH 54 | * @brief HASH driver modules 55 | * @{ 56 | */ 57 | 58 | /* Private typedef -----------------------------------------------------------*/ 59 | /* Private define ------------------------------------------------------------*/ 60 | #define MD5BUSY_TIMEOUT ((uint32_t) 0x00010000) 61 | 62 | /* Private macro -------------------------------------------------------------*/ 63 | /* Private variables ---------------------------------------------------------*/ 64 | /* Private function prototypes -----------------------------------------------*/ 65 | /* Private functions ---------------------------------------------------------*/ 66 | 67 | /** @defgroup HASH_Private_Functions 68 | * @{ 69 | */ 70 | 71 | /** @defgroup HASH_Group7 High Level MD5 functions 72 | * @brief High Level MD5 Hash and HMAC functions 73 | * 74 | @verbatim 75 | =============================================================================== 76 | ##### High Level MD5 Hash and HMAC functions ##### 77 | =============================================================================== 78 | 79 | 80 | @endverbatim 81 | * @{ 82 | */ 83 | 84 | /** 85 | * @brief Compute the HASH MD5 digest. 86 | * @param Input: pointer to the Input buffer to be treated. 87 | * @param Ilen: length of the Input buffer. 88 | * @param Output: the returned digest 89 | * @retval An ErrorStatus enumeration value: 90 | * - SUCCESS: digest computation done 91 | * - ERROR: digest computation failed 92 | */ 93 | ErrorStatus HASH_MD5(uint8_t *Input, uint32_t Ilen, uint8_t Output[16]) 94 | { 95 | HASH_InitTypeDef MD5_HASH_InitStructure; 96 | HASH_MsgDigest MD5_MessageDigest; 97 | __IO uint16_t nbvalidbitsdata = 0; 98 | uint32_t i = 0; 99 | __IO uint32_t counter = 0; 100 | uint32_t busystatus = 0; 101 | ErrorStatus status = SUCCESS; 102 | uint32_t inputaddr = (uint32_t)Input; 103 | uint32_t outputaddr = (uint32_t)Output; 104 | 105 | 106 | /* Number of valid bits in last word of the Input data */ 107 | nbvalidbitsdata = 8 * (Ilen % 4); 108 | 109 | /* HASH peripheral initialization */ 110 | HASH_DeInit(); 111 | 112 | /* HASH Configuration */ 113 | MD5_HASH_InitStructure.HASH_AlgoSelection = HASH_AlgoSelection_MD5; 114 | MD5_HASH_InitStructure.HASH_AlgoMode = HASH_AlgoMode_HASH; 115 | MD5_HASH_InitStructure.HASH_DataType = HASH_DataType_8b; 116 | HASH_Init(&MD5_HASH_InitStructure); 117 | 118 | /* Configure the number of valid bits in last word of the data */ 119 | HASH_SetLastWordValidBitsNbr(nbvalidbitsdata); 120 | 121 | /* Write the Input block in the IN FIFO */ 122 | for(i=0; i 64) 197 | { 198 | /* HMAC long Key */ 199 | MD5_HASH_InitStructure.HASH_HMACKeyType = HASH_HMACKeyType_LongKey; 200 | } 201 | else 202 | { 203 | /* HMAC short Key */ 204 | MD5_HASH_InitStructure.HASH_HMACKeyType = HASH_HMACKeyType_ShortKey; 205 | } 206 | HASH_Init(&MD5_HASH_InitStructure); 207 | 208 | /* Configure the number of valid bits in last word of the Key */ 209 | HASH_SetLastWordValidBitsNbr(nbvalidbitskey); 210 | 211 | /* Write the Key */ 212 | for(i=0; i
© COPYRIGHT 2014 STMicroelectronics
30 | * 31 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 32 | * You may not use this file except in compliance with the License. 33 | * You may obtain a copy of the License at: 34 | * 35 | * http://www.st.com/software_license_agreement_liberty_v2 36 | * 37 | * Unless required by applicable law or agreed to in writing, software 38 | * distributed under the License is distributed on an "AS IS" BASIS, 39 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 | * See the License for the specific language governing permissions and 41 | * limitations under the License. 42 | * 43 | ****************************************************************************** 44 | */ 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f4xx_hash.h" 48 | 49 | /** @addtogroup STM32F4xx_StdPeriph_Driver 50 | * @{ 51 | */ 52 | 53 | /** @defgroup HASH 54 | * @brief HASH driver modules 55 | * @{ 56 | */ 57 | 58 | /* Private typedef -----------------------------------------------------------*/ 59 | /* Private define ------------------------------------------------------------*/ 60 | #define SHA1BUSY_TIMEOUT ((uint32_t) 0x00010000) 61 | 62 | /* Private macro -------------------------------------------------------------*/ 63 | /* Private variables ---------------------------------------------------------*/ 64 | /* Private function prototypes -----------------------------------------------*/ 65 | /* Private functions ---------------------------------------------------------*/ 66 | 67 | /** @defgroup HASH_Private_Functions 68 | * @{ 69 | */ 70 | 71 | /** @defgroup HASH_Group6 High Level SHA1 functions 72 | * @brief High Level SHA1 Hash and HMAC functions 73 | * 74 | @verbatim 75 | =============================================================================== 76 | ##### High Level SHA1 Hash and HMAC functions ##### 77 | =============================================================================== 78 | 79 | 80 | @endverbatim 81 | * @{ 82 | */ 83 | 84 | /** 85 | * @brief Compute the HASH SHA1 digest. 86 | * @param Input: pointer to the Input buffer to be treated. 87 | * @param Ilen: length of the Input buffer. 88 | * @param Output: the returned digest 89 | * @retval An ErrorStatus enumeration value: 90 | * - SUCCESS: digest computation done 91 | * - ERROR: digest computation failed 92 | */ 93 | ErrorStatus HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20]) 94 | { 95 | HASH_InitTypeDef SHA1_HASH_InitStructure; 96 | HASH_MsgDigest SHA1_MessageDigest; 97 | __IO uint16_t nbvalidbitsdata = 0; 98 | uint32_t i = 0; 99 | __IO uint32_t counter = 0; 100 | uint32_t busystatus = 0; 101 | ErrorStatus status = SUCCESS; 102 | uint32_t inputaddr = (uint32_t)Input; 103 | uint32_t outputaddr = (uint32_t)Output; 104 | 105 | /* Number of valid bits in last word of the Input data */ 106 | nbvalidbitsdata = 8 * (Ilen % 4); 107 | 108 | /* HASH peripheral initialization */ 109 | HASH_DeInit(); 110 | 111 | /* HASH Configuration */ 112 | SHA1_HASH_InitStructure.HASH_AlgoSelection = HASH_AlgoSelection_SHA1; 113 | SHA1_HASH_InitStructure.HASH_AlgoMode = HASH_AlgoMode_HASH; 114 | SHA1_HASH_InitStructure.HASH_DataType = HASH_DataType_8b; 115 | HASH_Init(&SHA1_HASH_InitStructure); 116 | 117 | /* Configure the number of valid bits in last word of the data */ 118 | HASH_SetLastWordValidBitsNbr(nbvalidbitsdata); 119 | 120 | /* Write the Input block in the IN FIFO */ 121 | for(i=0; i 64) 198 | { 199 | /* HMAC long Key */ 200 | SHA1_HASH_InitStructure.HASH_HMACKeyType = HASH_HMACKeyType_LongKey; 201 | } 202 | else 203 | { 204 | /* HMAC short Key */ 205 | SHA1_HASH_InitStructure.HASH_HMACKeyType = HASH_HMACKeyType_ShortKey; 206 | } 207 | HASH_Init(&SHA1_HASH_InitStructure); 208 | 209 | /* Configure the number of valid bits in last word of the Key */ 210 | HASH_SetLastWordValidBitsNbr(nbvalidbitskey); 211 | 212 | /* Write the Key */ 213 | for(i=0; i
© COPYRIGHT 2014 STMicroelectronics
68 | * 69 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 70 | * You may not use this file except in compliance with the License. 71 | * You may obtain a copy of the License at: 72 | * 73 | * http://www.st.com/software_license_agreement_liberty_v2 74 | * 75 | * Unless required by applicable law or agreed to in writing, software 76 | * distributed under the License is distributed on an "AS IS" BASIS, 77 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 78 | * See the License for the specific language governing permissions and 79 | * limitations under the License. 80 | * 81 | ****************************************************************************** 82 | */ 83 | 84 | /* Includes ------------------------------------------------------------------*/ 85 | #include "stm32f4xx_iwdg.h" 86 | 87 | /** @addtogroup STM32F4xx_StdPeriph_Driver 88 | * @{ 89 | */ 90 | 91 | /** @defgroup IWDG 92 | * @brief IWDG driver modules 93 | * @{ 94 | */ 95 | 96 | /* Private typedef -----------------------------------------------------------*/ 97 | /* Private define ------------------------------------------------------------*/ 98 | 99 | /* KR register bit mask */ 100 | #define KR_KEY_RELOAD ((uint16_t)0xAAAA) 101 | #define KR_KEY_ENABLE ((uint16_t)0xCCCC) 102 | 103 | /* Private macro -------------------------------------------------------------*/ 104 | /* Private variables ---------------------------------------------------------*/ 105 | /* Private function prototypes -----------------------------------------------*/ 106 | /* Private functions ---------------------------------------------------------*/ 107 | 108 | /** @defgroup IWDG_Private_Functions 109 | * @{ 110 | */ 111 | 112 | /** @defgroup IWDG_Group1 Prescaler and Counter configuration functions 113 | * @brief Prescaler and Counter configuration functions 114 | * 115 | @verbatim 116 | =============================================================================== 117 | ##### Prescaler and Counter configuration functions ##### 118 | =============================================================================== 119 | 120 | @endverbatim 121 | * @{ 122 | */ 123 | 124 | /** 125 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers. 126 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers. 127 | * This parameter can be one of the following values: 128 | * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers 129 | * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers 130 | * @retval None 131 | */ 132 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess) 133 | { 134 | /* Check the parameters */ 135 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess)); 136 | IWDG->KR = IWDG_WriteAccess; 137 | } 138 | 139 | /** 140 | * @brief Sets IWDG Prescaler value. 141 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value. 142 | * This parameter can be one of the following values: 143 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4 144 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8 145 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16 146 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32 147 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64 148 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128 149 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256 150 | * @retval None 151 | */ 152 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler) 153 | { 154 | /* Check the parameters */ 155 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler)); 156 | IWDG->PR = IWDG_Prescaler; 157 | } 158 | 159 | /** 160 | * @brief Sets IWDG Reload value. 161 | * @param Reload: specifies the IWDG Reload value. 162 | * This parameter must be a number between 0 and 0x0FFF. 163 | * @retval None 164 | */ 165 | void IWDG_SetReload(uint16_t Reload) 166 | { 167 | /* Check the parameters */ 168 | assert_param(IS_IWDG_RELOAD(Reload)); 169 | IWDG->RLR = Reload; 170 | } 171 | 172 | /** 173 | * @brief Reloads IWDG counter with value defined in the reload register 174 | * (write access to IWDG_PR and IWDG_RLR registers disabled). 175 | * @param None 176 | * @retval None 177 | */ 178 | void IWDG_ReloadCounter(void) 179 | { 180 | IWDG->KR = KR_KEY_RELOAD; 181 | } 182 | 183 | /** 184 | * @} 185 | */ 186 | 187 | /** @defgroup IWDG_Group2 IWDG activation function 188 | * @brief IWDG activation function 189 | * 190 | @verbatim 191 | =============================================================================== 192 | ##### IWDG activation function ##### 193 | =============================================================================== 194 | 195 | @endverbatim 196 | * @{ 197 | */ 198 | 199 | /** 200 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled). 201 | * @param None 202 | * @retval None 203 | */ 204 | void IWDG_Enable(void) 205 | { 206 | IWDG->KR = KR_KEY_ENABLE; 207 | } 208 | 209 | /** 210 | * @} 211 | */ 212 | 213 | /** @defgroup IWDG_Group3 Flag management function 214 | * @brief Flag management function 215 | * 216 | @verbatim 217 | =============================================================================== 218 | ##### Flag management function ##### 219 | =============================================================================== 220 | 221 | @endverbatim 222 | * @{ 223 | */ 224 | 225 | /** 226 | * @brief Checks whether the specified IWDG flag is set or not. 227 | * @param IWDG_FLAG: specifies the flag to check. 228 | * This parameter can be one of the following values: 229 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going 230 | * @arg IWDG_FLAG_RVU: Reload Value Update on going 231 | * @retval The new state of IWDG_FLAG (SET or RESET). 232 | */ 233 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG) 234 | { 235 | FlagStatus bitstatus = RESET; 236 | /* Check the parameters */ 237 | assert_param(IS_IWDG_FLAG(IWDG_FLAG)); 238 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET) 239 | { 240 | bitstatus = SET; 241 | } 242 | else 243 | { 244 | bitstatus = RESET; 245 | } 246 | /* Return the flag status */ 247 | return bitstatus; 248 | } 249 | 250 | /** 251 | * @} 252 | */ 253 | 254 | /** 255 | * @} 256 | */ 257 | 258 | /** 259 | * @} 260 | */ 261 | 262 | /** 263 | * @} 264 | */ 265 | 266 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 267 | -------------------------------------------------------------------------------- /FWLIB/src/stm32f4xx_syscfg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_syscfg.c 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file provides firmware functions to manage the SYSCFG peripheral. 8 | * 9 | @verbatim 10 | 11 | =============================================================================== 12 | ##### How to use this driver ##### 13 | =============================================================================== 14 | [..] This driver provides functions for: 15 | 16 | (#) Remapping the memory accessible in the code area using SYSCFG_MemoryRemapConfig() 17 | 18 | (#) Swapping the internal flash Bank1 and Bank2 this features is only visible for 19 | STM32F42xxx/43xxx devices Devices. 20 | 21 | (#) Manage the EXTI lines connection to the GPIOs using SYSCFG_EXTILineConfig() 22 | 23 | (#) Select the ETHERNET media interface (RMII/RII) using SYSCFG_ETH_MediaInterfaceConfig() 24 | 25 | -@- SYSCFG APB clock must be enabled to get write access to SYSCFG registers, 26 | using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 27 | 28 | @endverbatim 29 | ****************************************************************************** 30 | * @attention 31 | * 32 | *

© COPYRIGHT 2014 STMicroelectronics

33 | * 34 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 35 | * You may not use this file except in compliance with the License. 36 | * You may obtain a copy of the License at: 37 | * 38 | * http://www.st.com/software_license_agreement_liberty_v2 39 | * 40 | * Unless required by applicable law or agreed to in writing, software 41 | * distributed under the License is distributed on an "AS IS" BASIS, 42 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 43 | * See the License for the specific language governing permissions and 44 | * limitations under the License. 45 | * 46 | ****************************************************************************** 47 | */ 48 | 49 | /* Includes ------------------------------------------------------------------*/ 50 | #include "stm32f4xx_syscfg.h" 51 | #include "stm32f4xx_rcc.h" 52 | 53 | /** @addtogroup STM32F4xx_StdPeriph_Driver 54 | * @{ 55 | */ 56 | 57 | /** @defgroup SYSCFG 58 | * @brief SYSCFG driver modules 59 | * @{ 60 | */ 61 | 62 | /* Private typedef -----------------------------------------------------------*/ 63 | /* Private define ------------------------------------------------------------*/ 64 | /* ------------ RCC registers bit address in the alias region ----------- */ 65 | #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE) 66 | /* --- MEMRMP Register ---*/ 67 | /* Alias word address of UFB_MODE bit */ 68 | #define MEMRMP_OFFSET SYSCFG_OFFSET 69 | #define UFB_MODE_BitNumber ((uint8_t)0x8) 70 | #define UFB_MODE_BB (PERIPH_BB_BASE + (MEMRMP_OFFSET * 32) + (UFB_MODE_BitNumber * 4)) 71 | 72 | 73 | /* --- PMC Register ---*/ 74 | /* Alias word address of MII_RMII_SEL bit */ 75 | #define PMC_OFFSET (SYSCFG_OFFSET + 0x04) 76 | #define MII_RMII_SEL_BitNumber ((uint8_t)0x17) 77 | #define PMC_MII_RMII_SEL_BB (PERIPH_BB_BASE + (PMC_OFFSET * 32) + (MII_RMII_SEL_BitNumber * 4)) 78 | 79 | /* --- CMPCR Register ---*/ 80 | /* Alias word address of CMP_PD bit */ 81 | #define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20) 82 | #define CMP_PD_BitNumber ((uint8_t)0x00) 83 | #define CMPCR_CMP_PD_BB (PERIPH_BB_BASE + (CMPCR_OFFSET * 32) + (CMP_PD_BitNumber * 4)) 84 | 85 | /* Private macro -------------------------------------------------------------*/ 86 | /* Private variables ---------------------------------------------------------*/ 87 | /* Private function prototypes -----------------------------------------------*/ 88 | /* Private functions ---------------------------------------------------------*/ 89 | 90 | /** @defgroup SYSCFG_Private_Functions 91 | * @{ 92 | */ 93 | 94 | /** 95 | * @brief Deinitializes the Alternate Functions (remap and EXTI configuration) 96 | * registers to their default reset values. 97 | * @param None 98 | * @retval None 99 | */ 100 | void SYSCFG_DeInit(void) 101 | { 102 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE); 103 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, DISABLE); 104 | } 105 | 106 | /** 107 | * @brief Changes the mapping of the specified pin. 108 | * @param SYSCFG_Memory: selects the memory remapping. 109 | * This parameter can be one of the following values: 110 | * @arg SYSCFG_MemoryRemap_Flash: Main Flash memory mapped at 0x00000000 111 | * @arg SYSCFG_MemoryRemap_SystemFlash: System Flash memory mapped at 0x00000000 112 | * @arg SYSCFG_MemoryRemap_FSMC: FSMC (Bank1 (NOR/PSRAM 1 and 2) mapped at 0x00000000 for STM32F405xx/407xx and STM32F415xx/417xx devices. 113 | * @arg SYSCFG_MemoryRemap_FMC: FMC (Bank1 (NOR/PSRAM 1 and 2) mapped at 0x00000000 for STM32F42xxx/43xxx devices. 114 | * @arg SYSCFG_MemoryRemap_SRAM: Embedded SRAM (112kB) mapped at 0x00000000 115 | * @arg SYSCFG_MemoryRemap_SDRAM: FMC (External SDRAM) mapped at 0x00000000 for STM32F42xxx/43xxx devices. 116 | * @retval None 117 | */ 118 | void SYSCFG_MemoryRemapConfig(uint8_t SYSCFG_MemoryRemap) 119 | { 120 | /* Check the parameters */ 121 | assert_param(IS_SYSCFG_MEMORY_REMAP_CONFING(SYSCFG_MemoryRemap)); 122 | 123 | SYSCFG->MEMRMP = SYSCFG_MemoryRemap; 124 | } 125 | 126 | /** 127 | * @brief Enables or disables the Interal FLASH Bank Swapping. 128 | * 129 | * @note This function can be used only for STM32F42xxx/43xxx devices. 130 | * 131 | * @param NewState: new state of Interal FLASH Bank swapping. 132 | * This parameter can be one of the following values: 133 | * @arg ENABLE: Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000) 134 | * and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000) 135 | * @arg DISABLE:(the default state) Flash Bank1 mapped at 0x08000000 (and aliased @0x0000 0000) 136 | and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000) 137 | * @retval None 138 | */ 139 | void SYSCFG_MemorySwappingBank(FunctionalState NewState) 140 | { 141 | /* Check the parameters */ 142 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 143 | 144 | *(__IO uint32_t *) UFB_MODE_BB = (uint32_t)NewState; 145 | } 146 | 147 | /** 148 | * @brief Selects the GPIO pin used as EXTI Line. 149 | * @param EXTI_PortSourceGPIOx : selects the GPIO port to be used as source for 150 | * EXTI lines where x can be (A..K) for STM32F42xxx/43xxx devices, (A..I) 151 | * for STM32F405xx/407xx and STM32F415xx/417xx devices or (A, B, C, D and H) 152 | * for STM32401xx devices. 153 | * 154 | * @param EXTI_PinSourcex: specifies the EXTI line to be configured. 155 | * This parameter can be EXTI_PinSourcex where x can be (0..15, except 156 | * for EXTI_PortSourceGPIOI x can be (0..11) for STM32F405xx/407xx 157 | * and STM32F405xx/407xx devices and for EXTI_PortSourceGPIOK x can 158 | * be (0..7) for STM32F42xxx/43xxx devices. 159 | * 160 | * @retval None 161 | */ 162 | void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex) 163 | { 164 | uint32_t tmp = 0x00; 165 | 166 | /* Check the parameters */ 167 | assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx)); 168 | assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex)); 169 | 170 | tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)); 171 | SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp; 172 | SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03))); 173 | } 174 | 175 | /** 176 | * @brief Selects the ETHERNET media interface 177 | * @param SYSCFG_ETH_MediaInterface: specifies the Media Interface mode. 178 | * This parameter can be one of the following values: 179 | * @arg SYSCFG_ETH_MediaInterface_MII: MII mode selected 180 | * @arg SYSCFG_ETH_MediaInterface_RMII: RMII mode selected 181 | * @retval None 182 | */ 183 | void SYSCFG_ETH_MediaInterfaceConfig(uint32_t SYSCFG_ETH_MediaInterface) 184 | { 185 | assert_param(IS_SYSCFG_ETH_MEDIA_INTERFACE(SYSCFG_ETH_MediaInterface)); 186 | /* Configure MII_RMII selection bit */ 187 | *(__IO uint32_t *) PMC_MII_RMII_SEL_BB = SYSCFG_ETH_MediaInterface; 188 | } 189 | 190 | /** 191 | * @brief Enables or disables the I/O Compensation Cell. 192 | * @note The I/O compensation cell can be used only when the device supply 193 | * voltage ranges from 2.4 to 3.6 V. 194 | * @param NewState: new state of the I/O Compensation Cell. 195 | * This parameter can be one of the following values: 196 | * @arg ENABLE: I/O compensation cell enabled 197 | * @arg DISABLE: I/O compensation cell power-down mode 198 | * @retval None 199 | */ 200 | void SYSCFG_CompensationCellCmd(FunctionalState NewState) 201 | { 202 | /* Check the parameters */ 203 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 204 | 205 | *(__IO uint32_t *) CMPCR_CMP_PD_BB = (uint32_t)NewState; 206 | } 207 | 208 | /** 209 | * @brief Checks whether the I/O Compensation Cell ready flag is set or not. 210 | * @param None 211 | * @retval The new state of the I/O Compensation Cell ready flag (SET or RESET) 212 | */ 213 | FlagStatus SYSCFG_GetCompensationCellStatus(void) 214 | { 215 | FlagStatus bitstatus = RESET; 216 | 217 | if ((SYSCFG->CMPCR & SYSCFG_CMPCR_READY ) != (uint32_t)RESET) 218 | { 219 | bitstatus = SET; 220 | } 221 | else 222 | { 223 | bitstatus = RESET; 224 | } 225 | return bitstatus; 226 | } 227 | 228 | /** 229 | * @} 230 | */ 231 | 232 | /** 233 | * @} 234 | */ 235 | 236 | /** 237 | * @} 238 | */ 239 | 240 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 241 | -------------------------------------------------------------------------------- /HARDWARE/ADC/adc.c: -------------------------------------------------------------------------------- 1 | #include "adc.h" 2 | #include "delay.h" 3 | ////////////////////////////////////////////////////////////////////////////////// 4 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 5 | //ALIENTEK STM32F407开发板 6 | //ADC 驱动代码 7 | //正点原子@ALIENTEK 8 | //技术论坛:www.openedv.com 9 | //创建日期:2014/5/6 10 | //版本:V1.0 11 | //版权所有,盗版必究。 12 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 13 | //All rights reserved 14 | ////////////////////////////////////////////////////////////////////////////////// 15 | 16 | 17 | //初始化ADC 18 | void Adc_Init(void) 19 | { 20 | GPIO_InitTypeDef GPIO_InitStructure; 21 | ADC_CommonInitTypeDef ADC_CommonInitStructure; 22 | ADC_InitTypeDef ADC_InitStructure; 23 | 24 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOA时钟 25 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //使能ADC1时钟 26 | 27 | //先初始化ADC1通道5 IO口 28 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//PA5 通道5 29 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//模拟输入 30 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//不带上下拉 31 | GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化 32 | 33 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); //ADC1复位 34 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); //复位结束 35 | 36 | 37 | ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//独立模式 38 | ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//两个采样阶段之间的延迟5个时钟 39 | ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //DMA失能 40 | ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//预分频4分频。ADCCLK=PCLK2/4=84/4=21Mhz,ADC时钟最好不要超过36Mhz 41 | ADC_CommonInit(&ADC_CommonInitStructure);//初始化 42 | 43 | ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12位模式 44 | ADC_InitStructure.ADC_ScanConvMode = DISABLE;//非扫描模式 45 | ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//关闭连续转换 46 | ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//禁止触发检测,使用软件触发 47 | ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//右对齐 48 | ADC_InitStructure.ADC_NbrOfConversion = 1;//1个转换在规则序列中 也就是只转换规则序列1 49 | ADC_Init(ADC1, &ADC_InitStructure);//ADC初始化 50 | 51 | 52 | ADC_Cmd(ADC1, ENABLE);//开启AD转换器 53 | 54 | } 55 | //获得ADC值 56 | //ch: @ref ADC_channels 57 | //通道值 0~16取值范围为:ADC_Channel_0~ADC_Channel_16 58 | //返回值:转换结果 59 | u16 Get_Adc(u8 ch) 60 | { 61 | //设置指定ADC的规则组通道,一个序列,采样时间 62 | ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_480Cycles ); //ADC1,ADC通道,480个周期,提高采样时间可以提高精确度 63 | 64 | ADC_SoftwareStartConv(ADC1); //使能指定的ADC1的软件转换启动功能 65 | 66 | while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//等待转换结束 67 | 68 | return ADC_GetConversionValue(ADC1); //返回最近一次ADC1规则组的转换结果 69 | } 70 | //获取通道ch的转换值,取times次,然后平均 71 | //ch:通道编号 72 | //times:获取次数 73 | //返回值:通道ch的times次转换结果平均值 74 | u16 Get_Adc_Average(u8 ch,u8 times) 75 | { 76 | u32 temp_val=0; 77 | u8 t; 78 | for(t=0;tKEY1>KEY2>WK_UP!! 46 | u8 KEY_Scan(u8 mode) 47 | { 48 | static u8 key_up=1;//按键按松开标志u 49 | //u8 runstop=1; 50 | 51 | if(mode)key_up=1; //支持连按 52 | if(key_up&&(KEY0==0||KEY1==0||KEY2==0||WK_UP==1)) 53 | { 54 | delay_ms(10);//去抖动 55 | key_up=0; 56 | if(KEY0==0)return 0; 57 | else if(KEY1==0)return 2; 58 | else if(KEY2==0)return 3; 59 | else if(WK_UP==1)return 4; 60 | }else if(KEY0==1&&KEY1==1&&KEY2==1&&WK_UP==0)key_up=1; 61 | return 1;// 无按键按下 62 | } 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /HARDWARE/KEY/key.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEY_H 2 | #define __KEY_H 3 | #include "sys.h" 4 | ////////////////////////////////////////////////////////////////////////////////// 5 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 6 | //ALIENTEK STM32F407开发板 7 | //按键输入驱动代码 8 | //正点原子@ALIENTEK 9 | //技术论坛:www.openedv.com 10 | //创建日期:2014/5/3 11 | //版本:V1.0 12 | //版权所有,盗版必究。 13 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 14 | //All rights reserved 15 | ////////////////////////////////////////////////////////////////////////////////// 16 | 17 | /*下面的方式是通过直接操作库函数方式读取IO*/ 18 | #define KEY0 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4) //PE4 19 | #define KEY1 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3) //PE3 20 | #define KEY2 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2) //PE2 21 | #define WK_UP GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) //PA0 22 | 23 | 24 | /*下面方式是通过位带操作方式读取IO*/ 25 | /* 26 | #define KEY0 PEin(4) //PE4 27 | #define KEY1 PEin(3) //PE3 28 | #define KEY2 PEin(2) //P32 29 | #define WK_UP PAin(0) //PA0 30 | */ 31 | 32 | 33 | #define KEY0_PRES 0 34 | #define KEY1_PRES 2 35 | #define KEY2_PRES 3 36 | #define WKUP_PRES 4 37 | 38 | void KEY_Init(void); //IO初始化 39 | u8 KEY_Scan(u8); //按键扫描函数 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /HARDWARE/LCD/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H 2 | #define __LCD_H 3 | #include "sys.h" 4 | #include "stdlib.h" 5 | 6 | 7 | //LCD重要参数集 8 | typedef struct 9 | { 10 | u16 width; //LCD 宽度 11 | u16 height; //LCD 高度 12 | u16 id; //LCD ID 13 | u8 dir; //横屏还是竖屏控制:0,竖屏;1,横屏。 14 | u16 wramcmd; //开始写gram指令 15 | u16 setxcmd; //设置x坐标指令 16 | u16 setycmd; //设置y坐标指令 17 | }_lcd_dev; 18 | 19 | //LCD参数 20 | extern _lcd_dev lcddev; //管理LCD重要参数 21 | //LCD的画笔颜色和背景色 22 | extern u16 POINT_COLOR;//默认红色 23 | extern u16 BACK_COLOR; //背景颜色.默认为白色 24 | 25 | 26 | ////////////////////////////////////////////////////////////////////////////////// 27 | //-----------------LCD端口定义---------------- 28 | #define LCD_LED PBout(15) //LCD背光 PB15 29 | //LCD地址结构体 30 | typedef struct 31 | { 32 | vu16 LCD_REG; 33 | vu16 LCD_RAM; 34 | } LCD_TypeDef; 35 | //使用NOR/SRAM的 Bank1.sector4,地址位HADDR[27,26]=11 A6作为数据命令区分线 36 | //注意设置时STM32内部会右移一位对其! 111 1110=0X7E 37 | #define LCD_BASE ((u32)(0x6C000000 | 0x0000007E)) 38 | #define LCD ((LCD_TypeDef *) LCD_BASE) 39 | ////////////////////////////////////////////////////////////////////////////////// 40 | 41 | //扫描方向定义 42 | #define L2R_U2D 0 //从左到右,从上到下 43 | #define L2R_D2U 1 //从左到右,从下到上 44 | #define R2L_U2D 2 //从右到左,从上到下 45 | #define R2L_D2U 3 //从右到左,从下到上 46 | 47 | #define U2D_L2R 4 //从上到下,从左到右 48 | #define U2D_R2L 5 //从上到下,从右到左 49 | #define D2U_L2R 6 //从下到上,从左到右 50 | #define D2U_R2L 7 //从下到上,从右到左 51 | 52 | #define DFT_SCAN_DIR L2R_U2D //默认的扫描方向 53 | 54 | //画笔颜色 55 | #define WHITE 0xFFFF 56 | #define BLACK 0x0000 57 | #define BLUE 0x001F 58 | #define BRED 0XF81F 59 | #define GRED 0XFFE0 60 | #define GBLUE 0X07FF 61 | #define RED 0xF800 62 | #define MAGENTA 0xF81F 63 | #define GREEN 0x07E0 64 | #define CYAN 0x7FFF 65 | #define YELLOW 0xFFE0 66 | #define BROWN 0XBC40 //棕色 67 | #define BRRED 0XFC07 //棕红色 68 | #define GRAY 0X8430 //灰色 69 | //GUI颜色 70 | 71 | #define DARKBLUE 0X01CF //深蓝色 72 | #define LIGHTBLUE 0X7D7C //浅蓝色 73 | #define GRAYBLUE 0X5458 //灰蓝色 74 | //以上三色为PANEL的颜色 75 | 76 | #define LIGHTGREEN 0X841F //浅绿色 77 | //#define LIGHTGRAY 0XEF5B //浅灰色(PANNEL) 78 | #define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色 79 | 80 | #define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色) 81 | #define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色) 82 | void LCD_Init(void); //初始化 83 | void LCD_DisplayOn(void); //开显示 84 | void LCD_DisplayOff(void); //关显示 85 | void LCD_Clear(u16 Color); //清屏 86 | void LCD_SetCursor(u16 Xpos, u16 Ypos); //设置光标 87 | void LCD_DrawPoint(u16 x,u16 y); //画点 88 | void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color); //快速画点 89 | u16 LCD_ReadPoint(u16 x,u16 y); //读点 90 | void LCD_Draw_Circle(u16 x0,u16 y0,u8 r); //画圆 91 | void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2); //画线 92 | void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2); //画矩形 93 | void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 color); //填充单色 94 | void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color); //填充指定颜色 95 | void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode); //显示一个字符 96 | void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size); //显示一个数字 97 | void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode); //显示 数字 98 | void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p); //显示一个字符串,12/16字体 99 | 100 | void LCD_WriteReg(u16 LCD_Reg, u16 LCD_RegValue); 101 | u16 LCD_ReadReg(u16 LCD_Reg); 102 | void LCD_WriteRAM_Prepare(void); 103 | void LCD_WriteRAM(u16 RGB_Code); 104 | void LCD_SSD_BackLightSet(u8 pwm); //SSD1963 背光控制 105 | void LCD_Scan_Dir(u8 dir); //设置屏扫描方向 106 | void LCD_Display_Dir(u8 dir); //设置屏幕显示方向 107 | void LCD_Set_Window(u16 sx,u16 sy,u16 width,u16 height); //设置窗口 108 | void LCD_ShowData(float Vmax,float Vmin,float Vpp); 109 | void LCD_ShowFloat(u16 x, u16 y, float num); 110 | 111 | //LCD分辨率设置 112 | #define SSD_HOR_RESOLUTION 800 //LCD水平分辨率 113 | #define SSD_VER_RESOLUTION 480 //LCD垂直分辨率 114 | //LCD驱动参数设置 115 | #define SSD_HOR_PULSE_WIDTH 1 //水平脉宽 116 | #define SSD_HOR_BACK_PORCH 46 //水平前廊 117 | #define SSD_HOR_FRONT_PORCH 210 //水平后廊 118 | 119 | #define SSD_VER_PULSE_WIDTH 1 //垂直脉宽 120 | #define SSD_VER_BACK_PORCH 23 //垂直前廊 121 | #define SSD_VER_FRONT_PORCH 22 //垂直前廊 122 | //如下几个参数,自动计算 123 | #define SSD_HT (SSD_HOR_RESOLUTION+SSD_HOR_BACK_PORCH+SSD_HOR_FRONT_PORCH) 124 | #define SSD_HPS (SSD_HOR_BACK_PORCH) 125 | #define SSD_VT (SSD_VER_RESOLUTION+SSD_VER_BACK_PORCH+SSD_VER_FRONT_PORCH) 126 | #define SSD_VPS (SSD_VER_BACK_PORCH) 127 | 128 | #endif 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /HARDWARE/LED/led.c: -------------------------------------------------------------------------------- 1 | #include "led.h" 2 | ////////////////////////////////////////////////////////////////////////////////// 3 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 4 | //ALIENTEK STM32F407开发板 5 | //LED驱动代码 6 | //正点原子@ALIENTEK 7 | //技术论坛:www.openedv.com 8 | //创建日期:2014/5/2 9 | //版本:V1.0 10 | //版权所有,盗版必究。 11 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 12 | //All rights reserved 13 | ////////////////////////////////////////////////////////////////////////////////// 14 | 15 | //初始化PF9和PF10为输出口.并使能这两个口的时钟 16 | //LED IO初始化 17 | void LED_Init(void) 18 | { 19 | GPIO_InitTypeDef GPIO_InitStructure; 20 | 21 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//使能GPIOF时钟 22 | 23 | //GPIOF9,F10初始化设置 24 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; 25 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 26 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 27 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 28 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 29 | GPIO_Init(GPIOF, &GPIO_InitStructure);//初始化 30 | 31 | GPIO_SetBits(GPIOF,GPIO_Pin_9 | GPIO_Pin_10);//GPIOF9,F10设置高,灯灭 32 | 33 | } 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /HARDWARE/LED/led.h: -------------------------------------------------------------------------------- 1 | #ifndef __LED_H 2 | #define __LED_H 3 | #include "sys.h" 4 | 5 | ////////////////////////////////////////////////////////////////////////////////// 6 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 7 | //ALIENTEK STM32F407开发板 8 | //LED驱动代码 9 | //正点原子@ALIENTEK 10 | //技术论坛:www.openedv.com 11 | //创建日期:2014/5/2 12 | //版本:V1.0 13 | //版权所有,盗版必究。 14 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 15 | //All rights reserved 16 | ////////////////////////////////////////////////////////////////////////////////// 17 | 18 | 19 | //LED端口定义 20 | #define LED0 PFout(9) // DS0 21 | #define LED1 PFout(10) // DS1 22 | 23 | void LED_Init(void);//初始化 24 | #endif 25 | -------------------------------------------------------------------------------- /HARDWARE/TIMER/timer.c: -------------------------------------------------------------------------------- 1 | #include "timer.h" 2 | 3 | ////////////////////////////////////////////////////////////////////////////////// 4 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 5 | //ALIENTEK STM32F407开发板 6 | //定时器 驱动代码 7 | //正点原子@ALIENTEK 8 | //技术论坛:www.openedv.com 9 | //创建日期:2014/5/4 10 | //版本:V1.0 11 | //版权所有,盗版必究。 12 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 13 | //All rights reserved 14 | ////////////////////////////////////////////////////////////////////////////////// 15 | //通用定时器2中断初始化 16 | //arr:自动重装值。 17 | //psc:时钟预分频数 18 | //定时器溢出时间计算方法:Tout=((arr+1)*(psc+1))/Ft us. 19 | //Ft=定时器工作频率,单位:Mhz 20 | //这里使用的是定时器2! 21 | void TIM2_Int_Init(u16 arr,u16 psc) 22 | { 23 | TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; 24 | NVIC_InitTypeDef NVIC_InitStructure; 25 | 26 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); ///使能TIM2时钟 27 | 28 | TIM_TimeBaseInitStructure.TIM_Period = arr; //自动重装载值 29 | TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //定时器分频 30 | TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式 31 | TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; 32 | 33 | TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);//初始化TIM2 34 | 35 | TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); //允许定时器2更新中断 36 | TIM_Cmd(TIM2,ENABLE); //使能定时器2 37 | 38 | NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; //定时器2中断 39 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x00; //抢占优先级0 40 | NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00; //子优先级0 41 | NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; 42 | NVIC_Init(&NVIC_InitStructure); 43 | 44 | } 45 | 46 | void Time_Init(void) 47 | { 48 | TIM2_Int_Init(100-1,8400-1); 49 | } 50 | 51 | void Time_Enable(void) 52 | { 53 | TIM_Cmd(TIM2,ENABLE); 54 | } 55 | 56 | void Time_Disable(void) 57 | { 58 | TIM_Cmd(TIM2,DISABLE); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /HARDWARE/TIMER/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIMER_H 2 | #define _TIMER_H 3 | #include "sys.h" 4 | 5 | ////////////////////////////////////////////////////////////////////////////////// 6 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 7 | //ALIENTEK STM32F407开发板 8 | //定时器 驱动代码 9 | //正点原子@ALIENTEK 10 | //技术论坛:www.openedv.com 11 | //创建日期:2014/6/16 12 | //版本:V1.0 13 | //版权所有,盗版必究。 14 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 15 | //All rights reserved 16 | ////////////////////////////////////////////////////////////////////////////////// 17 | 18 | void Time_Init(void); 19 | void Time_Enable(void); 20 | void Time_Disable(void); 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /HARDWARE/TOUCH/rtouch.h: -------------------------------------------------------------------------------- 1 | #ifndef __TOUCH_H__ 2 | #define __TOUCH_H__ 3 | #include "sys.h" 4 | 5 | #define TP_PRES_DOWN 0x80 //触屏被按下 6 | #define TP_CATH_PRES 0x40 //有按键按下了 7 | #define CT_MAX_TOUCH 5 //电容屏支持的点数,固定为5点 8 | 9 | //触摸屏控制器 10 | typedef struct 11 | { 12 | u8 (*init)(void); //初始化触摸屏控制器 13 | u8 (*scan)(u8); //扫描触摸屏.0,屏幕扫描;1,物理坐标; 14 | void (*adjust)(void); //触摸屏校准 15 | u16 x[CT_MAX_TOUCH]; //当前坐标 16 | u16 y[CT_MAX_TOUCH]; //电容屏有最多5组坐标,电阻屏则用x[0],y[0]代表:此次扫描时,触屏的坐标,用 17 | //x[4],y[4]存储第一次按下时的坐标. 18 | u8 sta; //笔的状态 19 | //b7:按下1/松开0; 20 | //b6:0,没有按键按下;1,有按键按下. 21 | //b5:保留 22 | //b4~b0:电容触摸屏按下的点数(0,表示未按下,1表示按下) 23 | /////////////////////触摸屏校准参数(电容屏不需要校准)////////////////////// 24 | float xfac; 25 | float yfac; 26 | short xoff; 27 | short yoff; 28 | //新增的参数,当触摸屏的左右上下完全颠倒时需要用到. 29 | //b0:0,竖屏(适合左右为X坐标,上下为Y坐标的TP) 30 | // 1,横屏(适合左右为Y坐标,上下为X坐标的TP) 31 | //b1~6:保留. 32 | //b7:0,电阻屏 33 | // 1,电容屏 34 | u8 touchtype; 35 | }_m_tp_dev; 36 | 37 | extern _m_tp_dev tp_dev; //触屏控制器在touch.c里面定义 38 | 39 | //电阻屏芯片连接引脚 40 | #define PEN PBin(1) //T_PEN 41 | #define DOUT PBin(2) //T_MISO 42 | #define TDIN PFout(11) //T_MOSI 43 | #define TCLK PBout(0) //T_SCK 44 | #define TCS PCout(13) //T_CS 45 | 46 | //电阻屏函数 47 | void TP_Write_Byte(u8 num); //向控制芯片写入一个数据 48 | u16 TP_Read_AD(u8 CMD); //读取AD转换值 49 | u16 TP_Read_XOY(u8 xy); //带滤波的坐标读取(X/Y) 50 | u8 TP_Read_XY(u16 *x,u16 *y); //双方向读取(X+Y) 51 | u8 TP_Read_XY2(u16 *x,u16 *y); //带加强滤波的双方向坐标读取 52 | void TP_Drow_Touch_Point(u16 x,u16 y,u16 color);//画一个坐标校准点 53 | void TP_Draw_Big_Point(u16 x,u16 y,u16 color); //画一个大点 54 | u8 TP_Get_Adjdata(void); //读取校准参数 55 | void TP_Adjust(void); //触摸屏校准 56 | void TP_Adj_Info_Show(u16 x0,u16 y0,u16 x1,u16 y1,u16 x2,u16 y2,u16 x3,u16 y3,u16 fac);//显示校准信息 57 | //电阻屏/电容屏 共用函数 58 | u8 TP_Scan(u8 tp); //扫描 59 | u8 TP_Init(void); //初始化 60 | //UI函数 61 | void UI_Create(u16 x,u16 y,u16 sx,u16 sy,u8 *p,u8 num); 62 | //UI触摸函数 63 | u8 Touch_Scan(void); 64 | 65 | #endif 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 简易示波器 & 信号发生器 for 正点原子探索者 STM32F407 开发板 2 | 3 | ## 最初版本 4 | 5 | STM32F4 简易波形图显示 6 | 7 | ————小马哥————2018.3.14 --2018.3.16 8 | 9 | 内容:在显示屏上通过按键产生正弦波、三角波、矩形波、锯齿波,并且能通过按键来暂停波形,显示静态波形,并且显示波形电压的峰峰值。 10 | 11 | 一、波形图显示 12 | 13 | 1. 生成正弦波、三角波、矩形波、锯齿波数据 14 | 15 | 2. 将这些数据显示到 TFT 2.4 寸液晶屏上 16 | 17 | 思路:用数组 1,2,3,4 分别保存正弦波、三角波、矩形波、锯齿波数据,写按键函数分别打印不同的数组内容,然后再将数组内容打印到 TFT 液晶屏上。 18 | 19 | 二、峰峰值显示 20 | 21 | 从数组中采集最大和最小值,然后做差求得峰峰值,显示到 TFT 液晶屏上。 22 | 23 | 优化:使用 DMA 来减轻 CPU 的负担,提高数据传输速度。 24 | 25 | *STM32 使用 DMA+DAC+TIMER 输出正弦波* 26 | 27 | 那么对于使用 DMA+DAC+TIMER 产生正弦波的原理或过程,我有这样一个简单的理解:先将一个可以生成正弦波的数据表保存在静态内存中,然后在 DAC 以及这块内存中间使用 DMA 建立一个通道,经过以上步骤之后,DAC 模块就可以通过 DMA 通道拿取静态内存中可以生成正弦波的数据,拿取数据,然后经过数模准换,在引脚进行输出就可以得到正弦波了。那么当然,这个速度是非常快的,如果没有一定的延时,那么得到的估计就是一个变化很快的模拟量。所以这个时候就需要使用定时器 TIMER 了。DAC 在初始化的时候,可以设置成使用定时器触发,这就意味着,当定时器溢满的时候,就会触发 DAC 工作。这样一来,就可以通过改变定时器的定时时间来改变正弦波的周期了。电压大小的显示用 DAC 来处理。(PA4 和 PA5 短接,DAC 与 ADC 结合。) 28 | 29 | ## 修改 30 | 31 | 在网友代码的基础上增加了一个功能:按下黄色按键(KEY_UP,KEY_0,KEY_1,KEY_2),动态正弦波会暂停,按下红色按键(RESERT)动态波形重新显示。 32 | 33 | 操作:只需要在 HARDWARE 文件下添加 key.c 和 key.h 文件,再做修改即可。 34 | 35 | ## 再修改 36 | 37 | 把 DAC 头文件和源文件删除了,居然还有波形 38 | 39 | 为什么 DAC GPIO 配置 PIN4 或 PIN5: 40 | 41 | PA4:DAC 把正弦数字数据转化为模拟数据,把模拟数据给 PA5 42 | 43 | PA5:模拟量转化为数字量,生成波形和 Vpp 大小 44 | 45 | ## 第三次修改 46 | 47 | 基本完成四种波形的 run 和 stop,~~但无法完成在暂停键按下去之后,按其他的按键可以直接跳转到那个按键对应的波形~~。 48 | -------------------------------------------------------------------------------- /SYSTEM/delay/delay.c: -------------------------------------------------------------------------------- 1 | #include "delay.h" 2 | #include "sys.h" 3 | ////////////////////////////////////////////////////////////////////////////////// 4 | //如果使用OS,则包括下面的头文件(以ucos为例)即可. 5 | #if SYSTEM_SUPPORT_OS 6 | #include "includes.h" //支持OS时,使用 7 | #endif 8 | ////////////////////////////////////////////////////////////////////////////////// 9 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 10 | //ALIENTEK STM32F407开发板 11 | //使用SysTick的普通计数模式对延迟进行管理(支持OS) 12 | //包括delay_us,delay_ms 13 | //正点原子@ALIENTEK 14 | //技术论坛:www.openedv.com 15 | //创建日期:2014/5/2 16 | //版本:V1.3 17 | //版权所有,盗版必究。 18 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 19 | //All rights reserved 20 | //******************************************************************************** 21 | //修改说明 22 | //V1.1 20140803 23 | //1,delay_us,添加参数等于0判断,如果参数等于0,则直接退出. 24 | //2,修改ucosii下,delay_ms函数,加入OSLockNesting的判断,在进入中断后,也可以准确延时. 25 | //V1.2 20150411 26 | //修改OS支持方式,以支持任意OS(不限于UCOSII和UCOSIII,理论上任意OS都可以支持) 27 | //添加:delay_osrunning/delay_ostickspersec/delay_osintnesting三个宏定义 28 | //添加:delay_osschedlock/delay_osschedunlock/delay_ostimedly三个函数 29 | //V1.3 20150521 30 | //修正UCOSIII支持时的2个bug: 31 | //delay_tickspersec改为:delay_ostickspersec 32 | //delay_intnesting改为:delay_osintnesting 33 | ////////////////////////////////////////////////////////////////////////////////// 34 | 35 | static u8 fac_us=0; //us延时倍乘数 36 | static u16 fac_ms=0; //ms延时倍乘数,在os下,代表每个节拍的ms数 37 | 38 | #if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS定义了,说明要支持OS了(不限于UCOS). 39 | //当delay_us/delay_ms需要支持OS的时候需要三个与OS相关的宏定义和函数来支持 40 | //首先是3个宏定义: 41 | // delay_osrunning:用于表示OS当前是否正在运行,以决定是否可以使用相关函数 42 | //delay_ostickspersec:用于表示OS设定的时钟节拍,delay_init将根据这个参数来初始哈systick 43 | // delay_osintnesting:用于表示OS中断嵌套级别,因为中断里面不可以调度,delay_ms使用该参数来决定如何运行 44 | //然后是3个函数: 45 | // delay_osschedlock:用于锁定OS任务调度,禁止调度 46 | //delay_osschedunlock:用于解锁OS任务调度,重新开启调度 47 | // delay_ostimedly:用于OS延时,可以引起任务调度. 48 | 49 | //本例程仅作UCOSII和UCOSIII的支持,其他OS,请自行参考着移植 50 | //支持UCOSII 51 | #ifdef OS_CRITICAL_METHOD //OS_CRITICAL_METHOD定义了,说明要支持UCOSII 52 | #define delay_osrunning OSRunning //OS是否运行标记,0,不运行;1,在运行 53 | #define delay_ostickspersec OS_TICKS_PER_SEC //OS时钟节拍,即每秒调度次数 54 | #define delay_osintnesting OSIntNesting //中断嵌套级别,即中断嵌套次数 55 | #endif 56 | 57 | //支持UCOSIII 58 | #ifdef CPU_CFG_CRITICAL_METHOD //CPU_CFG_CRITICAL_METHOD定义了,说明要支持UCOSIII 59 | #define delay_osrunning OSRunning //OS是否运行标记,0,不运行;1,在运行 60 | #define delay_ostickspersec OSCfg_TickRate_Hz //OS时钟节拍,即每秒调度次数 61 | #define delay_osintnesting OSIntNestingCtr //中断嵌套级别,即中断嵌套次数 62 | #endif 63 | 64 | 65 | //us级延时时,关闭任务调度(防止打断us级延迟) 66 | void delay_osschedlock(void) 67 | { 68 | #ifdef CPU_CFG_CRITICAL_METHOD //使用UCOSIII 69 | OS_ERR err; 70 | OSSchedLock(&err); //UCOSIII的方式,禁止调度,防止打断us延时 71 | #else //否则UCOSII 72 | OSSchedLock(); //UCOSII的方式,禁止调度,防止打断us延时 73 | #endif 74 | } 75 | 76 | //us级延时时,恢复任务调度 77 | void delay_osschedunlock(void) 78 | { 79 | #ifdef CPU_CFG_CRITICAL_METHOD //使用UCOSIII 80 | OS_ERR err; 81 | OSSchedUnlock(&err); //UCOSIII的方式,恢复调度 82 | #else //否则UCOSII 83 | OSSchedUnlock(); //UCOSII的方式,恢复调度 84 | #endif 85 | } 86 | 87 | //调用OS自带的延时函数延时 88 | //ticks:延时的节拍数 89 | void delay_ostimedly(u32 ticks) 90 | { 91 | #ifdef CPU_CFG_CRITICAL_METHOD 92 | OS_ERR err; 93 | OSTimeDly(ticks,OS_OPT_TIME_PERIODIC,&err);//UCOSIII延时采用周期模式 94 | #else 95 | OSTimeDly(ticks); //UCOSII延时 96 | #endif 97 | } 98 | 99 | //systick中断服务函数,使用OS时用到 100 | void SysTick_Handler(void) 101 | { 102 | if(delay_osrunning==1) //OS开始跑了,才执行正常的调度处理 103 | { 104 | OSIntEnter(); //进入中断 105 | OSTimeTick(); //调用ucos的时钟服务程序 106 | OSIntExit(); //触发任务切换软中断 107 | } 108 | } 109 | #endif 110 | 111 | //初始化延迟函数 112 | //当使用OS的时候,此函数会初始化OS的时钟节拍 113 | //SYSTICK的时钟固定为AHB时钟的1/8 114 | //SYSCLK:系统时钟频率 115 | void delay_init(u8 SYSCLK) 116 | { 117 | #if SYSTEM_SUPPORT_OS //如果需要支持OS. 118 | u32 reload; 119 | #endif 120 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 121 | fac_us=SYSCLK/8; //不论是否使用OS,fac_us都需要使用 122 | #if SYSTEM_SUPPORT_OS //如果需要支持OS. 123 | reload=SYSCLK/8; //每秒钟的计数次数 单位为M 124 | reload*=1000000/delay_ostickspersec; //根据delay_ostickspersec设定溢出时间 125 | //reload为24位寄存器,最大值:16777216,在168M下,约合0.7989s左右 126 | fac_ms=1000/delay_ostickspersec; //代表OS可以延时的最少单位 127 | SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk; //开启SYSTICK中断 128 | SysTick->LOAD=reload; //每1/delay_ostickspersec秒中断一次 129 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //开启SYSTICK 130 | #else 131 | fac_ms=(u16)fac_us*1000; //非OS下,代表每个ms需要的systick时钟数 132 | #endif 133 | } 134 | 135 | #if SYSTEM_SUPPORT_OS //如果需要支持OS. 136 | //延时nus 137 | //nus:要延时的us数. 138 | //nus:0~204522252(最大值即2^32/fac_us@fac_us=21) 139 | void delay_us(u32 nus) 140 | { 141 | u32 ticks; 142 | u32 told,tnow,tcnt=0; 143 | u32 reload=SysTick->LOAD; //LOAD的值 144 | ticks=nus*fac_us; //需要的节拍数 145 | delay_osschedlock(); //阻止OS调度,防止打断us延时 146 | told=SysTick->VAL; //刚进入时的计数器值 147 | while(1) 148 | { 149 | tnow=SysTick->VAL; 150 | if(tnow!=told) 151 | { 152 | if(tnow=ticks)break; //时间超过/等于要延迟的时间,则退出. 156 | } 157 | }; 158 | delay_osschedunlock(); //恢复OS调度 159 | } 160 | //延时nms 161 | //nms:要延时的ms数 162 | //nms:0~65535 163 | void delay_ms(u16 nms) 164 | { 165 | if(delay_osrunning&&delay_osintnesting==0)//如果OS已经在跑了,并且不是在中断里面(中断里面不能任务调度) 166 | { 167 | if(nms>=fac_ms) //延时的时间大于OS的最少时间周期 168 | { 169 | delay_ostimedly(nms/fac_ms); //OS延时 170 | } 171 | nms%=fac_ms; //OS已经无法提供这么小的延时了,采用普通方式延时 172 | } 173 | delay_us((u32)(nms*1000)); //普通方式延时 174 | } 175 | #else //不用ucos时 176 | //延时nus 177 | //nus为要延时的us数. 178 | //注意:nus的值,不要大于798915us(最大值即2^24/fac_us@fac_us=21) 179 | void delay_us(u32 nus) 180 | { 181 | u32 temp; 182 | SysTick->LOAD=nus*fac_us; //时间加载 183 | SysTick->VAL=0x00; //清空计数器 184 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 185 | do 186 | { 187 | temp=SysTick->CTRL; 188 | }while((temp&0x01)&&!(temp&(1<<16))); //等待时间到达 189 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器 190 | SysTick->VAL =0X00; //清空计数器 191 | } 192 | //延时nms 193 | //注意nms的范围 194 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 195 | //nms<=0xffffff*8*1000/SYSCLK 196 | //SYSCLK单位为Hz,nms单位为ms 197 | //对168M条件下,nms<=798ms 198 | void delay_xms(u16 nms) 199 | { 200 | u32 temp; 201 | SysTick->LOAD=(u32)nms*fac_ms; //时间加载(SysTick->LOAD为24bit) 202 | SysTick->VAL =0x00; //清空计数器 203 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 204 | do 205 | { 206 | temp=SysTick->CTRL; 207 | }while((temp&0x01)&&!(temp&(1<<16))); //等待时间到达 208 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器 209 | SysTick->VAL =0X00; //清空计数器 210 | } 211 | //延时nms 212 | //nms:0~65535 213 | void delay_ms(u16 nms) 214 | { 215 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 216 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 217 | u16 remain=nms%540; 218 | while(repeat) 219 | { 220 | delay_xms(540); 221 | repeat--; 222 | } 223 | if(remain)delay_xms(remain); 224 | } 225 | #endif 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /SYSTEM/delay/delay.h: -------------------------------------------------------------------------------- 1 | #ifndef __DELAY_H 2 | #define __DELAY_H 3 | #include 4 | ////////////////////////////////////////////////////////////////////////////////// 5 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 6 | //ALIENTEK STM32F407开发板 7 | //使用SysTick的普通计数模式对延迟进行管理(支持ucosii) 8 | //包括delay_us,delay_ms 9 | //正点原子@ALIENTEK 10 | //技术论坛:www.openedv.com 11 | //修改日期:2014/5/2 12 | //版本:V1.0 13 | //版权所有,盗版必究。 14 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 15 | //All rights reserved 16 | //******************************************************************************** 17 | //修改说明 18 | //无 19 | ////////////////////////////////////////////////////////////////////////////////// 20 | void delay_init(u8 SYSCLK); 21 | void delay_ms(u16 nms); 22 | void delay_us(u32 nus); 23 | 24 | #endif 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /SYSTEM/sys/sys.c: -------------------------------------------------------------------------------- 1 | #include "sys.h" 2 | ////////////////////////////////////////////////////////////////////////////////// 3 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 4 | //ALIENTEK STM32F407开发板 5 | //系统时钟初始化 6 | //包括时钟设置/中断管理/GPIO设置等 7 | //正点原子@ALIENTEK 8 | //技术论坛:www.openedv.com 9 | //创建日期:2014/5/2 10 | //版本:V1.0 11 | //版权所有,盗版必究。 12 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 13 | //All rights reserved 14 | //******************************************************************************** 15 | //修改说明 16 | //无 17 | ////////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | //THUMB指令不支持汇编内联 21 | //采用如下方法实现执行汇编指令WFI 22 | __asm void WFI_SET(void) 23 | { 24 | WFI; 25 | } 26 | //关闭所有中断(但是不包括fault和NMI中断) 27 | __asm void INTX_DISABLE(void) 28 | { 29 | CPSID I 30 | BX LR 31 | } 32 | //开启所有中断 33 | __asm void INTX_ENABLE(void) 34 | { 35 | CPSIE I 36 | BX LR 37 | } 38 | //设置栈顶地址 39 | //addr:栈顶地址 40 | __asm void MSR_MSP(u32 addr) 41 | { 42 | MSR MSP, r0 //set Main Stack value 43 | BX r14 44 | } 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /SYSTEM/sys/sys.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYS_H 2 | #define __SYS_H 3 | #include "stm32f4xx.h" 4 | ////////////////////////////////////////////////////////////////////////////////// 5 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 6 | //ALIENTEK STM32F407开发板 7 | //系统时钟初始化 8 | //正点原子@ALIENTEK 9 | //技术论坛:www.openedv.com 10 | //创建日期:2014/5/2 11 | //版本:V1.0 12 | //版权所有,盗版必究。 13 | //Copyright(C) 广州市星翼电子科技有限公司 2014-2024 14 | //All rights reserved 15 | //******************************************************************************** 16 | //修改说明 17 | //无 18 | ////////////////////////////////////////////////////////////////////////////////// 19 | 20 | 21 | //0,不支持ucos 22 | //1,支持ucos 23 | #define SYSTEM_SUPPORT_OS 0 //定义系统文件夹是否支持UCOS 24 | 25 | 26 | //位带操作,实现51类似的GPIO控制功能 27 | //具体实现思想,参考<>第五章(87页~92页).M4同M3类似,只是寄存器地址变了. 28 | //IO口操作宏定义 29 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 30 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 31 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 32 | //IO口地址映射 33 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 34 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 35 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 36 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 37 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 38 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 39 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 40 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 41 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 42 | 43 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 44 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 45 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 46 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 47 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 48 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 49 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 50 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 51 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 52 | 53 | //IO口操作,只对单一的IO口! 54 | //确保n的值小于16! 55 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 56 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 57 | 58 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 59 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 60 | 61 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 62 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 63 | 64 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 65 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 66 | 67 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 68 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 69 | 70 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 71 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 72 | 73 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 74 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 75 | 76 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 77 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 78 | 79 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 80 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 81 | 82 | //以下为汇编函数 83 | void WFI_SET(void); //执行WFI指令 84 | void INTX_DISABLE(void);//关闭所有中断 85 | void INTX_ENABLE(void); //开启所有中断 86 | void MSR_MSP(u32 addr); //设置堆栈地址 87 | #endif 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /SYSTEM/usart/usart.c: -------------------------------------------------------------------------------- 1 | #include "sys.h" 2 | #include "usart.h" 3 | ////////////////////////////////////////////////////////////////////////////////// 4 | //如果使用ucos,则包括下面的头文件即可. 5 | #if SYSTEM_SUPPORT_OS 6 | #include "includes.h" //ucos 使用 7 | #endif 8 | ////////////////////////////////////////////////////////////////////////////////// 9 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 10 | //ALIENTEK STM32F4探索者开发板 11 | //串口1初始化 12 | //正点原子@ALIENTEK 13 | //技术论坛:www.openedv.com 14 | //修改日期:2014/6/10 15 | //版本:V1.5 16 | //版权所有,盗版必究。 17 | //Copyright(C) 广州市星翼电子科技有限公司 2009-2019 18 | //All rights reserved 19 | //******************************************************************************** 20 | //V1.3修改说明 21 | //支持适应不同频率下的串口波特率设置. 22 | //加入了对printf的支持 23 | //增加了串口接收命令功能. 24 | //修正了printf第一个字符丢失的bug 25 | //V1.4修改说明 26 | //1,修改串口初始化IO的bug 27 | //2,修改了USART_RX_STA,使得串口最大接收字节数为2的14次方 28 | //3,增加了USART_REC_LEN,用于定义串口最大允许接收的字节数(不大于2的14次方) 29 | //4,修改了EN_USART1_RX的使能方式 30 | //V1.5修改说明 31 | //1,增加了对UCOSII的支持 32 | ////////////////////////////////////////////////////////////////////////////////// 33 | 34 | 35 | ////////////////////////////////////////////////////////////////// 36 | //加入以下代码,支持printf函数,而不需要选择use MicroLIB 37 | #if 1 38 | #pragma import(__use_no_semihosting) 39 | //标准库需要的支持函数 40 | struct __FILE 41 | { 42 | int handle; 43 | }; 44 | 45 | FILE __stdout; 46 | //定义_sys_exit()以避免使用半主机模式 47 | void _sys_exit(int x) 48 | { 49 | x = x; 50 | } 51 | //重定义fputc函数 52 | int fputc(int ch, FILE *f) 53 | { 54 | while((USART1->SR&0X40)==0);//循环发送,直到发送完毕 55 | USART1->DR = (u8) ch; 56 | return ch; 57 | } 58 | #endif 59 | 60 | #if EN_USART1_RX //如果使能了接收 61 | //串口1中断服务程序 62 | //注意,读取USARTx->SR能避免莫名其妙的错误 63 | u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节. 64 | //接收状态 65 | //bit15, 接收完成标志 66 | //bit14, 接收到0x0d 67 | //bit13~0, 接收到的有效字节数目 68 | u16 USART_RX_STA=0; //接收状态标记 69 | 70 | //初始化IO 串口1 71 | //bound:波特率 72 | void uart_init(u32 bound){ 73 | //GPIO端口设置 74 | GPIO_InitTypeDef GPIO_InitStructure; 75 | USART_InitTypeDef USART_InitStructure; 76 | NVIC_InitTypeDef NVIC_InitStructure; 77 | 78 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //使能GPIOA时钟 79 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//使能USART1时钟 80 | 81 | //串口1对应引脚复用映射 82 | GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9复用为USART1 83 | GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10复用为USART1 84 | 85 | //USART1端口配置 86 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; //GPIOA9与GPIOA10 87 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能 88 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度50MHz 89 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出 90 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉 91 | GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA9,PA10 92 | 93 | //USART1 初始化设置 94 | USART_InitStructure.USART_BaudRate = bound;//波特率设置 95 | USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式 96 | USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位 97 | USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位 98 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制 99 | USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式 100 | USART_Init(USART1, &USART_InitStructure); //初始化串口1 101 | 102 | USART_Cmd(USART1, ENABLE); //使能串口1 103 | 104 | //USART_ClearFlag(USART1, USART_FLAG_TC); 105 | 106 | #if EN_USART1_RX 107 | USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启相关中断 108 | 109 | //Usart1 NVIC 配置 110 | NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//串口1中断通道 111 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//抢占优先级3 112 | NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //子优先级3 113 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 114 | NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器、 115 | 116 | #endif 117 | 118 | } 119 | 120 | 121 | void USART1_IRQHandler(void) //串口1中断服务程序 122 | { 123 | u8 Res; 124 | #if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS. 125 | OSIntEnter(); 126 | #endif 127 | if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾) 128 | { 129 | Res =USART_ReceiveData(USART1);//(USART1->DR); //读取接收到的数据 130 | 131 | if((USART_RX_STA&0x8000)==0)//接收未完成 132 | { 133 | if(USART_RX_STA&0x4000)//接收到了0x0d 134 | { 135 | if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始 136 | else USART_RX_STA|=0x8000; //接收完成了 137 | } 138 | else //还没收到0X0D 139 | { 140 | if(Res==0x0d)USART_RX_STA|=0x4000; 141 | else 142 | { 143 | USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ; 144 | USART_RX_STA++; 145 | if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//接收数据错误,重新开始接收 146 | } 147 | } 148 | } 149 | } 150 | #if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS. 151 | OSIntExit(); 152 | #endif 153 | } 154 | #endif 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /SYSTEM/usart/usart.h: -------------------------------------------------------------------------------- 1 | #ifndef __USART_H 2 | #define __USART_H 3 | #include "stdio.h" 4 | #include "stm32f4xx_conf.h" 5 | #include "sys.h" 6 | ////////////////////////////////////////////////////////////////////////////////// 7 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 8 | //Mini STM32开发板 9 | //串口1初始化 10 | //正点原子@ALIENTEK 11 | //技术论坛:www.openedv.csom 12 | //修改日期:2011/6/14 13 | //版本:V1.4 14 | //版权所有,盗版必究。 15 | //Copyright(C) 正点原子 2009-2019 16 | //All rights reserved 17 | //******************************************************************************** 18 | //V1.3修改说明 19 | //支持适应不同频率下的串口波特率设置. 20 | //加入了对printf的支持 21 | //增加了串口接收命令功能. 22 | //修正了printf第一个字符丢失的bug 23 | //V1.4修改说明 24 | //1,修改串口初始化IO的bug 25 | //2,修改了USART_RX_STA,使得串口最大接收字节数为2的14次方 26 | //3,增加了USART_REC_LEN,用于定义串口最大允许接收的字节数(不大于2的14次方) 27 | //4,修改了EN_USART1_RX的使能方式 28 | ////////////////////////////////////////////////////////////////////////////////// 29 | #define USART_REC_LEN 200 //定义最大接收字节数 200 30 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 31 | 32 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 33 | extern u16 USART_RX_STA; //接收状态标记 34 | //如果想串口中断接收,请不要注释以下宏定义 35 | void uart_init(u32 bound); 36 | #endif 37 | 38 | 39 | -------------------------------------------------------------------------------- /USER/JLinkSettings.ini: -------------------------------------------------------------------------------- 1 | [BREAKPOINTS] 2 | ShowInfoWin = 1 3 | EnableFlashBP = 2 4 | BPDuringExecution = 0 5 | [CFI] 6 | CFISize = 0x00 7 | CFIAddr = 0x00 8 | [CPU] 9 | OverrideMemMap = 0 10 | AllowSimulation = 1 11 | ScriptFile="" 12 | [FLASH] 13 | CacheExcludeSize = 0x00 14 | CacheExcludeAddr = 0x00 15 | MinNumBytesFlashDL = 0 16 | SkipProgOnCRCMatch = 1 17 | VerifyDownload = 1 18 | AllowCaching = 1 19 | EnableFlashDL = 2 20 | Override = 0 21 | Device="UNSPECIFIED" 22 | [GENERAL] 23 | WorkRAMSize = 0x00 24 | WorkRAMAddr = 0x00 25 | RAMUsageLimit = 0x00 26 | [SWO] 27 | SWOLogFile="" 28 | [MEM] 29 | RdOverrideOrMask = 0x00 30 | RdOverrideAndMask = 0xFFFFFFFF 31 | RdOverrideAddr = 0xFFFFFFFF 32 | WrOverrideOrMask = 0x00 33 | WrOverrideAndMask = 0xFFFFFFFF 34 | WrOverrideAddr = 0xFFFFFFFF 35 | -------------------------------------------------------------------------------- /USER/main.c: -------------------------------------------------------------------------------- 1 | //STM32 使用DMA+DAC+TIMER输出正弦波// 2 | 3 | /* 4 | 5 | 那么对于使用DMA+DAC+TIMER产生正弦波的原理或过程,我有这样一个简单的理解: 6 | 先将一个可以生成正弦波的数据表保存在静态内存中,然后在DAC以及这块内存中间使 7 | 用DMA建立一个通道,经过以上步骤之后,DAC模块就可以通过DMA通道拿取静态内存中 8 | 可以生成正弦波的数据,拿取数据,然后经过数模准换,在引脚进行输出就可以得到正 9 | 弦波了。那么当然,这个速度是非常快的,如果没有一定的延时,那么得到的估计就是 10 | 一个变化很快的模拟量。所以这个时候就需要使用定时器TIMER了。DAC在初始化的时候, 11 | 可以设置成使用定时器触发,这就意味着,当定时器溢满的时候,就会触发DAC工作。 12 | 这样一来,就可以通过改变定时器的定时时间来改变正弦波的周期了。 13 | 14 | 电压大小的显示用DAC来处理 15 | */ 16 | 17 | #include "sys.h" 18 | #include "delay.h" 19 | #include "usart.h" 20 | #include "led.h" 21 | #include "lcd.h" 22 | #include "beep.h" 23 | //#include "dac.h" 24 | #include "adc.h" 25 | #include "waveform.h" 26 | #include "timer.h" 27 | #include "stm32f4xx_it.h" 28 | #include "key.h" 29 | #include "stm32f4xx.h" // Device header 30 | //void touch_task(void); //触摸功能,可添加,这里只有TFTLCD所以不用 31 | void clear_point(u16 num); //更新显示屏当前列 32 | void Set_BackGround(void); //设置背景 33 | void Lcd_DrawNetwork(void); //画网格 34 | float get_vpp(u16 *buf); //获取峰峰值 35 | void DrawOscillogram(u16 *buf); //画波形图 36 | 37 | void sin_Generation(void); 38 | void sawtooth_Generation(void); 39 | void triangle_Generation(void); 40 | void rectangle_Generation(void); 41 | 42 | u32 max_data; 43 | u16 position = 200; //波形图中心轴 44 | u8 num = 0; 45 | //u8 runstop = 1; 46 | 47 | int main(void) 48 | { 49 | u16 buff[800]; 50 | float Adresult = 0; 51 | u8 Vpp_buff[20] = {0}; 52 | u8 key = 0; 53 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置系统中断优先级分组2 54 | delay_init(168); //初始化延时函数 55 | uart_init(115200); //初始化串口波特率为115200 56 | LED_Init(); //初始化LED 57 | BEEP_Init(); //初始化蜂鸣器端口 58 | LCD_Init(); //初始化LCD FSMC接口 59 | Adc_Init(); //初始化ADC 60 | Set_BackGround(); //显示背景 61 | Lcd_DrawNetwork(); 62 | KEY_Init(); 63 | LED0 = 0; 64 | MYDAC_Init(); 65 | 66 | while (1) 67 | { 68 | //void touch_task(void); 69 | DrawOscillogram(buff); //画波形 70 | Adresult = get_vpp(buff); //峰峰值mv 71 | sprintf((char *)Vpp_buff, "Vpp = %0.3fV", Adresult); 72 | POINT_COLOR = WHITE; 73 | BACK_COLOR = DARKBLUE; 74 | //LCD_ShowString(156,201,66,12,12,Vpp_buff); 75 | LCD_ShowString(330, 425, 210, 24, 24, Vpp_buff); 76 | //runstop=KEY_Scan(0); 77 | // if(runstop==1){ 78 | POINT_COLOR = WHITE; 79 | //LCD_ShowString(258,0,288,29,12,"STOP"); 80 | LCD_ShowString(600, 425, 288, 29, 24, "STOP"); 81 | POINT_COLOR = YELLOW; 82 | //LCD_ShowString(289,0,319,29,12,"RUN"); 83 | LCD_ShowString(665, 425, 319, 29, 24, "RUN"); 84 | LED0 = !LED0; //} 85 | //else if(runstop==0) 86 | //{ 87 | // POINT_COLOR = YELLOW; 88 | // LCD_ShowString(258,0,288,29,12,"STOP"); 89 | // LCD_ShowString(289,0,319,29,12,"RUN"); 90 | //} 91 | 92 | key = KEY_Scan(0); //得到键值 93 | if (key) 94 | { 95 | switch (key) 96 | { 97 | case WKUP_PRES: 98 | sin_Generation(); 99 | BEEP = 1; 100 | delay_ms(100); 101 | BEEP = 0; 102 | break; 103 | // case KEY0_PRES: 104 | // runstop=0; 105 | // break; 106 | case KEY1_PRES: 107 | triangle_Generation(); 108 | BEEP = 1; 109 | delay_ms(100); 110 | BEEP = 0; 111 | break; 112 | case KEY2_PRES: 113 | sawtooth_Generation(); 114 | BEEP = 1; 115 | delay_ms(100); 116 | BEEP = 0; 117 | break; 118 | } 119 | } 120 | else if (key == KEY0_PRES) 121 | { 122 | BEEP = 1; 123 | delay_ms(100); 124 | BEEP = 0; 125 | do 126 | { 127 | //runstop=0; 128 | //void DrawOscillogram(u16* buf); 129 | POINT_COLOR = YELLOW; 130 | //LCD_ShowString(258,0,288,29,12,"STOP"); 131 | LCD_ShowString(600, 425, 288, 29, 24, "STOP"); 132 | POINT_COLOR = WHITE; 133 | //LCD_ShowString(289,0,319,29,12,"RUN"); 134 | LCD_ShowString(665, 425, 319, 29, 24, "RUN"); 135 | key = KEY_Scan(0); 136 | if (key == 0 || key == 2 || key == 3 || key == 4) 137 | { 138 | BEEP = 1; 139 | delay_ms(100); 140 | BEEP = 0; 141 | switch (key) 142 | { 143 | case WKUP_PRES: 144 | sin_Generation(); 145 | break; 146 | case KEY1_PRES: 147 | triangle_Generation(); 148 | break; 149 | case KEY2_PRES: 150 | sawtooth_Generation(); 151 | break; 152 | } 153 | break; 154 | } 155 | } while (1); 156 | } 157 | } 158 | } 159 | 160 | void clear_point(u16 num) //更新显示屏当前列 161 | { 162 | u16 lie = 0; 163 | POINT_COLOR = DARKBLUE; 164 | for (lie = 1; lie < 400; lie++) 165 | { 166 | LCD_DrawPoint(num, lie); 167 | } 168 | if (!(num % 50)) //判断hang是否为50的倍数 画列点 169 | { 170 | for (lie = 10; lie < 400; lie += 10) 171 | { 172 | LCD_Fast_DrawPoint(num, lie, WHITE); 173 | } 174 | } 175 | if (!(num % 10)) //判断hang是否为10的倍数 画行点 176 | { 177 | for (lie = 50; lie < 400; lie += 50) 178 | { 179 | LCD_Fast_DrawPoint(num, lie, WHITE); 180 | } 181 | } 182 | POINT_COLOR = YELLOW; 183 | } 184 | 185 | void DrawOscillogram(u16 *buff) //画波形图 186 | { 187 | //runstop = KEY_Scan(0); 188 | 189 | //if (runstop == 1 | runstop == 2 | runstop == 3 | runstop == 4) //画正弦波 190 | //{ 191 | static u16 Ypos1 = 0, Ypos2 = 0; 192 | u16 i = 0; 193 | for (i = 1; i < 700; i++) //存储AD数值 194 | { 195 | buff[i] = Get_Adc(ADC_Channel_5); 196 | // delay_us(1); 197 | } 198 | for (i = 1; i < 700; i++) 199 | { 200 | clear_point(i); 201 | Ypos2 = position - (buff[i] * 165 / 4096); //转换坐标//4096 202 | Ypos2 = Ypos2 * 2; //纵坐标倍数 203 | if (Ypos2 > 400) 204 | Ypos2 = 400; //超出范围不显示 205 | LCD_DrawLine(i, Ypos1, i + 1, Ypos2); //波形连接 206 | Ypos1 = Ypos2; 207 | } 208 | Ypos1 = 0; 209 | //} 210 | 211 | // else if(runstop==0)//暂停动态显示 212 | // { 213 | // do 214 | // { 215 | //// u8 a=0; 216 | // runstop = KEY_Scan(0); 217 | // POINT_COLOR = YELLOW; 218 | // LCD_ShowString(258,0,288,29,12,"STOP"); 219 | // POINT_COLOR = WHITE; 220 | // LCD_ShowString(289,0,319,29,12,"RUN"); 221 | // //runstop=1; 222 | // if( runstop == 2|runstop==3|runstop==4 ) break; 223 | // } 224 | // while(1); 225 | // } 226 | 227 | //else if (runstop == 2) 228 | //{ 229 | // static u16 Ypos1 = 0,Ypos2 = 0; 230 | // u16 i = 0; 231 | // for(i = 1;i < 255;i++)//存储AD数值 232 | // { 233 | // buff[i]=Get_Adc(ADC_Channel_5); 234 | //// delay_us(1); 235 | // } 236 | // for(i = 1;i < 255;i++) 237 | // { 238 | // clear_point(i); 239 | // Ypos2 = position - ( buff[i] * 165 / 4096);//转换坐标//4096 240 | // if(Ypos2 >255) 241 | // Ypos2 =255; //超出范围不显示 242 | // LCD_DrawLine (i ,Ypos1 , i+1 ,Ypos2);//波形连接 243 | // Ypos1 = Ypos2 ; 244 | // } 245 | // Ypos1 = 0; 246 | //} 247 | 248 | //else if (runstop == 3) 249 | //{ 250 | //} 251 | 252 | //else if (runstop == 4) 253 | //{ 254 | //} 255 | } 256 | void Set_BackGround(void) 257 | { 258 | LCD_Clear(DARKBLUE); 259 | POINT_COLOR = WHITE; 260 | LCD_DrawRectangle(0, 0, 700, 400); 261 | // POINT_COLOR = WHITE; 262 | // LCD_ShowString(258,0,288,29,12,"STOP"); 263 | // LCD_ShowString(289,0,319,29,12,"RUN"); 264 | } 265 | 266 | void Lcd_DrawNetwork(void) 267 | { 268 | u16 index_y = 0; 269 | u16 index_x = 0; 270 | //POINT_COLOR = WHITE; 271 | //LCD_DrawRectangle(258,0,288,29); 272 | //POINT_COLOR = WHITE; 273 | //LCD_DrawRectangle(289,0,319,29); 274 | //画列点 275 | for (index_x = 50; index_x < 700; index_x += 50) 276 | { 277 | for (index_y = 10; index_y < 400; index_y += 10) 278 | { 279 | LCD_Fast_DrawPoint(index_x, index_y, WHITE); 280 | } 281 | } 282 | //画行点 283 | for (index_y = 50; index_y < 400; index_y += 50) 284 | { 285 | for (index_x = 10; index_x < 700; index_x += 10) 286 | { 287 | LCD_Fast_DrawPoint(index_x, index_y, WHITE); 288 | } 289 | } 290 | } 291 | 292 | float get_vpp(u16 *buf) //获取峰峰值 293 | { 294 | 295 | u32 max_data = buf[0]; 296 | u32 min_data = buf[0]; 297 | u32 n = 0; 298 | float Vpp = 0; 299 | for (n = 1; n < 256; n++) 300 | { 301 | if (buf[n] > max_data) 302 | { 303 | max_data = buf[n]; 304 | } 305 | else if (buf[n] < min_data) 306 | min_data = buf[n]; 307 | } 308 | Vpp = (float)(max_data - min_data); 309 | Vpp = Vpp * (3.3 / 4096); 310 | max_data = max_data * (3.3 / 4096); 311 | min_data = min_data * (3.3 / 4096); 312 | return Vpp; 313 | } 314 | -------------------------------------------------------------------------------- /USER/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasongzy/stm32f407-oscilloscope/de624938735230a026de1f4115cfac8f1473dcc3/USER/stm32f4xx.h -------------------------------------------------------------------------------- /USER/stm32f4xx_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_conf.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 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 __STM32F4xx_CONF_H 30 | #define __STM32F4xx_CONF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Uncomment the line below to enable peripheral header file inclusion */ 34 | #include "stm32f4xx_adc.h" 35 | #include "stm32f4xx_crc.h" 36 | #include "stm32f4xx_dbgmcu.h" 37 | #include "stm32f4xx_dma.h" 38 | #include "stm32f4xx_exti.h" 39 | #include "stm32f4xx_flash.h" 40 | #include "stm32f4xx_gpio.h" 41 | #include "stm32f4xx_i2c.h" 42 | #include "stm32f4xx_iwdg.h" 43 | #include "stm32f4xx_pwr.h" 44 | #include "stm32f4xx_rcc.h" 45 | #include "stm32f4xx_rtc.h" 46 | #include "stm32f4xx_sdio.h" 47 | #include "stm32f4xx_spi.h" 48 | #include "stm32f4xx_syscfg.h" 49 | #include "stm32f4xx_tim.h" 50 | #include "stm32f4xx_usart.h" 51 | #include "stm32f4xx_wwdg.h" 52 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 53 | 54 | #if defined (STM32F429_439xx) 55 | #include "stm32f4xx_cryp.h" 56 | #include "stm32f4xx_hash.h" 57 | #include "stm32f4xx_rng.h" 58 | #include "stm32f4xx_can.h" 59 | #include "stm32f4xx_dac.h" 60 | #include "stm32f4xx_dcmi.h" 61 | #include "stm32f4xx_dma2d.h" 62 | #include "stm32f4xx_fmc.h" 63 | #include "stm32f4xx_ltdc.h" 64 | #include "stm32f4xx_sai.h" 65 | #endif /* STM32F429_439xx */ 66 | 67 | #if defined (STM32F427_437xx) 68 | #include "stm32f4xx_cryp.h" 69 | #include "stm32f4xx_hash.h" 70 | #include "stm32f4xx_rng.h" 71 | #include "stm32f4xx_can.h" 72 | #include "stm32f4xx_dac.h" 73 | #include "stm32f4xx_dcmi.h" 74 | #include "stm32f4xx_dma2d.h" 75 | #include "stm32f4xx_fmc.h" 76 | #include "stm32f4xx_sai.h" 77 | #endif /* STM32F427_437xx */ 78 | 79 | #if defined (STM32F40_41xxx) 80 | #include "stm32f4xx_cryp.h" 81 | #include "stm32f4xx_hash.h" 82 | #include "stm32f4xx_rng.h" 83 | #include "stm32f4xx_can.h" 84 | #include "stm32f4xx_dac.h" 85 | #include "stm32f4xx_dcmi.h" 86 | #include "stm32f4xx_fsmc.h" 87 | #endif /* STM32F40_41xxx */ 88 | 89 | #if defined (STM32F411xE) 90 | #include "stm32f4xx_flash_ramfunc.h" 91 | #endif /* STM32F411xE */ 92 | /* Exported types ------------------------------------------------------------*/ 93 | /* Exported constants --------------------------------------------------------*/ 94 | 95 | /* If an external clock source is used, then the value of the following define 96 | should be set to the value of the external clock source, else, if no external 97 | clock is used, keep this define commented */ 98 | /*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */ 99 | 100 | 101 | /* Uncomment the line below to expanse the "assert_param" macro in the 102 | Standard Peripheral Library drivers code */ 103 | /* #define USE_FULL_ASSERT 1 */ 104 | 105 | /* Exported macro ------------------------------------------------------------*/ 106 | #ifdef USE_FULL_ASSERT 107 | 108 | /** 109 | * @brief The assert_param macro is used for function's parameters check. 110 | * @param expr: If expr is false, it calls assert_failed function 111 | * which reports the name of the source file and the source 112 | * line number of the call that failed. 113 | * If expr is true, it returns no value. 114 | * @retval None 115 | */ 116 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 117 | /* Exported functions ------------------------------------------------------- */ 118 | void assert_failed(uint8_t* file, uint32_t line); 119 | #else 120 | #define assert_param(expr) ((void)0) 121 | #endif /* USE_FULL_ASSERT */ 122 | 123 | #endif /* __STM32F4xx_CONF_H */ 124 | 125 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 126 | -------------------------------------------------------------------------------- /USER/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.c 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and 9 | * peripherals interrupt service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© COPYRIGHT 2014 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 "stm32f4xx_it.h" 32 | #include "sys.h" 33 | #include "delay.h" 34 | #include "usart.h" 35 | #include "led.h" 36 | #include "lcd.h" 37 | //#include "dac.h" 38 | #include "adc.h" 39 | #include "waveform.h" 40 | #include "timer.h" 41 | u32 count = 0; 42 | u32 frequency = 0; 43 | 44 | /** @addtogroup Template_Project 45 | * @{ 46 | */ 47 | 48 | /* Private typedef -----------------------------------------------------------*/ 49 | /* Private define ------------------------------------------------------------*/ 50 | /* Private macro -------------------------------------------------------------*/ 51 | /* Private variables ---------------------------------------------------------*/ 52 | /* Private function prototypes -----------------------------------------------*/ 53 | /* Private functions ---------------------------------------------------------*/ 54 | 55 | /******************************************************************************/ 56 | /* Cortex-M4 Processor Exceptions Handlers */ 57 | /******************************************************************************/ 58 | 59 | /** 60 | * @brief This function handles NMI exception. 61 | * @param None 62 | * @retval None 63 | */ 64 | void NMI_Handler(void) 65 | { 66 | } 67 | 68 | /** 69 | * @brief This function handles Hard Fault exception. 70 | * @param None 71 | * @retval None 72 | */ 73 | void HardFault_Handler(void) 74 | { 75 | /* Go to infinite loop when Hard Fault exception occurs */ 76 | while (1) 77 | { 78 | } 79 | } 80 | 81 | /** 82 | * @brief This function handles Memory Manage exception. 83 | * @param None 84 | * @retval None 85 | */ 86 | void MemManage_Handler(void) 87 | { 88 | /* Go to infinite loop when Memory Manage exception occurs */ 89 | while (1) 90 | { 91 | } 92 | } 93 | 94 | /** 95 | * @brief This function handles Bus Fault exception. 96 | * @param None 97 | * @retval None 98 | */ 99 | void BusFault_Handler(void) 100 | { 101 | /* Go to infinite loop when Bus Fault exception occurs */ 102 | while (1) 103 | { 104 | } 105 | } 106 | 107 | /** 108 | * @brief This function handles Usage Fault exception. 109 | * @param None 110 | * @retval None 111 | */ 112 | void UsageFault_Handler(void) 113 | { 114 | /* Go to infinite loop when Usage Fault exception occurs */ 115 | while (1) 116 | { 117 | } 118 | } 119 | 120 | /** 121 | * @brief This function handles SVCall exception. 122 | * @param None 123 | * @retval None 124 | */ 125 | void SVC_Handler(void) 126 | { 127 | } 128 | 129 | /** 130 | * @brief This function handles Debug Monitor exception. 131 | * @param None 132 | * @retval None 133 | */ 134 | void DebugMon_Handler(void) 135 | { 136 | } 137 | 138 | /** 139 | * @brief This function handles PendSVC exception. 140 | * @param None 141 | * @retval None 142 | */ 143 | void PendSV_Handler(void) 144 | { 145 | } 146 | 147 | /** 148 | * @brief This function handles SysTick Handler. 149 | * @param None 150 | * @retval None 151 | */ 152 | void SysTick_Handler(void) 153 | { 154 | 155 | } 156 | 157 | /******************************************************************************/ 158 | /* STM32F4xx Peripherals Interrupt Handlers */ 159 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 160 | /* available peripheral interrupt handler's name please refer to the startup */ 161 | /* file (startup_stm32f4xx.s). */ 162 | /******************************************************************************/ 163 | 164 | /** 165 | * @brief This function handles PPP interrupt request. 166 | * @param None 167 | * @retval None 168 | */ 169 | /*void PPP_IRQHandler(void) 170 | { 171 | }*/ 172 | 173 | /** 174 | * @} 175 | */ 176 | void TIM2_IRQHandler(void) 177 | { 178 | if(TIM_GetITStatus(TIM2, TIM_IT_Update)) 179 | { 180 | TIM_Cmd(TIM2,DISABLE); 181 | frequency = 1; 182 | TIM_ClearITPendingBit(TIM2, TIM_IT_Update); 183 | 184 | TIM_SetCounter(TIM2,0); 185 | 186 | TIM_Cmd(TIM2,ENABLE); 187 | } 188 | } 189 | 190 | 191 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 192 | -------------------------------------------------------------------------------- /USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 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 __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | extern u32 frequency; 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /USER/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 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 stm32f4xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F4XX_H 40 | #define __SYSTEM_STM32F4XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F4xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F4xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /USER/waveform.c: -------------------------------------------------------------------------------- 1 | //STM32 使用DMA+DAC+TIMER输出正弦波// 2 | 3 | /* 4 | 5 | 那么对于使用DMA+DAC+TIMER产生正弦波的原理或过程,我有这样一个简单的理解: 6 | 先将一个可以生成正弦波的数据表保存在静态内存中,然后在DAC以及这块内存中间使 7 | 用DMA建立一个通道,经过以上步骤之后,DAC模块就可以通过DMA通道拿取静态内存中 8 | 可以生成正弦波的数据,拿取数据,然后经过数模准换,在引脚进行输出就可以得到正 9 | 弦波了。那么当然,这个速度是非常快的,如果没有一定的延时,那么得到的估计就是 10 | 一个变化很快的模拟量。所以这个时候就需要使用定时器TIMER了。DAC在初始化的时候, 11 | 可以设置成使用定时器触发,这就意味着,当定时器溢满的时候,就会触发DAC工作。 12 | 这样一来,就可以通过改变定时器的定时时间来改变正弦波的周期了。 13 | 14 | 电压大小的显示用DAC来处理 15 | */ 16 | 17 | //#include "dac.h" 18 | #include "sys.h" 19 | #include "math.h" 20 | #include "waveform.h" 21 | #include "key.h" 22 | #include "delay.h" 23 | #define PI 3.14159 24 | #define DAC_DHR12R1_ADDRESS 0x40007408 25 | 26 | u16 sinTable[tableSize]; //256; 27 | //u16 sawtoothTable[tableSize];//256; 28 | //u16 triangleTable[tableSize];//256; 29 | //u16 rectangleTable[tableSize];//256; 30 | 31 | u8 KEY_Scan(u8 mode); 32 | 33 | //将正弦波数据保存在静态内存中 34 | void sin_Generation(void) 35 | { 36 | u16 n; 37 | u16 temp = 1023; 38 | //temp=KEY_Scan(0); 39 | if (KEY_Scan(0) == 4) 40 | { 41 | temp = temp + 200; 42 | } 43 | for (n = 0; n < tableSize; n++) 44 | { 45 | sinTable[n] = (sin(2 * PI * n / tableSize) + 1) * (temp); 46 | } 47 | } 48 | 49 | //锯齿波 50 | void sawtooth_Generation(void) 51 | { 52 | u16 n; 53 | for (n = 0; n < tableSize; n++) 54 | { 55 | sinTable[n] = ((2 * n * 1000) / tableSize); 56 | } 57 | } 58 | 59 | //三角波 60 | void triangle_Generation(void) 61 | { 62 | u16 n; 63 | for (n = 0; n < tableSize / 2; n++) 64 | { 65 | sinTable[n] = ((2 * n * 1000) / tableSize); 66 | } 67 | for (; n < tableSize; n++) 68 | { 69 | sinTable[n] = (2 * 1000 - (2 * n * 1000) / tableSize); 70 | } 71 | } 72 | 73 | //矩形波 74 | void rectangle_Generation(void) 75 | { 76 | u16 n; 77 | for (n = 0; n < tableSize / 2; n++) 78 | { 79 | sinTable[n] = 0; 80 | } 81 | for (; n < (tableSize); n++) 82 | { 83 | sinTable[n] = 1000; 84 | } 85 | } 86 | 87 | //当定时器溢满的时候,就会触发DAC工作,这样一来,就可以通过改变定时器的定时时间来改变正弦波的周期了 88 | void TIM6_Configuration(void) 89 | { 90 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); 91 | 92 | TIM_PrescalerConfig(TIM6, 83, TIM_PSCReloadMode_Update); 93 | TIM_SetAutoreload(TIM6, 4); 94 | TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); 95 | TIM_Cmd(TIM6, ENABLE); 96 | } 97 | 98 | void DacGPIO_Configuration(void) 99 | { 100 | GPIO_InitTypeDef GPIO_InitStructure; //结构体 101 | 102 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //使能GPIOA时钟 103 | 104 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //选定4号引脚,4,5都可以 105 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; //模拟输入 106 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //不上拉,不下拉 107 | GPIO_Init(GPIOA, &GPIO_InitStructure); //确定为GPIOA的初始化 108 | } 109 | 110 | //后在DAC以及这块内存中间使用DMA建立一个通道 111 | void DAC_DMA_Configuration(void) 112 | { 113 | DAC_InitTypeDef DAC_InitStructure; //DAC结构体 114 | 115 | DMA_InitTypeDef DMA_InitStructure; //DMA结构体 116 | 117 | //使能DMA1时钟,则我们要找DMA1的请求映射来进行下面的配置 118 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); 119 | 120 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); //使能DAC时钟 121 | 122 | DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; //使用触发功能 123 | DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; //不用STM32自带的波形 124 | DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //一般设置不使用输出缓存 125 | //STM32的DAC有两个通道,这里我们使用的是DAC的通道1,所以对DAC进行初始化 126 | DAC_Init(DAC_Channel_1, &DAC_InitStructure); 127 | 128 | //DMA1请求映射,DMA的数据流5和通道7为DAC1功能 129 | DMA_DeInit(DMA1_Stream5); //设置数据流5 130 | DMA_InitStructure.DMA_Channel = DMA_Channel_7; //设置通道7 131 | //把正弦波的数据表保存在静态内存中 132 | DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_ADDRESS; 133 | DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&sinTable; //定义DMA外设基地址 134 | DMA_InitStructure.DMA_BufferSize = tableSize; //设置DMA缓存大小 135 | //外设数据宽度 136 | DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; 137 | DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_HalfWord; 138 | DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; 139 | DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 140 | DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; 141 | //设置为循环工作模式 142 | DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; 143 | DMA_InitStructure.DMA_Priority = DMA_Priority_High; 144 | DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; 145 | DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; 146 | DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; 147 | DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; 148 | DMA_Init(DMA1_Stream5, &DMA_InitStructure); 149 | 150 | DMA_Cmd(DMA1_Stream5, ENABLE); //使能DMA1数据流5 151 | 152 | DAC_Cmd(DAC_Channel_1, ENABLE); //使能DAC的通道1 153 | 154 | //将DAC通道和DMA通道接起来 155 | DAC_DMACmd(DAC_Channel_1, ENABLE); //使能DAC_DMA通道1 156 | } 157 | 158 | //void opt(void) 159 | //{ 160 | // u8 t ; 161 | // t=KEY_Scan(0); 162 | // if(t==2) 163 | // { 164 | // while(1) 165 | // { 166 | // sin_Generation(); 167 | // if(KEY_Scan(0)!=1) 168 | // break; 169 | // } 170 | // } 171 | //} 172 | 173 | void MYDAC_Init(void) 174 | { 175 | // opt(); 176 | //u8 key; 177 | //sawtooth_Generation(); 178 | DacGPIO_Configuration(); 179 | TIM6_Configuration(); 180 | DAC_DMA_Configuration(); 181 | // while(1) 182 | // { 183 | // key=KEY_Scan(0); //得到键值 184 | // if(key) 185 | // { 186 | // switch(key) 187 | // { 188 | // case WKUP_PRES: //控制蜂鸣器 189 | // sin_Generation(); 190 | // break; 191 | //// case KEY0_PRES: //控制LED0翻转 192 | //// 193 | //// break; 194 | // case KEY1_PRES: //控制LED1翻转 195 | // triangle_Generation(); 196 | // break; 197 | // case KEY2_PRES: //同时控制LED0,LED1翻转 198 | // sawtooth_Generation(); 199 | // break; 200 | // } 201 | // } 202 | // else delay_ms(10); 203 | // } 204 | } 205 | 206 | //// u8 opt=0; 207 | //// opt = KEY_Scan(0); 208 | //// if(opt==1) 209 | //// { 210 | //// while(1) 211 | //// { 212 | // sin_Generation(); 213 | //// } 214 | //// } 215 | // //else if(opt==2) 216 | // triangle_Generation(); 217 | // 218 | // //else if(opt==3) 219 | // sawtooth_Generation(); 220 | // 221 | // //else if(opt==4) 222 | // rectangle_Generation(); 223 | // 224 | -------------------------------------------------------------------------------- /USER/waveform.h: -------------------------------------------------------------------------------- 1 | #ifndef __WAVEFORM_H 2 | #define __WAVEFORM_H 3 | 4 | #define tableSize 256 5 | 6 | void MYDAC_Init(void); 7 | 8 | #endif 9 | 10 | --------------------------------------------------------------------------------